adding web search to all recs
This commit is contained in:
@@ -1,23 +1,25 @@
|
||||
import { openai } from '../agent.js';
|
||||
import type { InterpreterOutput, RetrievalOutput } from '../types/agents.js';
|
||||
import { z } from 'zod';
|
||||
import { zodTextFormat } from 'openai/helpers/zod';
|
||||
|
||||
const RetrievalSchema = z.object({
|
||||
candidates: z.array(z.object({
|
||||
title: z.string(),
|
||||
reason: z.string()
|
||||
}))
|
||||
});
|
||||
|
||||
export async function runRetrieval(input: InterpreterOutput, brainstormCount = 100): Promise<RetrievalOutput> {
|
||||
const response = await openai.chat.completions.create({
|
||||
const response = await openai.responses.parse({
|
||||
model: 'gpt-5.4',
|
||||
temperature: 0.9,
|
||||
service_tier: 'flex',
|
||||
response_format: { type: 'json_object' },
|
||||
messages: [
|
||||
{
|
||||
role: 'system',
|
||||
content: `You are a TV show candidate generator. Your goal is to brainstorm a LARGE, DIVERSE pool of ${brainstormCount} TV show candidates that match the user's structured preferences.
|
||||
|
||||
Your output MUST be valid JSON matching this schema:
|
||||
{
|
||||
"candidates": [
|
||||
{ "title": string, "reason": string }
|
||||
]
|
||||
}
|
||||
tools: [
|
||||
{ type: 'web_search' }
|
||||
],
|
||||
text: { format: zodTextFormat(RetrievalSchema, "candidates") },
|
||||
instructions: `You are a TV show candidate generator. Your goal is to brainstorm a LARGE, DIVERSE pool of ${brainstormCount} TV show candidates that match the user's structured preferences.
|
||||
|
||||
Rules:
|
||||
- Include both well-known and obscure shows
|
||||
@@ -26,10 +28,7 @@ Rules:
|
||||
- Avoid duplicates
|
||||
- Include shows from different decades, countries, and networks
|
||||
- Aim for ${brainstormCount} candidates minimum`,
|
||||
},
|
||||
{
|
||||
role: 'user',
|
||||
content: `Structured preferences:
|
||||
input: `Structured preferences:
|
||||
Liked shows: ${JSON.stringify(input.liked)}
|
||||
Disliked shows: ${JSON.stringify(input.disliked)}
|
||||
Themes: ${JSON.stringify(input.themes)}
|
||||
@@ -38,10 +37,7 @@ Tone: ${JSON.stringify(input.tone)}
|
||||
Avoid: ${JSON.stringify(input.avoid)}
|
||||
|
||||
Generate a large, diverse pool of TV show candidates.`,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const content = response.choices[0]?.message?.content ?? '{"candidates":[]}';
|
||||
return JSON.parse(content) as RetrievalOutput;
|
||||
return (response.output_parsed as RetrievalOutput) ?? { candidates: [] };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user