feat: add json schema support

This commit is contained in:
Han Xiao 2025-03-03 10:58:00 +08:00
parent 7c035f59c5
commit ebec1bc713
2 changed files with 6 additions and 4 deletions

View File

@ -493,7 +493,6 @@ app.post('/v1/chat/completions', (async (req: Request, res: Response) => {
if (responseSchema) {
try {
console.log('hello2')
const generator = new ObjectGeneratorSafe(context?.tokenTracker);
const result = await generator.generateObject({
model: 'agent',
@ -539,7 +538,7 @@ app.post('/v1/chat/completions', (async (req: Request, res: Response) => {
system_fingerprint: 'fp_' + requestId,
choices: [{
index: 0,
delta: {content: finalAnswer, type: "text"},
delta: {content: finalAnswer, type: responseSchema? 'json': 'text'},
logprobs: null,
finish_reason: 'stop'
}],
@ -561,7 +560,8 @@ app.post('/v1/chat/completions', (async (req: Request, res: Response) => {
index: 0,
message: {
role: 'assistant',
content: finalStep.action === 'answer' ? (finalAnswer || '') : finalStep.think
content: finalStep.action === 'answer' ? (finalAnswer || '') : finalStep.think,
type: responseSchema? 'json': 'text'
},
logprobs: null,
finish_reason: 'stop'
@ -649,7 +649,8 @@ app.post('/v1/chat/completions', (async (req: Request, res: Response) => {
index: 0,
message: {
role: 'assistant',
content: `Error: ${errorMessage}`
content: `Error: ${errorMessage}`,
type: 'error'
},
logprobs: null,
finish_reason: 'stop'

View File

@ -213,6 +213,7 @@ export interface ChatCompletionResponse {
message: {
role: 'assistant';
content: string;
type: 'text' | 'think' | 'json' | 'error';
};
logprobs: null;
finish_reason: 'stop';