MCPcopy Create free account
hub / github.com/ethanniser/NextFaster / generateCategories

Function generateCategories

scripts/generate.ts:43–70  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

41
42// generate 20 categories per each collection
43const generateCategories = async () => {
44 const data = [] as any;
45 const c = await getCollections();
46
47 const promises = c.map(async (col) => {
48 const { object } = await generateObject({
49 model: client.languageModel("gpt-4o-mini", { structuredOutputs: true }),
50 schema: z.object({
51 categories: z.array(z.string()),
52 }),
53 system,
54 prompt: `Collection Name: ${col.name}`,
55 });
56
57 const { categories: cats } = object;
58 console.log(`Categories generated: ${cats.length}`);
59
60 const categoriesToAdd = cats.map((category: string) => ({
61 name: category,
62 collection_id: col.id,
63 slug: slugify(category, { lower: true }),
64 }));
65 data.push(...categoriesToAdd);
66 });
67
68 await Promise.all(promises);
69 await db.insert(categories).values(data).onConflictDoNothing();
70};
71
72// generateCategories();
73

Callers

nothing calls this directly

Calls 1

getCollectionsFunction · 0.85

Tested by

no test coverage detected