AI 提问追问环境demo,以及评分处理
This commit is contained in:
@@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil;
|
|||||||
import cn.hutool.json.JSONObject;
|
import cn.hutool.json.JSONObject;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.vetti.common.ai.elevenLabs.ElevenLabsClient;
|
import com.vetti.common.ai.elevenLabs.ElevenLabsClient;
|
||||||
|
import com.vetti.common.ai.gpt.ChatGPTClient;
|
||||||
import com.vetti.common.ai.gpt.OpenAiStreamClient;
|
import com.vetti.common.ai.gpt.OpenAiStreamClient;
|
||||||
import com.vetti.common.ai.gpt.service.OpenAiStreamListenerService;
|
import com.vetti.common.ai.gpt.service.OpenAiStreamListenerService;
|
||||||
import com.vetti.common.ai.whisper.WhisperClient;
|
import com.vetti.common.ai.whisper.WhisperClient;
|
||||||
@@ -145,7 +146,7 @@ public class ChatWebSocketHandler {
|
|||||||
String cacheResultText = cacheClientTts.get(clientId);
|
String cacheResultText = cacheClientTts.get(clientId);
|
||||||
log.info("面试者回答信息为:{}", cacheResultText);
|
log.info("面试者回答信息为:{}", cacheResultText);
|
||||||
if (StrUtil.isEmpty(cacheResultText)) {
|
if (StrUtil.isEmpty(cacheResultText)) {
|
||||||
cacheResultText = "Hi.";
|
cacheResultText = "I am answering";
|
||||||
}
|
}
|
||||||
String promptJson = "";
|
String promptJson = "";
|
||||||
if("YES".equals(startFlag)) {
|
if("YES".equals(startFlag)) {
|
||||||
@@ -294,27 +295,12 @@ public class ChatWebSocketHandler {
|
|||||||
cacheMsgMapData.put(session.getId(),"");
|
cacheMsgMapData.put(session.getId(),"");
|
||||||
}
|
}
|
||||||
log.info("结束AI提示词为:{}",promptJson);
|
log.info("结束AI提示词为:{}",promptJson);
|
||||||
OpenAiStreamClient aiStreamClient = SpringUtils.getBean(OpenAiStreamClient.class);
|
ChatGPTClient gptClient = SpringUtils.getBean(ChatGPTClient.class);
|
||||||
aiStreamClient.streamChat(promptJson, new OpenAiStreamListenerService() {
|
String resultMsg = gptClient.handleAiChat(promptJson);
|
||||||
@Override
|
Map<String, String> resultEntity = new HashMap<>();
|
||||||
public void onMessage(String content) {
|
resultEntity.put("msg", resultMsg);
|
||||||
log.info("返回AI结果:{}", content);
|
resultEntity.put("dataType","score");
|
||||||
try {
|
session.getBasicRemote().sendText(JSONUtil.toJsonStr(resultEntity));
|
||||||
//发送文件流数据
|
|
||||||
session.getBasicRemote().sendText(content);
|
|
||||||
}catch (Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onComplete() {
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void onError(Throwable throwable) {
|
|
||||||
throwable.printStackTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.vetti.common.ai.gpt;
|
package com.vetti.common.ai.gpt;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
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 {
|
private String sendMessage(String prompt, String model,ObjectMapper objectMapper,HttpClient client,String role) throws IOException, InterruptedException {
|
||||||
// 创建消息列表
|
// 创建消息列表
|
||||||
List<Map<String, String>> messages = new ArrayList<>();
|
List<Map> messages = JSONUtil.toList(prompt, Map.class);
|
||||||
Map<String, String> message = new HashMap<>();
|
|
||||||
message.put("role", role);
|
// Map<String, String> message = new HashMap<>();
|
||||||
message.put("content", prompt);
|
// message.put("role", role);
|
||||||
messages.add(message);
|
// message.put("content", prompt);
|
||||||
|
// messages.add(message);
|
||||||
|
|
||||||
return sendChatRequest(messages, model, 0.7,objectMapper,client);
|
return sendChatRequest(messages, model, 0.7,objectMapper,client);
|
||||||
}
|
}
|
||||||
@@ -89,7 +91,7 @@ public class ChatGPTClient {
|
|||||||
* @throws IOException 网络或IO异常
|
* @throws IOException 网络或IO异常
|
||||||
* @throws InterruptedException 线程中断异常
|
* @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 {
|
throws IOException, InterruptedException {
|
||||||
// 构建请求体
|
// 构建请求体
|
||||||
Map<String, Object> requestBody = new HashMap<>();
|
Map<String, Object> requestBody = new HashMap<>();
|
||||||
|
|||||||
Reference in New Issue
Block a user