From 7024c5ab608832e69da3321f7f05f4516a6cd565 Mon Sep 17 00:00:00 2001 From: cherishsince Date: Sun, 14 Apr 2024 16:05:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20client=20name=20=E6=9E=9A?= =?UTF-8?q?=E4=B8=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/ai/enums/AiClientNameEnum.java | 28 +++++++++++++++++++ .../module/ai/controller/ChatController.java | 9 ++++-- 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/AiClientNameEnum.java diff --git a/yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/AiClientNameEnum.java b/yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/AiClientNameEnum.java new file mode 100644 index 0000000000..8e1418e626 --- /dev/null +++ b/yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/AiClientNameEnum.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.module.ai.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * ai client 名字 + * + * 这个需要根据配置文件起的来决定 + * + * @author fansili + * @time 2024/4/14 16:02 + * @since 1.0 + */ +@AllArgsConstructor +@Getter +public enum AiClientNameEnum { + + QIAN_WEN("qianWen", "千问模型!"), + YI_YAN("yiYan", "一言模型!"), + XING_HUO("xingHuo", "星火模型!"), + + ; + + private String name; + + private String message; +} diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/ChatController.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/ChatController.java index 26d1d99224..f873d6c52e 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/ChatController.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/ChatController.java @@ -5,6 +5,8 @@ import cn.iocoder.yudao.framework.ai.chat.ChatResponse; import cn.iocoder.yudao.framework.ai.chat.prompt.Prompt; import cn.iocoder.yudao.framework.ai.config.AiClient; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.ai.enums.AiClientNameEnum; +import cn.iocoder.yudao.module.ai.service.ChatService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.AllArgsConstructor; @@ -22,6 +24,8 @@ import java.io.IOException; import java.util.function.Consumer; /** + * ia 模块 + * * @author fansili * @time 2024/4/13 17:44 * @since 1.0 @@ -35,11 +39,12 @@ public class ChatController { @Autowired private AiClient aiClient; + private final ChatService chatService; @Operation(summary = "聊天-chat", description = "这个一般等待时间比较久,需要全部完成才会返回!") @GetMapping("/chat") public CommonResult chat(@RequestParam("prompt") String prompt) { - ChatResponse callRes = aiClient.call(new Prompt(prompt), "qianWen"); + ChatResponse callRes = aiClient.call(new Prompt(prompt), AiClientNameEnum.QIAN_WEN.getName()); return CommonResult.success(callRes.getResult().getOutput().getContent()); } @@ -48,7 +53,7 @@ public class ChatController { @GetMapping(value = "/chatStream", produces = MediaType.TEXT_EVENT_STREAM_VALUE) public SseEmitter chatStream(@RequestParam("prompt") String prompt) { Utf8SseEmitter sseEmitter = new Utf8SseEmitter(); - Flux streamResponse = aiClient.stream(new Prompt(prompt), "qianWen"); + Flux streamResponse = aiClient.stream(new Prompt(prompt), AiClientNameEnum.QIAN_WEN.getName()); streamResponse.subscribe( new Consumer() { @Override