结束评分结果逻辑修改

This commit is contained in:
2025-11-12 21:13:11 +08:00
parent 88840a1f40
commit bc4670ad59
5 changed files with 76 additions and 32 deletions

View File

@@ -7,8 +7,6 @@ import cn.hutool.core.util.StrUtil;
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.ChatGPTClient;
import com.vetti.common.ai.gpt.OpenAiStreamClient;
import com.vetti.common.ai.gpt.service.OpenAiStreamListenerService;
import com.vetti.common.config.RuoYiConfig; import com.vetti.common.config.RuoYiConfig;
import com.vetti.common.utils.spring.SpringUtils; import com.vetti.common.utils.spring.SpringUtils;
import com.vetti.hotake.domain.HotakeProblemBaseInfo; import com.vetti.hotake.domain.HotakeProblemBaseInfo;
@@ -145,7 +143,6 @@ public class ChatWebSocketHandler {
if (StrUtil.isEmpty(cacheResultText)) { if (StrUtil.isEmpty(cacheResultText)) {
cacheResultText = ""; cacheResultText = "";
} }
//这是初次处理的逻辑 //这是初次处理的逻辑
if ("YES".equals(startFlag)) { if ("YES".equals(startFlag)) {
//初始化-不走大模型-直接对候选人进行提问 //初始化-不走大模型-直接对候选人进行提问
@@ -176,37 +173,43 @@ public class ChatWebSocketHandler {
//把提问的文字发送给GPT //把提问的文字发送给GPT
ChatGPTClient chatGPTClient = SpringUtils.getBean(ChatGPTClient.class); ChatGPTClient chatGPTClient = SpringUtils.getBean(ChatGPTClient.class);
log.info("AI提示词为:{}", promptJson); log.info("AI提示词为:{}", promptJson);
log.info("开始请求AI:{}",System.currentTimeMillis()/1000);
String resultMsg = chatGPTClient.handleAiChat(promptJson,"QA"); String resultMsg = chatGPTClient.handleAiChat(promptJson,"QA");
if(StrUtil.isNotEmpty(resultMsg)) { if(StrUtil.isNotEmpty(resultMsg)) {
//开始解析返回结果 //开始解析返回结果
Map mapResultData = JSONUtil.toBean(resultMsg,Map.class); Map mapResultData = JSONUtil.toBean(resultMsg,Map.class);
//获取评分 //验证是否有追问问题返回,如果没有问题返回直接返回评分停止面试
//验证是否触发对应的规则 Boolean isEndFlagFollow = checkInterviewIsEnd(resultMsg,session);
Boolean isEndFlag = getInterviewScore(resultMsg, session); if(isEndFlagFollow){
if(isEndFlag){ //获取评分
log.info("面试回答符合条件规则,继续追问啦!!!!!"); //验证是否触发对应的规则
int resultNum = (int) (Math.random() * 2); Boolean isEndFlag = getInterviewScore(resultMsg, session);
List<String> questions = JSONUtil.toList(mapResultData.get("follow_up_questions").toString(), String.class); if(isEndFlag){
String questionStr = questions.get(resultNum); log.info("面试回答符合条件规则,继续追问啦!!!!!");
if (StrUtil.isNotEmpty(questionStr)) { int resultNum = (int) (Math.random() * 2);
//开始进行语音输出-流式持续输出 List<String> questions = JSONUtil.toList(mapResultData.get("follow_up_questions").toString(), String.class);
sendTTSBuffer(clientId, questionStr, session); String questionStr = questions.get(resultNum);
// 实时输出内容 if (StrUtil.isNotEmpty(questionStr)) {
try { //开始进行语音输出-流式持续输出
//把文本也给前端返回去 sendTTSBuffer(clientId, questionStr, session);
Map<String, String> dataText = new HashMap<>(); // 实时输出内容
dataText.put("type", "question"); try {
dataText.put("content", questionStr); //把文本也给前端返回去
log.info("提问的问题文本发送啦:{}",JSONUtil.toJsonStr(dataText)); Map<String, String> dataText = new HashMap<>();
session.getBasicRemote().sendText(JSONUtil.toJsonStr(dataText)); dataText.put("type", "question");
} catch (Exception e) { dataText.put("content", questionStr);
e.printStackTrace(); log.info("提问的问题文本发送啦:{}",JSONUtil.toJsonStr(dataText));
session.getBasicRemote().sendText(JSONUtil.toJsonStr(dataText));
} catch (Exception e) {
e.printStackTrace();
}
//开始对问题进行缓存
recordQuestion(questionStr,session);
} }
//开始对问题进行缓存
recordQuestion(questionStr,session);
} }
} }
} }
log.info("结束请求AI:{}",System.currentTimeMillis()/1000);
} }
} else if ("end".equals(resultFlag)) { } else if ("end".equals(resultFlag)) {
log.info("面试结束啦!!!!!"); log.info("面试结束啦!!!!!");
@@ -242,8 +245,16 @@ public class ChatWebSocketHandler {
// 发生错误时调用 // 发生错误时调用
@OnError @OnError
public void onError(Session session, Throwable throwable) { public void onError(Session session, Throwable throwable) {
System.err.println("WebSocket错误发生: " + throwable.getMessage()); System.err.println("WebSocket发生错误: 页面关闭,链接断开了");
throwable.printStackTrace(); if(session != null) {
//是初次自我介绍后的问答环节
cacheReplyFlag.put(session.getId(), "");
//初始化面试回答数据记录
cacheMsgMapData.put(session.getId(), "");
//初始化面试问题
cacheQuestionResult.put(session.getId(), "");
cacheScoreResult.put(session.getId(), null);
}
} }
/** /**
@@ -528,5 +539,38 @@ public class ChatWebSocketHandler {
} }
} }
/**
* 验证面试是否结束,不继续追问了
* @param resultMsg
* @param session
* @return
*/
private Boolean checkInterviewIsEnd(String resultMsg, Session session){
Map mapResultData = JSONUtil.toBean(resultMsg,Map.class);
//获取评分
Object scoreStr = mapResultData.get("score");
Object assessment = mapResultData.get("assessment");
Object followUpNeeded = mapResultData.get("follow_up_needed");
Boolean flag = Boolean.valueOf(followUpNeeded.toString());
try {
//不继续追问了
if (ObjectUtil.isNotEmpty(followUpNeeded) && !flag) {
//发送面试官结束语音流
String openingPathUrl = RuoYiConfig.getProfile() + VOICE_SYSTEM_DIR + "end.wav";
sendVoiceBuffer(openingPathUrl, session);
Map<String, String> resultEntity = new HashMap<>();
resultEntity.put("content", scoreStr +"\n"+assessment);
resultEntity.put("type", "score");
//返回评分结果
log.info("返回最终的评分结果:{}",JSONUtil.toJsonStr(resultEntity));
session.getBasicRemote().sendText(JSONUtil.toJsonStr(resultEntity));
}
} catch (Exception e) {
e.printStackTrace();
}
return flag;
}
} }

View File

@@ -53,7 +53,7 @@ public class AiCommonController extends BaseController
//你好,我是本次的面试官Vetti,请点击开始按钮后,做一段自我介绍. //你好,我是本次的面试官Vetti,请点击开始按钮后,做一段自我介绍.
//你好,我是本次的面试官Vetti,请在三秒后,开始做一段自我介绍. //你好,我是本次的面试官Vetti,请在三秒后,开始做一段自我介绍.
//本轮面试结束,谢谢您的配合,面试结果将稍后通知 //本轮面试结束,谢谢您的配合,面试结果将稍后通知
elevenLabsClient.handleTextToVoice("Ok, I have received your reply.","/Users/wangxiangshun/Desktop/临时文件/good.wav"); elevenLabsClient.handleTextToVoice("Yeah","/Users/wangxiangshun/Desktop/临时文件/Yeah.wav");
return success(); return success();
} }

View File

@@ -156,7 +156,7 @@ whisper:
apiKey: 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 apiKey: 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
language: en language: en
apiClientTokenUrl: https://api.openai.com/v1/realtime/sessions apiClientTokenUrl: https://api.openai.com/v1/realtime/sessions
prompt: This is a clear conversation in English. The user is speaking naturally through their device microphone. Please transcribe accurately with proper punctuation and natural speech patterns. prompt: You are a translator. Detect when the user stops speaking. When a full sentence is complete, send recognized text as type:\'transcript\', and send its English translation as type:\'translation\'.
# AI 聊天 # AI 聊天

View File

@@ -163,7 +163,7 @@ whisper:
apiKey: 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 apiKey: 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
language: en language: en
apiClientTokenUrl: https://api.openai.com/v1/realtime/sessions apiClientTokenUrl: https://api.openai.com/v1/realtime/sessions
prompt: This is a clear conversation in English. The user is speaking naturally through their device microphone. Please transcribe accurately with proper punctuation and natural speech patterns. prompt: You are a translator. Detect when the user stops speaking. When a full sentence is complete, send recognized text as type:\'transcript\', and send its English translation as type:\'translation\'.
# AI 聊天 # AI 聊天
chatGpt: chatGpt:

View File

@@ -163,7 +163,7 @@ whisper:
apiKey: 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 apiKey: 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
language: en language: en
apiClientTokenUrl: https://api.openai.com/v1/realtime/sessions apiClientTokenUrl: https://api.openai.com/v1/realtime/sessions
prompt: This is a clear conversation in English. The user is speaking naturally through their device microphone. Please transcribe accurately with proper punctuation and natural speech patterns. prompt: You are a translator. Detect when the user stops speaking. When a full sentence is complete, send recognized text as type:\'transcript\', and send its English translation as type:\'translation\'.
# AI 聊天 # AI 聊天
chatGpt: chatGpt: