mirror of
https://github.com/FJurmanovic/sugarr.git
synced 2026-11-11 07:41:08 +00:00
Add MovieRecommenderTool and MovieSearchTool
This commit is contained in:
38
src/app/tools/MovieRecommenderTool.ts
Normal file
38
src/app/tools/MovieRecommenderTool.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { z } from 'zod';
|
||||
import { SchemaLlmTool } from '../../core/llm/SchemaLlmTool';
|
||||
import type { RunContext } from '../../core/llm/RunContext';
|
||||
import type { Movie, MovieSuggestion } from '../models';
|
||||
|
||||
export interface RecommendInput {
|
||||
favorites: Movie[];
|
||||
watched: Movie[];
|
||||
library: Movie[];
|
||||
previouslySuggested: Movie[];
|
||||
count: number;
|
||||
}
|
||||
|
||||
const movieSuggestionSchema = z.object({
|
||||
title: z.string(),
|
||||
year: z.number(),
|
||||
reason: z.string(),
|
||||
});
|
||||
|
||||
export class MovieRecommenderTool extends SchemaLlmTool<RecommendInput, MovieSuggestion[]> {
|
||||
protected readonly promptName = 'movie-recommender';
|
||||
protected readonly outputSchema = z.array(movieSuggestionSchema);
|
||||
|
||||
protected buildVariables(input: RecommendInput, _ctx: RunContext): Record<string, unknown> {
|
||||
return {
|
||||
count: input.count,
|
||||
favorites: formatMovieList(input.favorites),
|
||||
watched: formatMovieList(input.watched),
|
||||
library: formatMovieList(input.library),
|
||||
previouslySuggested: formatMovieList(input.previouslySuggested),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function formatMovieList(movies: Movie[]): string {
|
||||
if (movies.length === 0) return '(none)';
|
||||
return movies.map((m) => `- ${m.name} (${m.year})`).join('\n');
|
||||
}
|
||||
24
src/app/tools/MovieSearchTool.ts
Normal file
24
src/app/tools/MovieSearchTool.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { z } from 'zod';
|
||||
import { SchemaLlmTool } from '../../core/llm/SchemaLlmTool';
|
||||
import type { RunContext } from '../../core/llm/RunContext';
|
||||
import type { MovieSuggestion } from '../models';
|
||||
|
||||
export interface SearchInput {
|
||||
query: string;
|
||||
count: number;
|
||||
}
|
||||
|
||||
const movieSuggestionSchema = z.object({
|
||||
title: z.string(),
|
||||
year: z.number(),
|
||||
reason: z.string(),
|
||||
});
|
||||
|
||||
export class MovieSearchTool extends SchemaLlmTool<SearchInput, MovieSuggestion[]> {
|
||||
protected readonly promptName = 'movie-search';
|
||||
protected readonly outputSchema = z.array(movieSuggestionSchema);
|
||||
|
||||
protected buildVariables(input: SearchInput, _ctx: RunContext): Record<string, unknown> {
|
||||
return { query: input.query, count: input.count };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user