style: prettier format

This commit is contained in:
AnotiaWang
2025-02-11 22:57:49 +08:00
parent 84f63abb3d
commit d027965013
23 changed files with 485 additions and 331 deletions

View File

@ -1,22 +1,22 @@
import { streamText } from 'ai';
import { z } from 'zod';
import { streamText } from 'ai'
import { z } from 'zod'
import { zodToJsonSchema } from 'zod-to-json-schema'
import { o3MiniModel } from './ai/providers';
import { systemPrompt } from './prompt';
import { o3MiniModel } from './ai/providers'
import { systemPrompt } from './prompt'
type PartialFeedback = DeepPartial<z.infer<typeof feedbackTypeSchema>>
export const feedbackTypeSchema = z.object({
questions: z.array(z.string())
questions: z.array(z.string()),
})
export function generateFeedback({
query,
numQuestions = 3,
}: {
query: string;
numQuestions?: number;
query: string
numQuestions?: number
}) {
const schema = z.object({
questions: z
@ -24,22 +24,22 @@ export function generateFeedback({
.describe(
`Follow up questions to clarify the research direction, max of ${numQuestions}`,
),
});
const jsonSchema = JSON.stringify(zodToJsonSchema(schema));
})
const jsonSchema = JSON.stringify(zodToJsonSchema(schema))
const prompt = [
`Given the following query from the user, ask some follow up questions to clarify the research direction. Return a maximum of ${numQuestions} questions, but feel free to return less if the original query is clear: <query>${query}</query>`,
`You MUST respond in JSON with the following schema: ${jsonSchema}`,
].join('\n\n');
].join('\n\n')
const stream = streamText({
model: o3MiniModel,
system: systemPrompt(),
prompt,
});
})
return parseStreamingJson(
stream.textStream,
feedbackTypeSchema,
(value: PartialFeedback) => !!value.questions && value.questions.length > 0
(value: PartialFeedback) => !!value.questions && value.questions.length > 0,
)
}