#
Junjie
2026-01-09 93b4b3ba7606e71601de2e326bd8bcc50c5898ab
#
3个文件已修改
29 ■■■■ 已修改文件
src/main/java/com/zy/ai/entity/ChatCompletionRequest.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/ai/service/LlmChatService.java 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application.yml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/ai/entity/ChatCompletionRequest.java
@@ -15,6 +15,7 @@
    private Boolean stream;
    private List<Object> tools;
    private Object tool_choice;
    private Thinking thinking;
    @Data
    public static class Message {
@@ -37,4 +38,10 @@
        private String name;
        private String arguments;
    }
    @Data
    public static class Thinking {
        private String type;
    }
}
src/main/java/com/zy/ai/service/LlmChatService.java
@@ -38,6 +38,9 @@
    @Value("${llm.pythonPlatformUrl}")
    private String pythonPlatformUrl;
    @Value("${llm.thinking}")
    private String thinking;
    /**
     * 通用对话方法:传入 messages,返回大模型文本回复
     */
@@ -84,13 +87,18 @@
                                                 Double temperature,
                                                 Integer maxTokens,
                                                 List<Object> tools) {
        ChatCompletionRequest req = new ChatCompletionRequest();
        req.setModel(model);
        req.setMessages(messages);
        req.setTemperature(temperature != null ? temperature : 0.3);
        req.setMax_tokens(maxTokens != null ? maxTokens : 1024);
        req.setStream(false);
        if(thinking.equals("enable")) {
            ChatCompletionRequest.Thinking thinking = new ChatCompletionRequest.Thinking();
            thinking.setType("enable");
            req.setThinking(thinking);
        }
        if (tools != null && !tools.isEmpty()) {
            req.setTools(tools);
            req.setTool_choice("auto");
@@ -224,18 +232,21 @@
                                    Consumer<String> onChunk,
                                    Runnable onComplete,
                                    Consumer<Throwable> onError) {
        ChatCompletionRequest req = new ChatCompletionRequest();
        req.setModel(model);
        req.setMessages(messages);
        req.setTemperature(temperature != null ? temperature : 0.3);
        req.setMax_tokens(maxTokens != null ? maxTokens : 1024);
        req.setStream(true);
        if(thinking.equals("enable")) {
            ChatCompletionRequest.Thinking thinking = new ChatCompletionRequest.Thinking();
            thinking.setType("enable");
            req.setThinking(thinking);
        }
        if (tools != null && !tools.isEmpty()) {
            req.setTools(tools);
            req.setTool_choice("auto");
        }
        Flux<String> flux = llmWebClient.post()
                .uri("/chat/completions")
                .header(HttpHeaders.AUTHORIZATION, "Bearer " + apiKey)
src/main/resources/application.yml
@@ -1,5 +1,5 @@
server:
  port: 9090
  port: 9091
  servlet:
    context-path: /@pom.build.finalName@
  shutdown: graceful
@@ -67,7 +67,7 @@
  threadControlCount: 10
  liftType: lift
mainProcessPlugin: FakeProcess
mainProcessPlugin: NormalProcess
deviceLogStorage:
  # 设备日志存储方式 mysql file
@@ -80,6 +80,7 @@
llm:
  platform: java
  pythonPlatformUrl: http://127.0.0.1:9000/ai/diagnose/askStream
  thinking: enable
#  base-url: https://api.siliconflow.cn/v1
#  api-key: sk-sxdtebtquwrugzrmaqqqkzdzmrgzhzmplwwuowysdasccent
#  model: deepseek-ai/DeepSeek-V3.2