diff --git a/fresh.gen.ts b/fresh.gen.ts index 7652e7b..1a33313 100644 --- a/fresh.gen.ts +++ b/fresh.gen.ts @@ -25,22 +25,23 @@ import * as $19 from "./routes/api/query/index.ts"; import * as $20 from "./routes/api/query/sync.ts"; import * as $21 from "./routes/api/recipes/[name].ts"; import * as $22 from "./routes/api/recipes/index.ts"; -import * as $23 from "./routes/api/resources.ts"; -import * as $24 from "./routes/api/series/[name].ts"; -import * as $25 from "./routes/api/series/enhance/[name].ts"; -import * as $26 from "./routes/api/series/index.ts"; -import * as $27 from "./routes/api/tmdb/[id].ts"; -import * as $28 from "./routes/api/tmdb/credits/[id].ts"; -import * as $29 from "./routes/api/tmdb/query.ts"; -import * as $30 from "./routes/articles/[name].tsx"; -import * as $31 from "./routes/articles/index.tsx"; -import * as $32 from "./routes/index.tsx"; -import * as $33 from "./routes/movies/[name].tsx"; -import * as $34 from "./routes/movies/index.tsx"; -import * as $35 from "./routes/recipes/[name].tsx"; -import * as $36 from "./routes/recipes/index.tsx"; -import * as $37 from "./routes/series/[name].tsx"; -import * as $38 from "./routes/series/index.tsx"; +import * as $23 from "./routes/api/recommendation/index.ts"; +import * as $24 from "./routes/api/resources.ts"; +import * as $25 from "./routes/api/series/[name].ts"; +import * as $26 from "./routes/api/series/enhance/[name].ts"; +import * as $27 from "./routes/api/series/index.ts"; +import * as $28 from "./routes/api/tmdb/[id].ts"; +import * as $29 from "./routes/api/tmdb/credits/[id].ts"; +import * as $30 from "./routes/api/tmdb/query.ts"; +import * as $31 from "./routes/articles/[name].tsx"; +import * as $32 from "./routes/articles/index.tsx"; +import * as $33 from "./routes/index.tsx"; +import * as $34 from "./routes/movies/[name].tsx"; +import * as $35 from "./routes/movies/index.tsx"; +import * as $36 from "./routes/recipes/[name].tsx"; +import * as $37 from "./routes/recipes/index.tsx"; +import * as $38 from "./routes/series/[name].tsx"; +import * as $39 from "./routes/series/index.tsx"; import * as $$0 from "./islands/Counter.tsx"; import * as $$1 from "./islands/IngredientsList.tsx"; import * as $$2 from "./islands/KMenu.tsx"; @@ -78,22 +79,23 @@ const manifest = { "./routes/api/query/sync.ts": $20, "./routes/api/recipes/[name].ts": $21, "./routes/api/recipes/index.ts": $22, - "./routes/api/resources.ts": $23, - "./routes/api/series/[name].ts": $24, - "./routes/api/series/enhance/[name].ts": $25, - "./routes/api/series/index.ts": $26, - "./routes/api/tmdb/[id].ts": $27, - "./routes/api/tmdb/credits/[id].ts": $28, - "./routes/api/tmdb/query.ts": $29, - "./routes/articles/[name].tsx": $30, - "./routes/articles/index.tsx": $31, - "./routes/index.tsx": $32, - "./routes/movies/[name].tsx": $33, - "./routes/movies/index.tsx": $34, - "./routes/recipes/[name].tsx": $35, - "./routes/recipes/index.tsx": $36, - "./routes/series/[name].tsx": $37, - "./routes/series/index.tsx": $38, + "./routes/api/recommendation/index.ts": $23, + "./routes/api/resources.ts": $24, + "./routes/api/series/[name].ts": $25, + "./routes/api/series/enhance/[name].ts": $26, + "./routes/api/series/index.ts": $27, + "./routes/api/tmdb/[id].ts": $28, + "./routes/api/tmdb/credits/[id].ts": $29, + "./routes/api/tmdb/query.ts": $30, + "./routes/articles/[name].tsx": $31, + "./routes/articles/index.tsx": $32, + "./routes/index.tsx": $33, + "./routes/movies/[name].tsx": $34, + "./routes/movies/index.tsx": $35, + "./routes/recipes/[name].tsx": $36, + "./routes/recipes/index.tsx": $37, + "./routes/series/[name].tsx": $38, + "./routes/series/index.tsx": $39, }, islands: { "./islands/Counter.tsx": $$0, diff --git a/lib/openai.ts b/lib/openai.ts index f037d11..35045d1 100644 --- a/lib/openai.ts +++ b/lib/openai.ts @@ -71,12 +71,13 @@ export async function createKeywords(type: string, description: string) { { "role": "system", "content": - `you create some general vibey keywords to use in a recommendation system based on a ${type} description`, + `you create some keywords to use in a recommendation system based on a ${type} description, create a range of keywords from very specific ones that describe the general vibe also include some that describe the genre`, }, { "role": "user", "content": description.slice(0, 2000) }, { "role": "user", - "content": "return a list of keywords seperated by commas", + "content": + "only return a list of around 20 keywords seperated by commas", }, ], }); diff --git a/lib/recommendation.ts b/lib/recommendation.ts index 3df2753..dd52993 100644 --- a/lib/recommendation.ts +++ b/lib/recommendation.ts @@ -51,3 +51,10 @@ export async function createRecommendationResource( cache.set(cacheId, JSON.stringify(resource)); } + +export async function getAllRecommendations() { + const keys = await cache.keys("recommendations:movie:*"); + return Promise.all(keys.map((k) => cache.get(k))).then((res) => + res.map((r) => JSON.parse(r)) + ); +} diff --git a/routes/api/movies/enhance/[name].ts b/routes/api/movies/enhance/[name].ts index d4c3c81..6117c2c 100644 --- a/routes/api/movies/enhance/[name].ts +++ b/routes/api/movies/enhance/[name].ts @@ -54,7 +54,9 @@ const POST = async ( movie.tags = [ ...new Set([ ...movie.tags.map((g) => g.toLowerCase()), - ...movieDetails.genres.map((g) => g.name?.toLowerCase()), + ...movieDetails.genres.map((g) => + g.name?.toLowerCase().replaceAll(" ", "-") + ), ].filter(isString)), ]; } diff --git a/routes/api/recommendation/index.ts b/routes/api/recommendation/index.ts new file mode 100644 index 0000000..d8e33ac --- /dev/null +++ b/routes/api/recommendation/index.ts @@ -0,0 +1,11 @@ +import { Handlers } from "$fresh/server.ts"; +import { json } from "@lib/helpers.ts"; +import { getAllRecommendations } from "@lib/recommendation.ts"; + +export const handler: Handlers = { + async GET() { + const recommendations = await getAllRecommendations(); + console.log({ recommendations }); + return json(recommendations); + }, +};