diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/conversation/ConversationServiceImpl.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/conversation/ConversationServiceImpl.java index 0f38cf733..6af8deb6e 100644 --- a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/conversation/ConversationServiceImpl.java +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/conversation/ConversationServiceImpl.java @@ -416,7 +416,7 @@ public class ConversationServiceImpl implements ConversationService { ModelCompletionsReqVO modelCompletionsReqVO = new ModelCompletionsReqVO(); modelCompletionsReqVO.setMessages(messages); modelCompletionsReqVO.setModel(model); - log.info("构建模型补全请求对象,请求参数: {}", modelCompletionsReqVO); + log.info("构建模型补全请求对象,请求参数1: {}", modelCompletionsReqVO); // 调用模型服务进行流式处理 modelService.modelCompletionsStream(selfModelUrl, modelCompletionsReqVO, emitter); diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/http/ModelService.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/http/ModelService.java index e71fc3dd0..7ef401702 100644 --- a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/http/ModelService.java +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/service/http/ModelService.java @@ -15,6 +15,7 @@ import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.HttpClients; import org.springframework.http.MediaType; @@ -147,10 +148,11 @@ public class ModelService { */ public void modelCompletionsStream (String url, ModelCompletionsReqVO req, SseEmitter emitter) { req.setStream(true); - log.info("开始处理模型补全请求,参数: {}", req); + log.info("开始处理模型补全请求,参数2: {}", req); try { - log.info("开始处理模型补全请求,参数: {}", JSON.toJSONString(req)); - sendPostRequest(url, JSON.toJSONString(req), emitter); + String jsonString = JSON.toJSONString(req); + log.info("开始处理模型补全请求,参数3: {}", jsonString); + sendPostRequest(url, jsonString, emitter); } catch (Exception e) { emitter.completeWithError(e); } @@ -166,6 +168,7 @@ public class ModelService { private void sendPostRequest (String apiUrl, String requestBody, SseEmitter emitter) throws IOException { // 创建 HttpClient 实例 HttpClient httpClient = HttpClients.createDefault(); + // 创建 HttpPost 请求对象 HttpPost httpPost = new HttpPost(apiUrl); @@ -188,11 +191,15 @@ public class ModelService { */ private void setupRequest (HttpPost httpPost, String requestBody) throws IOException { // 创建 StringEntity 对象,用于封装请求体 - StringEntity entity = new StringEntity(requestBody); + StringEntity entity = new StringEntity( + requestBody, + // 自动设置Content-Type为application/json; charset=UTF-8 + ContentType.APPLICATION_JSON + ); // 设置请求体 httpPost.setEntity(entity); // 设置请求头,指定请求体的内容类型为 JSON - httpPost.setHeader("Content-Type", "application/json"); +// httpPost.setHeader("Content-Type", "application/json"); httpPost.setHeader("Accept-Encoding", "gzip, deflate, br"); httpPost.setHeader("Accept", "*/*"); httpPost.setHeader("Connection", "keep-alive");