聊天相关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
+44 -2
View File
@@ -11,6 +11,7 @@ import { DataManager, DataId } from "../data/DataManager";
import { GirlData } from "../data/GirlData";
import proto from "db://assets/Scripts/proto/proto.pb.js";
import { TipsPanel } from "../ui/panels/TipsPanel";
import LanguageUtils from "../../Main/Common/LanguageUtils";
/**
* AI聊天服务类
@@ -48,12 +49,18 @@ export class ChatAIService {
{ config },
true
);
TipsPanel.show(LanguageUtils.getText("chat_error_code_2002"));
throw new Error("AI服务初始化失败:配置无效");
}
try {
this.ai = new GoogleGenAI({ apiKey: config.apiKey });
this.ai = new GoogleGenAI({
apiKey: config.apiKey,
httpOptions: { timeout: ApiConfig.Instance.getTimeout() },
});
} catch (error) {
TipsPanel.show(LanguageUtils.getText("chat_error_code_2001"));
ErrorHandler.Instance.handleError(
error as Error,
ErrorType.API_ERROR,
@@ -102,6 +109,23 @@ export class ChatAIService {
category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
threshold: HarmBlockThreshold.BLOCK_NONE,
},
{
category: HarmCategory.HARM_CATEGORY_CIVIC_INTEGRITY,
threshold: HarmBlockThreshold.BLOCK_NONE,
},
{
category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
threshold: HarmBlockThreshold.BLOCK_NONE,
},
{
category: HarmCategory.HARM_CATEGORY_HARASSMENT,
threshold: HarmBlockThreshold.BLOCK_NONE,
},
{
category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
threshold: HarmBlockThreshold.BLOCK_NONE,
},
],
},
history: savedHistory,
@@ -120,6 +144,23 @@ export class ChatAIService {
category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
threshold: HarmBlockThreshold.BLOCK_NONE,
},
{
category: HarmCategory.HARM_CATEGORY_CIVIC_INTEGRITY,
threshold: HarmBlockThreshold.BLOCK_NONE,
},
{
category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
threshold: HarmBlockThreshold.BLOCK_NONE,
},
{
category: HarmCategory.HARM_CATEGORY_HARASSMENT,
threshold: HarmBlockThreshold.BLOCK_NONE,
},
{
category: HarmCategory.HARM_CATEGORY_HATE_SPEECH,
threshold: HarmBlockThreshold.BLOCK_NONE,
},
],
},
});
@@ -245,6 +286,7 @@ export class ChatAIService {
return response.text;
} else {
TipsPanel.show(response.promptFeedback.blockReason);
const warningMsg = `AI返回了空响应 (角色ID: ${roleId})`;
ErrorHandler.Instance.handleError(
new Error(warningMsg),
@@ -257,7 +299,7 @@ export class ChatAIService {
} catch (error) {
ErrorHandler.Instance.handleApiError(error, "sendMessage", {
roleId,
message: message.substring(0, 100) + "...",
message: message,
});
TipsPanel.show("api调用失败,请使用vpn并重新启动");
return null;