adding movies & web search tool
All checks were successful
Recommender Build and Deploy (internal) / Build Recommender Image (push) Successful in 4m0s
Recommender Build and Deploy (internal) / Deploy Recommender (internal) (push) Successful in 12s

This commit is contained in:
2026-03-26 20:35:22 -03:00
parent 6fdfc3797a
commit 1437092a42
25 changed files with 450 additions and 135 deletions

View File

@@ -1,5 +1,5 @@
import { openai } from '../agent.js';
import type { InterpreterOutput, RetrievalOutput, RankingOutput } from '../types/agents.js';
import type { InterpreterOutput, RetrievalOutput, RankingOutput, MediaType } from '../types/agents.js';
import { z } from 'zod';
import { zodTextFormat } from 'openai/helpers/zod';
@@ -13,7 +13,10 @@ const RankingSchema = z.object({
export async function runRanking(
interpreter: InterpreterOutput,
retrieval: RetrievalOutput,
mediaType: MediaType = 'tv_show',
): Promise<RankingOutput> {
const mediaLabel = mediaType === 'movie' ? 'movie' : 'TV show';
// Phase 1: Pre-filter — remove avoidance violations
const avoidList = interpreter.avoid.map((a) => a.toLowerCase());
const filtered = retrieval.candidates.filter((c) => {
@@ -43,7 +46,7 @@ export async function runRanking(
temperature: 0.2,
service_tier: 'flex',
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.
instructions: `You are a ${mediaLabel} ranking critic. Assign each ${mediaLabel} 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
@@ -51,15 +54,15 @@ Buckets:
- "questionable": Partial alignment, some aspects don't match
- "will_not_like": Likely mismatch, conflicts with preferences or avoidance criteria
Every show in the input must appear in exactly one bucket. Use the title exactly as given.`,
Every ${mediaLabel} in the input must appear in exactly one bucket. Use the title exactly as given.`,
input: `User preferences:
Liked shows: ${JSON.stringify(interpreter.liked)}
Liked ${mediaLabel}s: ${JSON.stringify(interpreter.liked)}
Themes: ${JSON.stringify(interpreter.themes)}
Character preferences: ${JSON.stringify(interpreter.character_preferences)}
Tone: ${JSON.stringify(interpreter.tone)}
Avoid: ${JSON.stringify(interpreter.avoid)}
Rank these shows:
Rank these ${mediaLabel}s:
${chunkTitles}`,
});