AI 提问追问环境demo,以及评分处理

This commit is contained in:
2025-10-27 22:09:57 +08:00
parent 14b803609e
commit 45f3357962
2 changed files with 16 additions and 28 deletions

View File

@@ -1,5 +1,6 @@
package com.vetti.common.ai.gpt;
import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Value;
@@ -71,11 +72,12 @@ public class ChatGPTClient {
*/
private String sendMessage(String prompt, String model,ObjectMapper objectMapper,HttpClient client,String role) throws IOException, InterruptedException {
// 创建消息列表
List<Map<String, String>> messages = new ArrayList<>();
Map<String, String> message = new HashMap<>();
message.put("role", role);
message.put("content", prompt);
messages.add(message);
List<Map> messages = JSONUtil.toList(prompt, Map.class);
// Map<String, String> message = new HashMap<>();
// message.put("role", role);
// message.put("content", prompt);
// messages.add(message);
return sendChatRequest(messages, model, 0.7,objectMapper,client);
}
@@ -89,7 +91,7 @@ public class ChatGPTClient {
* @throws IOException 网络或IO异常
* @throws InterruptedException 线程中断异常
*/
private String sendChatRequest(List<Map<String, String>> messages, String model, double temperature,ObjectMapper objectMapper,HttpClient client)
private String sendChatRequest(List<Map> messages, String model, double temperature,ObjectMapper objectMapper,HttpClient client)
throws IOException, InterruptedException {
// 构建请求体
Map<String, Object> requestBody = new HashMap<>();