Commit d82c8e05d78d52b850673e80185350d8cbe7081d
1 parent
2fa59090
fix:【ai 大模型】科大讯飞星火 thinking 返回
Showing
5 changed files
with
48 additions
and
11 deletions
yudao-module-ai/src/main/java/cn/iocoder/yudao/module/ai/framework/ai/core/model/xinghuo/XingHuoChatModel.java
| @@ -6,7 +6,6 @@ import org.springframework.ai.chat.model.ChatModel; | @@ -6,7 +6,6 @@ import org.springframework.ai.chat.model.ChatModel; | ||
| 6 | import org.springframework.ai.chat.model.ChatResponse; | 6 | import org.springframework.ai.chat.model.ChatResponse; |
| 7 | import org.springframework.ai.chat.prompt.ChatOptions; | 7 | import org.springframework.ai.chat.prompt.ChatOptions; |
| 8 | import org.springframework.ai.chat.prompt.Prompt; | 8 | import org.springframework.ai.chat.prompt.Prompt; |
| 9 | -import org.springframework.ai.openai.OpenAiChatModel; | ||
| 10 | import reactor.core.publisher.Flux; | 9 | import reactor.core.publisher.Flux; |
| 11 | 10 | ||
| 12 | /** | 11 | /** |
| @@ -31,7 +30,7 @@ public class XingHuoChatModel implements ChatModel { | @@ -31,7 +30,7 @@ public class XingHuoChatModel implements ChatModel { | ||
| 31 | /** | 30 | /** |
| 32 | * v1 兼容 OpenAI 接口,进行复用 | 31 | * v1 兼容 OpenAI 接口,进行复用 |
| 33 | */ | 32 | */ |
| 34 | - private final OpenAiChatModel openAiChatModelV1; | 33 | + private final ChatModel openAiChatModelV1; |
| 35 | 34 | ||
| 36 | @Override | 35 | @Override |
| 37 | public ChatResponse call(Prompt prompt) { | 36 | public ChatResponse call(Prompt prompt) { |
yudao-module-ai/src/main/java/cn/iocoder/yudao/module/ai/util/AiUtils.java
| @@ -51,7 +51,8 @@ public class AiUtils { | @@ -51,7 +51,8 @@ public class AiUtils { | ||
| 51 | case DEEP_SEEK: | 51 | case DEEP_SEEK: |
| 52 | case DOU_BAO: // 复用 DeepSeek 客户端 | 52 | case DOU_BAO: // 复用 DeepSeek 客户端 |
| 53 | case HUN_YUAN: // 复用 DeepSeek 客户端 | 53 | case HUN_YUAN: // 复用 DeepSeek 客户端 |
| 54 | - case SILICON_FLOW: // 复用 OpenAI 客户端 | 54 | + case SILICON_FLOW: // 复用 DeepSeek 客户端 |
| 55 | + case XING_HUO: // 复用 DeepSeek 客户端 | ||
| 55 | return DeepSeekChatOptions.builder().model(model).temperature(temperature).maxTokens(maxTokens) | 56 | return DeepSeekChatOptions.builder().model(model).temperature(temperature).maxTokens(maxTokens) |
| 56 | .toolNames(toolNames).toolContext(toolContext).build(); | 57 | .toolNames(toolNames).toolContext(toolContext).build(); |
| 57 | case ZHI_PU: | 58 | case ZHI_PU: |
| @@ -65,7 +66,6 @@ public class AiUtils { | @@ -65,7 +66,6 @@ public class AiUtils { | ||
| 65 | .toolNames(toolNames).toolContext(toolContext).build(); | 66 | .toolNames(toolNames).toolContext(toolContext).build(); |
| 66 | case OPENAI: | 67 | case OPENAI: |
| 67 | case GEMINI: // 复用 OpenAI 客户端 | 68 | case GEMINI: // 复用 OpenAI 客户端 |
| 68 | - case XING_HUO: // 复用 OpenAI 客户端 | ||
| 69 | case BAI_CHUAN: // 复用 OpenAI 客户端 | 69 | case BAI_CHUAN: // 复用 OpenAI 客户端 |
| 70 | return OpenAiChatOptions.builder().model(model).temperature(temperature).maxTokens(maxTokens) | 70 | return OpenAiChatOptions.builder().model(model).temperature(temperature).maxTokens(maxTokens) |
| 71 | .toolNames(toolNames).toolContext(toolContext).build(); | 71 | .toolNames(toolNames).toolContext(toolContext).build(); |
yudao-module-ai/src/test/java/cn/iocoder/yudao/module/ai/framework/ai/core/model/chat/DouBaoChatModelTests.java
| @@ -70,4 +70,23 @@ public class DouBaoChatModelTests { | @@ -70,4 +70,23 @@ public class DouBaoChatModelTests { | ||
| 70 | flux.doOnNext(System.out::println).then().block(); | 70 | flux.doOnNext(System.out::println).then().block(); |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | + @Test | ||
| 74 | + @Disabled | ||
| 75 | + public void testStream_thinking() { | ||
| 76 | + // 准备参数 | ||
| 77 | + List<Message> messages = new ArrayList<>(); | ||
| 78 | + messages.add(new UserMessage("详细分析下,如何设计一个电商系统?")); | ||
| 79 | + DeepSeekChatOptions options = DeepSeekChatOptions.builder() | ||
| 80 | + .model("doubao-seed-1-6-thinking-250715") | ||
| 81 | + .build(); | ||
| 82 | + | ||
| 83 | + // 调用 | ||
| 84 | + Flux<ChatResponse> flux = chatModel.stream(new Prompt(messages, options)); | ||
| 85 | + // 打印结果 | ||
| 86 | + flux.doOnNext(response -> { | ||
| 87 | +// System.out.println(response); | ||
| 88 | + System.out.println(response.getResult().getOutput()); | ||
| 89 | + }).then().block(); | ||
| 90 | + } | ||
| 91 | + | ||
| 73 | } | 92 | } |
yudao-module-ai/src/test/java/cn/iocoder/yudao/module/ai/framework/ai/core/model/chat/XingHuoChatModelTests.java
| @@ -8,9 +8,9 @@ import org.springframework.ai.chat.messages.SystemMessage; | @@ -8,9 +8,9 @@ import org.springframework.ai.chat.messages.SystemMessage; | ||
| 8 | import org.springframework.ai.chat.messages.UserMessage; | 8 | import org.springframework.ai.chat.messages.UserMessage; |
| 9 | import org.springframework.ai.chat.model.ChatResponse; | 9 | import org.springframework.ai.chat.model.ChatResponse; |
| 10 | import org.springframework.ai.chat.prompt.Prompt; | 10 | import org.springframework.ai.chat.prompt.Prompt; |
| 11 | -import org.springframework.ai.openai.OpenAiChatModel; | ||
| 12 | -import org.springframework.ai.openai.OpenAiChatOptions; | ||
| 13 | -import org.springframework.ai.openai.api.OpenAiApi; | 11 | +import org.springframework.ai.deepseek.DeepSeekChatModel; |
| 12 | +import org.springframework.ai.deepseek.DeepSeekChatOptions; | ||
| 13 | +import org.springframework.ai.deepseek.api.DeepSeekApi; | ||
| 14 | import reactor.core.publisher.Flux; | 14 | import reactor.core.publisher.Flux; |
| 15 | 15 | ||
| 16 | import java.util.ArrayList; | 16 | import java.util.ArrayList; |
| @@ -23,13 +23,13 @@ import java.util.List; | @@ -23,13 +23,13 @@ import java.util.List; | ||
| 23 | */ | 23 | */ |
| 24 | public class XingHuoChatModelTests { | 24 | public class XingHuoChatModelTests { |
| 25 | 25 | ||
| 26 | - private final OpenAiChatModel openAiChatModel = OpenAiChatModel.builder() | ||
| 27 | - .openAiApi(OpenAiApi.builder() | 26 | + private final DeepSeekChatModel openAiChatModel = DeepSeekChatModel.builder() |
| 27 | + .deepSeekApi(DeepSeekApi.builder() | ||
| 28 | .baseUrl(XingHuoChatModel.BASE_URL_V2) | 28 | .baseUrl(XingHuoChatModel.BASE_URL_V2) |
| 29 | .completionsPath(XingHuoChatModel.BASE_COMPLETIONS_PATH_V2) | 29 | .completionsPath(XingHuoChatModel.BASE_COMPLETIONS_PATH_V2) |
| 30 | .apiKey("75b161ed2aef4719b275d6e7f2a4d4cd:YWYxYWI2MTA4ODI2NGZlYTQyNjAzZTcz") // appKey:secretKey | 30 | .apiKey("75b161ed2aef4719b275d6e7f2a4d4cd:YWYxYWI2MTA4ODI2NGZlYTQyNjAzZTcz") // appKey:secretKey |
| 31 | .build()) | 31 | .build()) |
| 32 | - .defaultOptions(OpenAiChatOptions.builder() | 32 | + .defaultOptions(DeepSeekChatOptions.builder() |
| 33 | // .model("generalv3.5") // 模型 | 33 | // .model("generalv3.5") // 模型 |
| 34 | .model("x1") // 模型 | 34 | .model("x1") // 模型 |
| 35 | .temperature(0.7) | 35 | .temperature(0.7) |
| @@ -66,4 +66,23 @@ public class XingHuoChatModelTests { | @@ -66,4 +66,23 @@ public class XingHuoChatModelTests { | ||
| 66 | flux.doOnNext(System.out::println).then().block(); | 66 | flux.doOnNext(System.out::println).then().block(); |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | + @Test | ||
| 70 | + @Disabled | ||
| 71 | + public void testStream_thinking() { | ||
| 72 | + // 准备参数 | ||
| 73 | + List<Message> messages = new ArrayList<>(); | ||
| 74 | + messages.add(new UserMessage("详细分析下,如何设计一个电商系统?")); | ||
| 75 | + DeepSeekChatOptions options = DeepSeekChatOptions.builder() | ||
| 76 | + .model("x1") | ||
| 77 | + .build(); | ||
| 78 | + | ||
| 79 | + // 调用 | ||
| 80 | + Flux<ChatResponse> flux = chatModel.stream(new Prompt(messages, options)); | ||
| 81 | + // 打印结果 | ||
| 82 | + flux.doOnNext(response -> { | ||
| 83 | +// System.out.println(response); | ||
| 84 | + System.out.println(response.getResult().getOutput()); | ||
| 85 | + }).then().block(); | ||
| 86 | + } | ||
| 87 | + | ||
| 69 | } | 88 | } |
yudao-server/src/main/resources/application.yaml
| @@ -217,7 +217,7 @@ yudao: | @@ -217,7 +217,7 @@ yudao: | ||
| 217 | enable: true | 217 | enable: true |
| 218 | appKey: 75b161ed2aef4719b275d6e7f2a4d4cd | 218 | appKey: 75b161ed2aef4719b275d6e7f2a4d4cd |
| 219 | secretKey: YWYxYWI2MTA4ODI2NGZlYTQyNjAzZTcz | 219 | secretKey: YWYxYWI2MTA4ODI2NGZlYTQyNjAzZTcz |
| 220 | - model: generalv3.5 | 220 | + model: x1 |
| 221 | baichuan: # 百川智能 | 221 | baichuan: # 百川智能 |
| 222 | enable: true | 222 | enable: true |
| 223 | api-key: sk-abc | 223 | api-key: sk-abc |