Commit 7024c5ab608832e69da3321f7f05f4516a6cd565
1 parent
009914ed
增加 client name 枚举
Showing
2 changed files
with
35 additions
and
2 deletions
yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/AiClientNameEnum.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.enums; | |
| 2 | + | |
| 3 | +import lombok.AllArgsConstructor; | |
| 4 | +import lombok.Getter; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * ai client 名字 | |
| 8 | + * | |
| 9 | + * 这个需要根据配置文件起的来决定 | |
| 10 | + * | |
| 11 | + * @author fansili | |
| 12 | + * @time 2024/4/14 16:02 | |
| 13 | + * @since 1.0 | |
| 14 | + */ | |
| 15 | +@AllArgsConstructor | |
| 16 | +@Getter | |
| 17 | +public enum AiClientNameEnum { | |
| 18 | + | |
| 19 | + QIAN_WEN("qianWen", "千问模型!"), | |
| 20 | + YI_YAN("yiYan", "一言模型!"), | |
| 21 | + XING_HUO("xingHuo", "星火模型!"), | |
| 22 | + | |
| 23 | + ; | |
| 24 | + | |
| 25 | + private String name; | |
| 26 | + | |
| 27 | + private String message; | |
| 28 | +} | ... | ... |
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; |
| 5 | 5 | import cn.iocoder.yudao.framework.ai.chat.prompt.Prompt; |
| 6 | 6 | import cn.iocoder.yudao.framework.ai.config.AiClient; |
| 7 | 7 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 8 | +import cn.iocoder.yudao.module.ai.enums.AiClientNameEnum; | |
| 9 | +import cn.iocoder.yudao.module.ai.service.ChatService; | |
| 8 | 10 | import io.swagger.v3.oas.annotations.Operation; |
| 9 | 11 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 10 | 12 | import lombok.AllArgsConstructor; |
| ... | ... | @@ -22,6 +24,8 @@ import java.io.IOException; |
| 22 | 24 | import java.util.function.Consumer; |
| 23 | 25 | |
| 24 | 26 | /** |
| 27 | + * ia 模块 | |
| 28 | + * | |
| 25 | 29 | * @author fansili |
| 26 | 30 | * @time 2024/4/13 17:44 |
| 27 | 31 | * @since 1.0 |
| ... | ... | @@ -35,11 +39,12 @@ public class ChatController { |
| 35 | 39 | |
| 36 | 40 | @Autowired |
| 37 | 41 | private AiClient aiClient; |
| 42 | + private final ChatService chatService; | |
| 38 | 43 | |
| 39 | 44 | @Operation(summary = "聊天-chat", description = "这个一般等待时间比较久,需要全部完成才会返回!") |
| 40 | 45 | @GetMapping("/chat") |
| 41 | 46 | public CommonResult<String> chat(@RequestParam("prompt") String prompt) { |
| 42 | - ChatResponse callRes = aiClient.call(new Prompt(prompt), "qianWen"); | |
| 47 | + ChatResponse callRes = aiClient.call(new Prompt(prompt), AiClientNameEnum.QIAN_WEN.getName()); | |
| 43 | 48 | return CommonResult.success(callRes.getResult().getOutput().getContent()); |
| 44 | 49 | } |
| 45 | 50 | |
| ... | ... | @@ -48,7 +53,7 @@ public class ChatController { |
| 48 | 53 | @GetMapping(value = "/chatStream", produces = MediaType.TEXT_EVENT_STREAM_VALUE) |
| 49 | 54 | public SseEmitter chatStream(@RequestParam("prompt") String prompt) { |
| 50 | 55 | Utf8SseEmitter sseEmitter = new Utf8SseEmitter(); |
| 51 | - Flux<ChatResponse> streamResponse = aiClient.stream(new Prompt(prompt), "qianWen"); | |
| 56 | + Flux<ChatResponse> streamResponse = aiClient.stream(new Prompt(prompt), AiClientNameEnum.QIAN_WEN.getName()); | |
| 52 | 57 | streamResponse.subscribe( |
| 53 | 58 | new Consumer<ChatResponse>() { |
| 54 | 59 | @Override | ... | ... |