From ce4325669051c2c81f2a9786f6003f84e527cb8f Mon Sep 17 00:00:00 2001 From: wangdl Date: Sat, 6 Jun 2026 13:56:28 +0800 Subject: [PATCH] =?UTF-8?q?debug:=20rag-chat=20sendMessage=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=AF=A6=E7=BB=86=E6=97=A5=E5=BF=97=E5=AE=9A=E4=BD=8D?= =?UTF-8?q?=20AI=20Gateway=20=E8=B0=83=E7=94=A8=E5=A4=B1=E8=B4=A5=E5=8E=9F?= =?UTF-8?q?=E5=9B=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.7 --- src/modules/rag-chat/rag-chat.service.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/modules/rag-chat/rag-chat.service.ts b/src/modules/rag-chat/rag-chat.service.ts index 1026ab4..25cb486 100644 --- a/src/modules/rag-chat/rag-chat.service.ts +++ b/src/modules/rag-chat/rag-chat.service.ts @@ -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); }