simplificando app
This commit is contained in:
+1
-57
@@ -2,12 +2,8 @@ import type { CardType } from "./cards";
|
||||
import { getCachedCard, setCachedCard } from "./cache";
|
||||
import { generateStructuredResponse } from "./llm";
|
||||
import {
|
||||
historicalAccuracySchema,
|
||||
internationalRatingsSchema,
|
||||
productionFactsSchema,
|
||||
ratingExplainedSchema,
|
||||
sensitivityGuideSchema,
|
||||
skipGuideSchema,
|
||||
} from "./schemas";
|
||||
import { formatMovieContext, getMovieDetails } from "./tmdb";
|
||||
|
||||
@@ -29,66 +25,14 @@ You MUST return ONLY valid JSON matching this exact structure (no extra keys, no
|
||||
}
|
||||
Focus on specific scenes or content patterns that drove the rating. Be precise with the allowed category and intensity values.`,
|
||||
|
||||
skip_guide: `Create a skip guide for families who want to watch this film with a younger audience.
|
||||
You MUST return ONLY valid JSON matching this exact structure:
|
||||
{
|
||||
"originalRating": string,
|
||||
"suggestedAudienceAge": number (integer 0-21),
|
||||
"totalSkippedMinutes": number (integer),
|
||||
"segments": array of {
|
||||
"start": string (e.g. "0:05" or "12m"),
|
||||
"end": string,
|
||||
"reason": string,
|
||||
"intensity": one of exactly ["mild", "moderate", "strong"],
|
||||
"plotImpact": one of exactly ["none", "minor", "significant"],
|
||||
"skipRecommendation": one of exactly ["recommended", "optional", "do_not_skip"],
|
||||
"resumeHint": string
|
||||
},
|
||||
"disclaimer": string
|
||||
}
|
||||
Only include genuinely skippable segments. Mark plot-critical scenes as skipRecommendation "do_not_skip".
|
||||
Timestamps should be approximate for the standard theatrical cut. Use only the exact enum strings listed.`,
|
||||
|
||||
sensitivity_guide: `Create a sensitivity guide grouping potentially upsetting content by theme.
|
||||
You MUST return ONLY valid JSON:
|
||||
{
|
||||
"summary": string,
|
||||
"themes": array of {
|
||||
"theme": string,
|
||||
"severity": one of exactly ["mild", "moderate", "strong"],
|
||||
"description": string,
|
||||
"approximateTiming": string (optional)
|
||||
}
|
||||
}
|
||||
Cover violence, sexuality, substances, self-harm, abuse, animal harm, discrimination, and other difficult themes where relevant. Use only the exact "severity" values.`,
|
||||
|
||||
international_ratings: `Summarize how this film is rated across countries using the certification data provided.
|
||||
Return JSON with: ratings (array of {country, countryCode, rating, descriptors?}), discrepancyNote, strictestCountry (optional), mostLenientCountry (optional).
|
||||
Include at least US, GB, ES, DE, FR when data exists. Explain notable differences.`,
|
||||
|
||||
production_facts: `Curate interesting behind-the-scenes production facts for cinephiles.
|
||||
Return JSON with: facts (array of at least 5 {category, fact}), budget (optional string), boxOffice (optional string), filmingLocations (optional array of strings).
|
||||
Prefer specific, verifiable-sounding details; note uncertainty in the fact text when needed.`,
|
||||
|
||||
historical_accuracy: `Evaluate historical accuracy for this biographical or historical film.
|
||||
You MUST return ONLY valid JSON:
|
||||
{
|
||||
"accuracyScore": number (0-100),
|
||||
"summary": string,
|
||||
"accurateElements": string[],
|
||||
"inventions": array of { "claim": string, "reality": string },
|
||||
"confidence": one of exactly ["high", "medium", "low"]
|
||||
}
|
||||
If the film is not historical/biographical, still assess any real-world basis it claims. Use only the exact confidence value.`,
|
||||
};
|
||||
|
||||
const SCHEMAS = {
|
||||
rating_explained: ratingExplainedSchema,
|
||||
skip_guide: skipGuideSchema,
|
||||
sensitivity_guide: sensitivityGuideSchema,
|
||||
international_ratings: internationalRatingsSchema,
|
||||
production_facts: productionFactsSchema,
|
||||
historical_accuracy: historicalAccuracySchema,
|
||||
} as const;
|
||||
|
||||
export async function generateCard(movieId: number, cardType: CardType) {
|
||||
@@ -113,4 +57,4 @@ ${context}`;
|
||||
await setCachedCard(movieId, cardType, data);
|
||||
|
||||
return { data, cached: false };
|
||||
}
|
||||
}
|
||||
|
||||
+1
-33
@@ -1,10 +1,6 @@
|
||||
export const CARD_TYPES = [
|
||||
"rating_explained",
|
||||
"skip_guide",
|
||||
"sensitivity_guide",
|
||||
"international_ratings",
|
||||
"production_facts",
|
||||
"historical_accuracy",
|
||||
] as const;
|
||||
|
||||
export type CardType = (typeof CARD_TYPES)[number];
|
||||
@@ -20,40 +16,12 @@ export const CARD_META: Record<CardType, CardMeta> = {
|
||||
title: "Rating Explained",
|
||||
subtitle: "Why this film has its age rating",
|
||||
},
|
||||
skip_guide: {
|
||||
title: "Skip Guide",
|
||||
subtitle: "Scenes you can skip for a younger audience",
|
||||
badge: "Families",
|
||||
},
|
||||
sensitivity_guide: {
|
||||
title: "Sensitivity Guide",
|
||||
subtitle: "Content warnings by theme",
|
||||
},
|
||||
international_ratings: {
|
||||
title: "International Ratings",
|
||||
subtitle: "How ratings differ by country",
|
||||
},
|
||||
production_facts: {
|
||||
title: "Production Facts",
|
||||
subtitle: "Behind-the-scenes facts",
|
||||
},
|
||||
historical_accuracy: {
|
||||
title: "Historical Accuracy",
|
||||
subtitle: "Fact vs fiction breakdown",
|
||||
},
|
||||
};
|
||||
|
||||
const HISTORICAL_GENRES = new Set([
|
||||
"history",
|
||||
"war",
|
||||
"biography",
|
||||
"documentary",
|
||||
]);
|
||||
|
||||
export function shouldShowHistoricalAccuracy(genres: string[]): boolean {
|
||||
return genres.some((genre) => HISTORICAL_GENRES.has(genre.toLowerCase()));
|
||||
}
|
||||
|
||||
export function isCardType(value: string): value is CardType {
|
||||
return CARD_TYPES.includes(value as CardType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,36 +26,6 @@ export const ratingExplainedSchema = z.object({
|
||||
borderlineNote: z.string().optional(),
|
||||
});
|
||||
|
||||
export const skipGuideSchema = z.object({
|
||||
originalRating: z.string(),
|
||||
suggestedAudienceAge: z.number().int().min(0).max(21),
|
||||
totalSkippedMinutes: z.number().int().min(0),
|
||||
segments: z.array(
|
||||
z.object({
|
||||
start: z.string(),
|
||||
end: z.string(),
|
||||
reason: z.string(),
|
||||
intensity,
|
||||
plotImpact: z.enum(["none", "minor", "significant"]),
|
||||
skipRecommendation: z.enum(["recommended", "optional", "do_not_skip"]),
|
||||
resumeHint: z.string(),
|
||||
}),
|
||||
),
|
||||
disclaimer: z.string(),
|
||||
});
|
||||
|
||||
export const sensitivityGuideSchema = z.object({
|
||||
summary: z.string(),
|
||||
themes: z.array(
|
||||
z.object({
|
||||
theme: z.string(),
|
||||
severity: intensity,
|
||||
description: z.string(),
|
||||
approximateTiming: z.string().optional(),
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
export const internationalRatingsSchema = z.object({
|
||||
ratings: z.array(
|
||||
z.object({
|
||||
@@ -70,34 +40,5 @@ export const internationalRatingsSchema = z.object({
|
||||
mostLenientCountry: z.string().optional(),
|
||||
});
|
||||
|
||||
export const productionFactsSchema = z.object({
|
||||
facts: z.array(
|
||||
z.object({
|
||||
category: z.string(),
|
||||
fact: z.string(),
|
||||
}),
|
||||
),
|
||||
budget: z.string().optional(),
|
||||
boxOffice: z.string().optional(),
|
||||
filmingLocations: z.array(z.string()).optional(),
|
||||
});
|
||||
|
||||
export const historicalAccuracySchema = z.object({
|
||||
accuracyScore: z.number().min(0).max(100),
|
||||
summary: z.string(),
|
||||
accurateElements: z.array(z.string()),
|
||||
inventions: z.array(
|
||||
z.object({
|
||||
claim: z.string(),
|
||||
reality: z.string(),
|
||||
}),
|
||||
),
|
||||
confidence,
|
||||
});
|
||||
|
||||
export type RatingExplained = z.infer<typeof ratingExplainedSchema>;
|
||||
export type SkipGuide = z.infer<typeof skipGuideSchema>;
|
||||
export type SensitivityGuide = z.infer<typeof sensitivityGuideSchema>;
|
||||
export type InternationalRatings = z.infer<typeof internationalRatingsSchema>;
|
||||
export type ProductionFacts = z.infer<typeof productionFactsSchema>;
|
||||
export type HistoricalAccuracy = z.infer<typeof historicalAccuracySchema>;
|
||||
+1
-17
@@ -36,10 +36,6 @@ export interface TmdbMovieDetails {
|
||||
keywords?: {
|
||||
keywords: Array<{ id: number; name: string }>;
|
||||
};
|
||||
credits?: {
|
||||
cast: Array<{ name: string; character: string }>;
|
||||
crew: Array<{ name: string; job: string; department: string }>;
|
||||
};
|
||||
}
|
||||
|
||||
function getApiKey(): string {
|
||||
@@ -85,7 +81,7 @@ export async function searchMovies(query: string): Promise<TmdbSearchResult[]> {
|
||||
|
||||
export async function getMovieDetails(movieId: number): Promise<TmdbMovieDetails> {
|
||||
return tmdbFetch<TmdbMovieDetails>(`/movie/${movieId}`, {
|
||||
append_to_response: "release_dates,credits,keywords",
|
||||
append_to_response: "release_dates,keywords",
|
||||
});
|
||||
}
|
||||
|
||||
@@ -115,14 +111,6 @@ export function formatMovieContext(movie: TmdbMovieDetails): string {
|
||||
const genres = movie.genres.map((g) => g.name).join(", ");
|
||||
const keywords = movie.keywords?.keywords.map((k) => k.name).join(", ") ?? "";
|
||||
const certification = getUsCertification(movie);
|
||||
const directors = movie.credits?.crew
|
||||
.filter((c) => c.job === "Director")
|
||||
.map((c) => c.name)
|
||||
.join(", ");
|
||||
const leadCast = movie.credits?.cast
|
||||
.slice(0, 5)
|
||||
.map((c) => `${c.name} as ${c.character}`)
|
||||
.join("; ");
|
||||
|
||||
const releaseDates = movie.release_dates?.results
|
||||
.map((country) => {
|
||||
@@ -146,10 +134,6 @@ export function formatMovieContext(movie: TmdbMovieDetails): string {
|
||||
`Overview: ${movie.overview}`,
|
||||
certification ? `US Certification: ${certification}` : null,
|
||||
keywords ? `Keywords: ${keywords}` : null,
|
||||
directors ? `Director(s): ${directors}` : null,
|
||||
leadCast ? `Lead cast: ${leadCast}` : null,
|
||||
movie.budget ? `Budget: $${movie.budget.toLocaleString("en-US")}` : null,
|
||||
movie.revenue ? `Revenue: $${movie.revenue.toLocaleString("en-US")}` : null,
|
||||
releaseDates ? `International certifications:\n${releaseDates}` : null,
|
||||
]
|
||||
.filter(Boolean)
|
||||
|
||||
Reference in New Issue
Block a user