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,14 @@
import { openai } from '../agent.js';
import type { InterpreterOutput, RetrievalOutput, RankingOutput } from '../types/agents.js';
import { z } from 'zod';
import { zodTextFormat } from 'openai/helpers/zod';
const RankingSchema = z.object({
definitely_like: z.array(z.string()),
might_like: z.array(z.string()),
questionable: z.array(z.string()),
will_not_like: z.array(z.string())
});
export async function runRanking(
interpreter: InterpreterOutput,
@@ -29,15 +38,12 @@ export async function runRanking(
for (const chunk of chunks) {
const chunkTitles = chunk.map((c) => `- ${c.title}: ${c.reason}`).join('\n');
const response = await openai.chat.completions.create({
const response = await openai.responses.parse({
model: 'gpt-5.4',
temperature: 0.2,
service_tier: 'flex',
response_format: { type: 'json_object' },
messages: [
{
role: 'system',
content: `You are a TV show ranking critic. Assign each show to exactly one of four confidence buckets based on how well it matches the user's preferences.
text: { format: zodTextFormat(RankingSchema, "ranking") },
instructions: `You are a TV show ranking critic. Assign each show to exactly one of four confidence buckets based on how well it matches the user's preferences.
Buckets:
- "definitely_like": Near-perfect match to all preferences
@@ -45,19 +51,8 @@ Buckets:
- "questionable": Partial alignment, some aspects don't match
- "will_not_like": Likely mismatch, conflicts with preferences or avoidance criteria
Your output MUST be valid JSON:
{
"definitely_like": string[],
"might_like": string[],
"questionable": string[],
"will_not_like": string[]
}
Every show in the input must appear in exactly one bucket. Use the title exactly as given.`,
},
{
role: 'user',
content: `User preferences:
input: `User preferences:
Liked shows: ${JSON.stringify(interpreter.liked)}
Themes: ${JSON.stringify(interpreter.themes)}
Character preferences: ${JSON.stringify(interpreter.character_preferences)}
@@ -66,12 +61,9 @@ Avoid: ${JSON.stringify(interpreter.avoid)}
Rank these shows:
${chunkTitles}`,
},
],
});
const content = response.choices[0]?.message?.content ?? '{}';
const chunkResult = JSON.parse(content) as Partial<RankingOutput>;
const chunkResult = (response.output_parsed as Partial<RankingOutput>) ?? {};
allBuckets.definitely_like.push(...(chunkResult.definitely_like ?? []));
allBuckets.might_like.push(...(chunkResult.might_like ?? []));