adding movies & web search tool
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { openai } from '../agent.js';
|
||||
import type { InterpreterOutput, RetrievalOutput } from '../types/agents.js';
|
||||
import type { InterpreterOutput, RetrievalOutput, MediaType } from '../types/agents.js';
|
||||
import { z } from 'zod';
|
||||
import { zodTextFormat } from 'openai/helpers/zod';
|
||||
|
||||
@@ -10,33 +10,39 @@ const RetrievalSchema = z.object({
|
||||
}))
|
||||
});
|
||||
|
||||
export async function runRetrieval(input: InterpreterOutput, brainstormCount = 100): Promise<RetrievalOutput> {
|
||||
export async function runRetrieval(
|
||||
input: InterpreterOutput,
|
||||
brainstormCount = 100,
|
||||
mediaType: MediaType = 'tv_show',
|
||||
useWebSearch = false,
|
||||
): Promise<RetrievalOutput> {
|
||||
const mediaLabel = mediaType === 'movie' ? 'movie' : 'TV show';
|
||||
const mediaLabelPlural = mediaType === 'movie' ? 'movies' : 'TV shows';
|
||||
|
||||
const response = await openai.responses.parse({
|
||||
model: 'gpt-5.4',
|
||||
temperature: 0.9,
|
||||
service_tier: 'flex',
|
||||
tools: [
|
||||
{ type: 'web_search' }
|
||||
],
|
||||
...(useWebSearch ? { tools: [{ type: 'web_search' as const }] } : {}),
|
||||
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.
|
||||
instructions: `You are a ${mediaLabel} candidate generator. Your goal is to brainstorm a LARGE, DIVERSE pool of ${brainstormCount} ${mediaLabel} candidates that match the user's structured preferences.${useWebSearch ? '\n\nUse web search to find recent and accurate titles, including newer releases.' : ''}
|
||||
|
||||
Rules:
|
||||
- Include both well-known and obscure shows
|
||||
- Include both well-known and obscure ${mediaLabelPlural}
|
||||
- Prioritize RECALL over precision — it's better to include too many than too few
|
||||
- Each "reason" should briefly explain why the show matches the preferences
|
||||
- Each "reason" should briefly explain why the ${mediaLabel} matches the preferences
|
||||
- Avoid duplicates
|
||||
- Include shows from different decades, countries, and networks
|
||||
- Include ${mediaLabelPlural} from different decades, countries${mediaType === 'tv_show' ? ', and networks' : ', and directors'}
|
||||
- Aim for ${brainstormCount} candidates minimum`,
|
||||
input: `Structured preferences:
|
||||
Liked shows: ${JSON.stringify(input.liked)}
|
||||
Disliked shows: ${JSON.stringify(input.disliked)}
|
||||
Liked ${mediaLabelPlural}: ${JSON.stringify(input.liked)}
|
||||
Disliked ${mediaLabelPlural}: ${JSON.stringify(input.disliked)}
|
||||
Themes: ${JSON.stringify(input.themes)}
|
||||
Character preferences: ${JSON.stringify(input.character_preferences)}
|
||||
Tone: ${JSON.stringify(input.tone)}
|
||||
Avoid: ${JSON.stringify(input.avoid)}
|
||||
|
||||
Generate a large, diverse pool of TV show candidates.`,
|
||||
Generate a large, diverse pool of ${mediaLabel} candidates.`,
|
||||
});
|
||||
|
||||
return (response.output_parsed as RetrievalOutput) ?? { candidates: [] };
|
||||
|
||||
Reference in New Issue
Block a user