refactor: make requests purely client-side

This commit is contained in:
AnotiaWang
2025-02-11 22:28:58 +08:00
parent 066aafa9b2
commit 84f63abb3d
4 changed files with 43 additions and 66 deletions

View File

@ -5,6 +5,8 @@ import { zodToJsonSchema } from 'zod-to-json-schema'
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())
})
@ -28,10 +30,16 @@ export function generateFeedback({
`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');
return streamText({
const stream = streamText({
model: o3MiniModel,
system: systemPrompt(),
prompt,
});
// return userFeedback.object.questions.slice(0, numQuestions);
return parseStreamingJson(
stream.textStream,
feedbackTypeSchema,
(value: PartialFeedback) => !!value.questions && value.questions.length > 0
)
}