debug: rag-chat sendMessage 添加详细日志定位 AI Gateway 调用失败原因
Some checks failed
Deploy API Server / build-and-deploy (push) Failing after 21s
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:
parent
d8877f926f
commit
ce43256690
@ -53,6 +53,7 @@ export class RagChatService {
|
|||||||
|
|
||||||
// Retrieve knowledge base context
|
// Retrieve knowledge base context
|
||||||
const context = await this.loadContext(session.knowledgeBaseId);
|
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
|
// Generate AI response
|
||||||
let reply: string;
|
let reply: string;
|
||||||
@ -60,6 +61,7 @@ export class RagChatService {
|
|||||||
|
|
||||||
if (this.aiGateway && context.text) {
|
if (this.aiGateway && context.text) {
|
||||||
try {
|
try {
|
||||||
|
this.logger.log(`Calling AI Gateway with ${context.text.length} chars context`);
|
||||||
const messages = [
|
const messages = [
|
||||||
{ role: 'system' as const, content: this.buildSystemPrompt(context.text) },
|
{ role: 'system' as const, content: this.buildSystemPrompt(context.text) },
|
||||||
{ role: 'user' as const, content },
|
{ role: 'user' as const, content },
|
||||||
@ -73,13 +75,15 @@ export class RagChatService {
|
|||||||
messages,
|
messages,
|
||||||
maxTokens: 2048,
|
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 暂时无法生成回答。');
|
reply = resp.parsed?.answer ?? String(resp.parsed?.content ?? '抱歉,AI 暂时无法生成回答。');
|
||||||
citations = context.citations;
|
citations = context.citations;
|
||||||
} catch (err: any) {
|
} 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);
|
reply = this.fallbackReply(context.isEmpty);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
this.logger.warn(`Falling back: aiGateway=${!!this.aiGateway}, hasText=${!!context.text}`);
|
||||||
reply = this.fallbackReply(context.isEmpty);
|
reply = this.fallbackReply(context.isEmpty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user