feat: enhance creation of recommendation keywords

This commit is contained in:
max_richter 2023-09-08 14:01:35 +02:00
parent cc112b7554
commit 217dce04fb
5 changed files with 58 additions and 35 deletions

View File

@ -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,

View File

@ -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",
},
],
});

View File

@ -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))
);
}

View File

@ -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)),
];
}

View File

@ -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);
},
};