mirror of
https://github.com/FJurmanovic/sugarr.git
synced 2026-11-11 15:51:09 +00:00
Add MovieRecommenderTool and MovieSearchTool
This commit is contained in:
60
test/app/tools/MovieRecommenderTool.test.ts
Normal file
60
test/app/tools/MovieRecommenderTool.test.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { MovieRecommenderTool } from '../../../src/app/tools/MovieRecommenderTool';
|
||||
import type { RunContext } from '../../../src/core/llm/RunContext';
|
||||
import type { Movie } from '../../../src/app/models';
|
||||
|
||||
function makeTool() {
|
||||
return new MovieRecommenderTool(
|
||||
{} as unknown as ConstructorParameters<typeof MovieRecommenderTool>[0],
|
||||
{} as unknown as ConstructorParameters<typeof MovieRecommenderTool>[1]
|
||||
) as unknown as {
|
||||
buildVariables(input: unknown, ctx: RunContext): Record<string, unknown>;
|
||||
parseOutput(raw: string, ctx: RunContext): unknown;
|
||||
};
|
||||
}
|
||||
|
||||
const movie = (name: string, year: number): Movie => ({
|
||||
name,
|
||||
year,
|
||||
imdbId: '',
|
||||
tmdbId: '',
|
||||
genres: [],
|
||||
communityRating: 0,
|
||||
isFavorite: false,
|
||||
playCount: 0,
|
||||
});
|
||||
|
||||
describe('MovieRecommenderTool.buildVariables', () => {
|
||||
it('formats favorites/watched/library/previouslySuggested as readable lists', () => {
|
||||
const tool = makeTool();
|
||||
const variables = tool.buildVariables(
|
||||
{
|
||||
favorites: [movie('Dune', 2021)],
|
||||
watched: [],
|
||||
library: [movie('Arrival', 2016)],
|
||||
previouslySuggested: [],
|
||||
count: 5,
|
||||
},
|
||||
{} as RunContext
|
||||
);
|
||||
|
||||
expect(variables).toEqual({
|
||||
count: 5,
|
||||
favorites: '- Dune (2021)',
|
||||
watched: '(none)',
|
||||
library: '- Arrival (2016)',
|
||||
previouslySuggested: '(none)',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('MovieRecommenderTool.parseOutput', () => {
|
||||
it('validates suggestions against the movie suggestion schema', () => {
|
||||
const tool = makeTool();
|
||||
const result = tool.parseOutput(
|
||||
'[{"title":"Dune","year":2021,"reason":"sci-fi epic"}]',
|
||||
{} as RunContext
|
||||
);
|
||||
expect(result).toEqual([{ title: 'Dune', year: 2021, reason: 'sci-fi epic' }]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user