Orange 开源项目 - 集成阿里云大模型
1 阿里云的大模型服务平台百炼
阿里云的大模型服务平台百炼是一站式的大模型开发及应用构建平台。不论是开发者还是业务人员,都能深入参与大模型应用的设计和构建。您可以通过简单的界面操作,在5分钟内开发出一款大模型应用,或在几小时内训练出一个专属模型,从而将更多精力专注于应用创新。
2 集成阿里云大模型
2.1 获取API-KEY
获取阿里API-KEY,请参考阿里官网「获取阿里API-KEY」
2.2 引入Maven依赖
<dependency><groupId>com.alibaba.cloud.ai</groupId><artifactId>spring-ai-alibaba-starter</artifactId><version>1.0.0-M5.1</version></dependency>
2.3 集成对话模型(Chat Model)
@Overridepublic Flux<Result<ConversationReplyVO>> conversationStream(ConversationParam param, List<ChatSessionRecordVO> contextMessageList) {List<Message> messages = new ArrayList<>(MessageConverter.toMessageList(contextMessageList));messages.add(new UserMessage(param.getPrompt()));Prompt prompt = new Prompt(messages, DashScopeChatOptions.builder().withModel(param.getModelCode()).build());Flux<ChatResponse> stream = chatModel.stream(prompt);return stream.takeWhile(chatResponse -> Objects.nonNull(chatResponse) && Objects.nonNull(chatResponse.getResult())&& Objects.nonNull(chatResponse.getResult().getOutput())).map(chatResponse -> {if (log.isDebugEnabled()) {log.debug("chatResponse: {}", chatResponse);}Usage usage = chatResponse.getMetadata().getUsage();String content = chatResponse.getResult().getOutput().getContent();String finishReason = chatResponse.getResult().getMetadata().getFinishReason();ConversationReplyVO replyVO = ConversationReplyVO.builder().event("STOP".equalsIgnoreCase(finishReason) ? ConverstationEventEnum.FINISHED : ConverstationEventEnum.REPLY).content(content).tokenUsage(TokenUsageVO.builder().promptTokens(usage.getPromptTokens()).generationTokens(usage.getGenerationTokens()).totalTokens(usage.getTotalTokens()).build()).build();return ResultWrapper.ok(replyVO);});}
- 项目源码:https://github.com/hengzq/orange-ai
2.4 集成文生成图模型(Image Model)
@Overridepublic ImageResponse textToImage(GenerateImageParam param) {ImageOptions options = DashScopeImageOptions.builder().withModel(param.getModelCode()).withHeight(param.getHeight()).withWidth(param.getWidth()).withN(param.getQuantity()).build();ImagePrompt imagePrompt = new ImagePrompt(param.getPrompt(), options);return imageModel.call(imagePrompt);}
- 项目源码:https://github.com/hengzq/orange-ai
2.5 在线体验
- 在线体验: http://tiny.hengzq.cn
3 项目体验
- Orange 官网: http://hengzq.cn
- 在线体验: http://tiny.hengzq.cn
- 项目文档: http://hengzq.cn/orange-monomer/
- 单体架构-后端源码下载【GitHub】: https://github.com/hengzq/orange-monomer
- 单体架构-后端源码下载【Gitee】: https://gitee.com/hengzq/orange-monomer
- 微服务版本-后端源码下载【GitHub】: https://github.com/hengzq/orange-cloud
- 微服务版本-后端源码下载【Gitee】: https://gitee.com/hengzq/orange-cloud
- 前端源码下载【GitHub】: https://github.com/hengzq/orange-cloud
- 前端源码下载【Gitee】: https://gitee.com/hengzq/orange-cloud
注:前端项目设计灵活,能够同时兼容后端的单体架构和微服务架构
4 相关文档
- Orange 开源项目介绍
- Orange 单体架构 - 快速启动
- Orange 开源项目 - 集成阿里云大模型
- Orange 开源项目 - 集成智谱AI大模型
- Orange 开源项目 - 集成DeepSeek大模型
- Orange 开源项目 - 集成百度智能云-千帆大模型