fix: rag-chat 传入 outputSchema= RagChatOutputSchema,修复 parsed 为空对象
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 42s
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 42s
parseJson 无 schema 时直接返回 {},导致 resp.parsed?.answer 始终为 null。
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
69bcd07a0f
commit
f4de598d96
@ -1,6 +1,9 @@
|
|||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
export const RagChatOutputSchema = z.object({
|
||||||
|
answer: z.string().min(1).max(5000),
|
||||||
|
});
|
||||||
|
|
||||||
export const RAG_CHAT_OUTPUT_SCHEMA_DESC = `{
|
export const RAG_CHAT_OUTPUT_SCHEMA_DESC = `{
|
||||||
"answer": "你的回答内容",
|
"answer": "你的回答内容"
|
||||||
"citations": [
|
|
||||||
{ "title": "引用的知识点标题", "snippet": "引用的原文片段" }
|
|
||||||
]
|
|
||||||
}`;
|
}`;
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import { Injectable, NotFoundException, Logger, Optional } from '@nestjs/common'
|
|||||||
import { PrismaService } from '../../infrastructure/database/prisma.service';
|
import { PrismaService } from '../../infrastructure/database/prisma.service';
|
||||||
import { ContentSafetyService } from '../content-safety/content-safety.service';
|
import { ContentSafetyService } from '../content-safety/content-safety.service';
|
||||||
import { AiGatewayService } from '../ai/gateway/ai-gateway.service';
|
import { AiGatewayService } from '../ai/gateway/ai-gateway.service';
|
||||||
|
import { RagChatOutputSchema } from '../ai/prompts/schemas/rag-chat.schema';
|
||||||
|
|
||||||
const MAX_CONTEXT_CHARS = 4000;
|
const MAX_CONTEXT_CHARS = 4000;
|
||||||
|
|
||||||
@ -75,6 +76,7 @@ export class RagChatService {
|
|||||||
promptVersion: 'v1',
|
promptVersion: 'v1',
|
||||||
messages,
|
messages,
|
||||||
maxTokens: 2048,
|
maxTokens: 2048,
|
||||||
|
outputSchema: RagChatOutputSchema,
|
||||||
});
|
});
|
||||||
this.logger.log(`AI Gateway response: parsed=${!!resp.parsed}, keys=${resp.parsed ? Object.keys(resp.parsed).join(',') : 'null'}, raw=${JSON.stringify(resp.parsed).substring(0, 300)}`);
|
this.logger.log(`AI Gateway response: parsed=${!!resp.parsed}, keys=${resp.parsed ? Object.keys(resp.parsed).join(',') : 'null'}, raw=${JSON.stringify(resp.parsed).substring(0, 300)}`);
|
||||||
reply = resp.parsed?.answer ?? String(resp.parsed?.content ?? '抱歉,AI 暂时无法生成回答。');
|
reply = resp.parsed?.answer ?? String(resp.parsed?.content ?? '抱歉,AI 暂时无法生成回答。');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user