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

@@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
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.service.OpenAiStreamListenerService;
import com.vetti.common.ai.whisper.WhisperClient;
@@ -145,7 +146,7 @@ public class ChatWebSocketHandler {
String cacheResultText = cacheClientTts.get(clientId);
log.info("面试者回答信息为:{}", cacheResultText);
if (StrUtil.isEmpty(cacheResultText)) {
cacheResultText = "Hi.";
cacheResultText = "I am answering";
}
String promptJson = "";
if("YES".equals(startFlag)) {
@@ -294,27 +295,12 @@ public class ChatWebSocketHandler {
cacheMsgMapData.put(session.getId(),"");
}
log.info("结束AI提示词为:{}",promptJson);
OpenAiStreamClient aiStreamClient = SpringUtils.getBean(OpenAiStreamClient.class);
aiStreamClient.streamChat(promptJson, new OpenAiStreamListenerService() {
@Override
public void onMessage(String content) {
log.info("返回AI结果{}", content);
try {
//发送文件流数据
session.getBasicRemote().sendText(content);
}catch (Exception e){
e.printStackTrace();
}
}
@Override
public void onComplete() {
}
@Override
public void onError(Throwable throwable) {
throwable.printStackTrace();
}
});
ChatGPTClient gptClient = SpringUtils.getBean(ChatGPTClient.class);
String resultMsg = gptClient.handleAiChat(promptJson);
Map<String, String> resultEntity = new HashMap<>();
resultEntity.put("msg", resultMsg);
resultEntity.put("dataType","score");
session.getBasicRemote().sendText(JSONUtil.toJsonStr(resultEntity));
}
}
} catch (Exception e) {