Commit f8ca6341599bd5d07b8b8d708ebeb70b498682c5
1 parent
9d149f41
fix:【ai 大模型】豆包支持 thinking 返回
Showing
4 changed files
with
16 additions
and
11 deletions
yudao-module-ai/src/main/java/cn/iocoder/yudao/module/ai/framework/ai/config/AiAutoConfiguration.java
| @@ -94,6 +94,7 @@ public class AiAutoConfiguration { | @@ -94,6 +94,7 @@ public class AiAutoConfiguration { | ||
| 94 | OpenAiChatModel openAiChatModel = OpenAiChatModel.builder() | 94 | OpenAiChatModel openAiChatModel = OpenAiChatModel.builder() |
| 95 | .openAiApi(OpenAiApi.builder() | 95 | .openAiApi(OpenAiApi.builder() |
| 96 | .baseUrl(DouBaoChatModel.BASE_URL) | 96 | .baseUrl(DouBaoChatModel.BASE_URL) |
| 97 | + .completionsPath(DouBaoChatModel.COMPLETE_PATH) | ||
| 97 | .apiKey(properties.getApiKey()) | 98 | .apiKey(properties.getApiKey()) |
| 98 | .build()) | 99 | .build()) |
| 99 | .defaultOptions(OpenAiChatOptions.builder() | 100 | .defaultOptions(OpenAiChatOptions.builder() |
yudao-module-ai/src/main/java/cn/iocoder/yudao/module/ai/framework/ai/core/model/doubao/DouBaoChatModel.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 | /** |
| @@ -19,13 +18,14 @@ import reactor.core.publisher.Flux; | @@ -19,13 +18,14 @@ import reactor.core.publisher.Flux; | ||
| 19 | public class DouBaoChatModel implements ChatModel { | 18 | public class DouBaoChatModel implements ChatModel { |
| 20 | 19 | ||
| 21 | public static final String BASE_URL = "https://ark.cn-beijing.volces.com/api"; | 20 | public static final String BASE_URL = "https://ark.cn-beijing.volces.com/api"; |
| 21 | + public static final String COMPLETE_PATH = "/v3/chat/completions"; | ||
| 22 | 22 | ||
| 23 | public static final String MODEL_DEFAULT = "doubao-1-5-lite-32k-250115"; | 23 | public static final String MODEL_DEFAULT = "doubao-1-5-lite-32k-250115"; |
| 24 | 24 | ||
| 25 | /** | 25 | /** |
| 26 | * 兼容 OpenAI 接口,进行复用 | 26 | * 兼容 OpenAI 接口,进行复用 |
| 27 | */ | 27 | */ |
| 28 | - private final OpenAiChatModel openAiChatModel; | 28 | + private final ChatModel openAiChatModel; |
| 29 | 29 | ||
| 30 | @Override | 30 | @Override |
| 31 | public ChatResponse call(Prompt prompt) { | 31 | public ChatResponse call(Prompt prompt) { |
yudao-module-ai/src/main/java/cn/iocoder/yudao/module/ai/util/AiUtils.java
| @@ -49,6 +49,7 @@ public class AiUtils { | @@ -49,6 +49,7 @@ public class AiUtils { | ||
| 49 | case YI_YAN: | 49 | case YI_YAN: |
| 50 | return QianFanChatOptions.builder().model(model).temperature(temperature).maxTokens(maxTokens).build(); | 50 | return QianFanChatOptions.builder().model(model).temperature(temperature).maxTokens(maxTokens).build(); |
| 51 | case DEEP_SEEK: | 51 | case DEEP_SEEK: |
| 52 | + case DOU_BAO: // 复用 DeepSeek 客户端 | ||
| 52 | return DeepSeekChatOptions.builder().model(model).temperature(temperature).maxTokens(maxTokens) | 53 | return DeepSeekChatOptions.builder().model(model).temperature(temperature).maxTokens(maxTokens) |
| 53 | .toolNames(toolNames).toolContext(toolContext).build(); | 54 | .toolNames(toolNames).toolContext(toolContext).build(); |
| 54 | case ZHI_PU: | 55 | case ZHI_PU: |
| @@ -62,7 +63,6 @@ public class AiUtils { | @@ -62,7 +63,6 @@ public class AiUtils { | ||
| 62 | .toolNames(toolNames).toolContext(toolContext).build(); | 63 | .toolNames(toolNames).toolContext(toolContext).build(); |
| 63 | case OPENAI: | 64 | case OPENAI: |
| 64 | case GEMINI: // 复用 OpenAI 客户端 | 65 | case GEMINI: // 复用 OpenAI 客户端 |
| 65 | - case DOU_BAO: // 复用 OpenAI 客户端 | ||
| 66 | case HUN_YUAN: // 复用 OpenAI 客户端 | 66 | case HUN_YUAN: // 复用 OpenAI 客户端 |
| 67 | case XING_HUO: // 复用 OpenAI 客户端 | 67 | case XING_HUO: // 复用 OpenAI 客户端 |
| 68 | case SILICON_FLOW: // 复用 OpenAI 客户端 | 68 | case SILICON_FLOW: // 复用 OpenAI 客户端 |
yudao-module-ai/src/test/java/cn/iocoder/yudao/module/ai/framework/ai/core/model/chat/DouBaoChatModelTests.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,18 @@ import java.util.List; | @@ -23,13 +23,18 @@ import java.util.List; | ||
| 23 | */ | 23 | */ |
| 24 | public class DouBaoChatModelTests { | 24 | public class DouBaoChatModelTests { |
| 25 | 25 | ||
| 26 | - private final OpenAiChatModel openAiChatModel = OpenAiChatModel.builder() | ||
| 27 | - .openAiApi(OpenAiApi.builder() | 26 | + /** |
| 27 | + * 相比 OpenAIChatModel 来说,DeepSeekChatModel 可以兼容豆包的 thinking 能力! | ||
| 28 | + */ | ||
| 29 | + private final DeepSeekChatModel openAiChatModel = DeepSeekChatModel.builder() | ||
| 30 | + .deepSeekApi(DeepSeekApi.builder() | ||
| 28 | .baseUrl(DouBaoChatModel.BASE_URL) | 31 | .baseUrl(DouBaoChatModel.BASE_URL) |
| 32 | + .completionsPath(DouBaoChatModel.COMPLETE_PATH) | ||
| 29 | .apiKey("5c1b5747-26d2-4ebd-a4e0-dd0e8d8b4272") // apiKey | 33 | .apiKey("5c1b5747-26d2-4ebd-a4e0-dd0e8d8b4272") // apiKey |
| 30 | .build()) | 34 | .build()) |
| 31 | - .defaultOptions(OpenAiChatOptions.builder() | 35 | + .defaultOptions(DeepSeekChatOptions.builder() |
| 32 | .model("doubao-1-5-lite-32k-250115") // 模型(doubao) | 36 | .model("doubao-1-5-lite-32k-250115") // 模型(doubao) |
| 37 | +// .model("doubao-seed-1-6-thinking-250715") // 模型(doubao) | ||
| 33 | // .model("deepseek-r1-250120") // 模型(deepseek) | 38 | // .model("deepseek-r1-250120") // 模型(deepseek) |
| 34 | .temperature(0.7) | 39 | .temperature(0.7) |
| 35 | .build()) | 40 | .build()) |
| @@ -51,14 +56,13 @@ public class DouBaoChatModelTests { | @@ -51,14 +56,13 @@ public class DouBaoChatModelTests { | ||
| 51 | System.out.println(response); | 56 | System.out.println(response); |
| 52 | } | 57 | } |
| 53 | 58 | ||
| 54 | - // TODO @芋艿:因为使用的是 v1 api,导致 deepseek-r1-250120 不返回 think 过程,后续需要优化 | ||
| 55 | @Test | 59 | @Test |
| 56 | @Disabled | 60 | @Disabled |
| 57 | public void testStream() { | 61 | public void testStream() { |
| 58 | // 准备参数 | 62 | // 准备参数 |
| 59 | List<Message> messages = new ArrayList<>(); | 63 | List<Message> messages = new ArrayList<>(); |
| 60 | messages.add(new SystemMessage("你是一个优质的文言文作者,用文言文描述着各城市的人文风景。")); | 64 | messages.add(new SystemMessage("你是一个优质的文言文作者,用文言文描述着各城市的人文风景。")); |
| 61 | - messages.add(new UserMessage("1 + 1 = ?")); | 65 | + messages.add(new UserMessage("详细推理下,帮我设计一个用户中心!")); |
| 62 | 66 | ||
| 63 | // 调用 | 67 | // 调用 |
| 64 | Flux<ChatResponse> flux = chatModel.stream(new Prompt(messages)); | 68 | Flux<ChatResponse> flux = chatModel.stream(new Prompt(messages)); |