adding web search to all recs

This commit is contained in:
2026-03-26 20:13:31 -03:00
parent f9f3d95406
commit 6fdfc3797a
7 changed files with 86 additions and 109 deletions

View File

@@ -1,5 +1,16 @@
import { openai } from '../agent.js';
import type { InterpreterOutput } from '../types/agents.js';
import { z } from 'zod';
import { zodTextFormat } from 'openai/helpers/zod';
const InterpreterSchema = z.object({
liked: z.array(z.string()),
disliked: z.array(z.string()),
themes: z.array(z.string()),
character_preferences: z.array(z.string()),
tone: z.array(z.string()),
avoid: z.array(z.string())
});
interface InterpreterInput {
main_prompt: string;
@@ -14,25 +25,12 @@ export async function runInterpreter(input: InterpreterInput): Promise<Interpret
? `\n\nUser Feedback Context (incorporate into preferences):\n${input.feedback_context}`
: '';
const response = await openai.chat.completions.create({
const response = await openai.responses.parse({
model: 'gpt-5.4-mini',
temperature: 0.2,
service_tier: 'flex',
response_format: { type: 'json_object' },
messages: [
{
role: 'system',
content: `You are a TV show preference interpreter. Transform raw user input into structured, normalized preferences.
Your output MUST be valid JSON matching this schema:
{
"liked": string[], // shows the user likes
"disliked": string[], // shows the user dislikes
"themes": string[], // normalized themes (e.g. "spy" -> "espionage")
"character_preferences": string[], // character types they prefer
"tone": string[], // tone descriptors (e.g. "serious", "grounded", "dark")
"avoid": string[] // things to explicitly avoid
}
text: { format: zodTextFormat(InterpreterSchema, "preferences") },
instructions: `You are a TV show preference interpreter. Transform raw user input into structured, normalized preferences.
Rules:
- Extract implicit preferences from the main prompt
@@ -40,17 +38,13 @@ Rules:
- Detect and resolve contradictions (prefer explicit over implicit)
- Do NOT assume anything not stated or clearly implied
- Be specific and concrete, not vague`,
},
{
role: 'user',
content: `Main prompt: ${input.main_prompt}
input: `Main prompt: ${input.main_prompt}
Liked shows: ${input.liked_shows || '(none)'}
Disliked shows: ${input.disliked_shows || '(none)'}
Themes and requirements: ${input.themes || '(none)'}${feedbackSection}`,
},
],
});
const content = response.choices[0]?.message?.content ?? '{}';
return JSON.parse(content) as InterpreterOutput;
return (response.output_parsed as InterpreterOutput) ?? {
liked: [], disliked: [], themes: [], character_preferences: [], tone: [], avoid: []
};
}