聊天相关fix

This commit is contained in:
2025-09-20 20:37:31 +08:00
parent 86282eec31
commit b8a417632a
22 changed files with 2423 additions and 398 deletions
@@ -40,7 +40,10 @@ export class EmotionAIService {
const emotionConfig = ApiConfig.Instance.getEmotionAIConfig();
try {
this.emotionAI = new GoogleGenAI({ apiKey: emotionConfig.apiKey });
this.emotionAI = new GoogleGenAI({
apiKey: emotionConfig.apiKey,
httpOptions: { timeout: emotionConfig.timeout },
});
} catch (error) {
ErrorHandler.Instance.handleError(
error as Error,
@@ -109,7 +112,9 @@ export class EmotionAIService {
// 分析历史情绪状态
emotionalState = await this.analyzeEmotionalState(roleId);
if (emotionalState == null) {
emotionalState = VideoEmotion.calm_down;
}
console.log(
`Initial emotional state for role ${roleId}: ${VideoEmotion[emotionalState]}`
);
@@ -185,7 +190,7 @@ export class EmotionAIService {
"角色ID必须是正整数",
roleId
);
return VideoEmotion.calm_down;
return null;
}
if (!message || message.trim() === "") {
@@ -194,7 +199,7 @@ export class EmotionAIService {
"消息内容不能为空",
message
);
return VideoEmotion.calm_down;
return null;
}
try {
@@ -214,14 +219,14 @@ export class EmotionAIService {
{ roleId, message, response },
true
);
return VideoEmotion.calm_down;
return null;
}
} catch (error) {
ErrorHandler.Instance.handleApiError(error, "sendEmotionMessage", {
roleId,
message: message.substring(0, 100) + "...",
});
return VideoEmotion.calm_down;
return null;
}
}
@@ -251,7 +256,7 @@ export class EmotionAIService {
{ roleId },
false
);
return VideoEmotion.calm_down;
return null;
}
}
@@ -376,8 +381,11 @@ export class EmotionAIService {
);
// 发送给情绪AI进行分析
const newEmotion = await this.sendEmotionMessage(roleId, analysisPrompt);
let newEmotion = await this.sendEmotionMessage(roleId, analysisPrompt);
if (newEmotion == null) {
newEmotion = currentEmotion;
}
// 更新并保存情绪状态
this.setCurrentEmotion(roleId, newEmotion);