debug: rag-chat sendMessage 添加详细日志定位 AI Gateway 调用失败原因
Some checks failed
Deploy API Server / build-and-deploy (push) Failing after 21s

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
wangdl 2026-06-06 13:56:28 +08:00
parent d8877f926f
commit ce43256690

View File

@ -53,6 +53,7 @@ export class RagChatService {
// Retrieve knowledge base context
const context = await this.loadContext(session.knowledgeBaseId);
this.logger.log(`RAG context: isEmpty=${context.isEmpty}, textLen=${context.text.length}, citations=${context.citations.length}, aiGateway=${!!this.aiGateway}`);
// Generate AI response
let reply: string;
@ -60,6 +61,7 @@ export class RagChatService {
if (this.aiGateway && context.text) {
try {
this.logger.log(`Calling AI Gateway with ${context.text.length} chars context`);
const messages = [
{ role: 'system' as const, content: this.buildSystemPrompt(context.text) },
{ role: 'user' as const, content },
@ -73,13 +75,15 @@ export class RagChatService {
messages,
maxTokens: 2048,
});
this.logger.log(`AI Gateway response: parsed=${!!resp.parsed}, rawLen=${resp.rawText?.length ?? 0}`);
reply = resp.parsed?.answer ?? String(resp.parsed?.content ?? '抱歉AI 暂时无法生成回答。');
citations = context.citations;
} catch (err: any) {
this.logger.error('AI Gateway failed, falling back', err?.message);
this.logger.error(`AI Gateway FAILED: ${err?.message}`, err?.stack?.substring(0, 300));
reply = this.fallbackReply(context.isEmpty);
}
} else {
this.logger.warn(`Falling back: aiGateway=${!!this.aiGateway}, hasText=${!!context.text}`);
reply = this.fallbackReply(context.isEmpty);
}