- MVP架构重构聊天逻辑
- 优化聊天气泡体验 - 修复prompt bug - 实现聊天次数限制功能(未接服务端) - 实现情绪切视频功能
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// 首先加载 polyfills 以确保兼容性
|
||||
import "../utils/polyfills";
|
||||
import { GoogleGenAI } from "@google/genai";
|
||||
import { GoogleGenAI, HarmBlockThreshold, HarmCategory } from "@google/genai";
|
||||
import { RoleConfigLoader } from "./RoleConfigLoader";
|
||||
import { ChatHistoryManager } from "../manager/ChatHistoryManager";
|
||||
import { ApiConfig } from "./ApiConfigLoader";
|
||||
@@ -90,6 +90,12 @@ export class ChatAIService {
|
||||
config: {
|
||||
temperature: config.temperature,
|
||||
systemInstruction: systemInstruction,
|
||||
safetySettings: [
|
||||
{
|
||||
category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
|
||||
threshold: HarmBlockThreshold.BLOCK_NONE,
|
||||
},
|
||||
],
|
||||
},
|
||||
history: savedHistory,
|
||||
});
|
||||
@@ -99,6 +105,12 @@ export class ChatAIService {
|
||||
config: {
|
||||
temperature: config.temperature,
|
||||
systemInstruction: systemInstruction,
|
||||
safetySettings: [
|
||||
{
|
||||
category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
|
||||
threshold: HarmBlockThreshold.BLOCK_NONE,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -190,13 +202,18 @@ export class ChatAIService {
|
||||
parts: [{ text: response.text }],
|
||||
});
|
||||
|
||||
// 更新情绪状态
|
||||
try {
|
||||
await EmotionAIService.Instance.updateEmotionFromChat(roleId, message, response.text);
|
||||
} catch (emotionError) {
|
||||
console.warn(`Failed to update emotion for role ${roleId}:`, emotionError);
|
||||
// 异步更新情绪状态(非阻塞)
|
||||
EmotionAIService.Instance.updateEmotionFromChat(
|
||||
roleId,
|
||||
message,
|
||||
response.text
|
||||
).catch(emotionError => {
|
||||
console.warn(
|
||||
`Failed to update emotion for role ${roleId}:`,
|
||||
emotionError
|
||||
);
|
||||
// 情绪更新失败不影响聊天功能
|
||||
}
|
||||
});
|
||||
} catch (storageError) {
|
||||
ErrorHandler.Instance.handleError(
|
||||
storageError as Error,
|
||||
@@ -213,7 +230,7 @@ export class ChatAIService {
|
||||
ErrorHandler.Instance.handleError(
|
||||
new Error(warningMsg),
|
||||
ErrorType.API_ERROR,
|
||||
{ roleId, message, response },
|
||||
{ roleId, chat, response },
|
||||
true
|
||||
);
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user