From 1d6c4751ded61c4bf8f5102767081e27db9767a9 Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Tue, 23 Dec 2025 14:42:33 +0800 Subject: [PATCH] =?UTF-8?q?update:=E8=82=A1=E4=B8=9C=E8=AE=B0=E5=BF=86?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E7=9A=84token=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/OpenAIStyleLLMServiceImpl.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/main/manager-api/src/main/java/xiaozhi/modules/llm/service/impl/OpenAIStyleLLMServiceImpl.java b/main/manager-api/src/main/java/xiaozhi/modules/llm/service/impl/OpenAIStyleLLMServiceImpl.java index e0b8a3b2..55fda70d 100644 --- a/main/manager-api/src/main/java/xiaozhi/modules/llm/service/impl/OpenAIStyleLLMServiceImpl.java +++ b/main/manager-api/src/main/java/xiaozhi/modules/llm/service/impl/OpenAIStyleLLMServiceImpl.java @@ -1,9 +1,9 @@ package xiaozhi.modules.llm.service.impl; -import cn.hutool.json.JSONArray; -import cn.hutool.json.JSONObject; -import cn.hutool.json.JSONUtil; -import lombok.extern.slf4j.Slf4j; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpEntity; @@ -13,14 +13,15 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; + +import cn.hutool.json.JSONArray; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import lombok.extern.slf4j.Slf4j; import xiaozhi.modules.llm.service.LLMService; import xiaozhi.modules.model.entity.ModelConfigEntity; import xiaozhi.modules.model.service.ModelConfigService; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - /** * OpenAI风格API的LLM服务实现 * 支持阿里云、DeepSeek、ChatGLM等兼容OpenAI API的模型 @@ -169,8 +170,6 @@ public class OpenAIStyleLLMServiceImpl implements LLMService { String baseUrl = configJson.getStr("base_url"); String model = configJson.getStr("model_name"); String apiKey = configJson.getStr("api_key"); - Double temperature = configJson.getDouble("temperature"); - Integer maxTokens = configJson.getInt("max_tokens"); if (StringUtils.isBlank(baseUrl) || StringUtils.isBlank(apiKey)) { log.error("LLM配置不完整,baseUrl或apiKey为空"); @@ -193,8 +192,8 @@ public class OpenAIStyleLLMServiceImpl implements LLMService { messages[0] = message; requestBody.put("messages", messages); - requestBody.put("temperature", temperature != null ? temperature : 0.7); - requestBody.put("max_tokens", maxTokens != null ? maxTokens : 2000); + requestBody.put("temperature", 0.2); + requestBody.put("max_tokens", 2000); // 发送HTTP请求 HttpHeaders headers = new HttpHeaders();