This commit is contained in:
2025-10-13 17:09:39 +08:00
parent 347a7292cc
commit 104e7f566c
9 changed files with 376 additions and 230 deletions
+17 -2
View File
@@ -43,6 +43,7 @@ export class ChatAIService {
private ai: GoogleGenAI;
private chatInstances: Map<number, any> = new Map();
private currentRoleId: number | null = null;
private shouldShowErrorTips: boolean = true; // 控制是否显示错误提示
private constructor() {
const config = ApiConfig.Instance.getAIConfig();
@@ -98,6 +99,14 @@ export class ChatAIService {
return this._instance;
}
/**
* 设置是否显示错误提示
* @param show 是否显示
*/
public setShouldShowErrorTips(show: boolean): void {
this.shouldShowErrorTips = show;
}
/**
* 创建或获取指定角色的聊天实例
* @param roleId 角色ID
@@ -306,7 +315,10 @@ export class ChatAIService {
return response.text;
} else {
TipsPanel.show(response.promptFeedback.blockReason);
// 只在允许显示错误提示时才显示
if (this.shouldShowErrorTips) {
TipsPanel.show(response.promptFeedback.blockReason);
}
const warningMsg = `AI返回了空响应 (角色ID: ${roleId})`;
ErrorHandler.Instance.handleError(
new Error(warningMsg),
@@ -321,7 +333,10 @@ export class ChatAIService {
roleId,
message: message,
});
TipsPanel.show("api调用失败,请使用vpn并重新启动");
// 只在允许显示错误提示时才显示
if (this.shouldShowErrorTips) {
TipsPanel.show("api调用失败,请使用vpn并重新启动");
}
return null;
}
}