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); }