()
| 77 | |
| 78 | // generate 10 subcollections per each category |
| 79 | const generateSubCollections = async () => { |
| 80 | const data = [] as any; |
| 81 | const c = await getCategories(); |
| 82 | |
| 83 | const promises = c.map(async (cat) => { |
| 84 | const { object } = await generateObject({ |
| 85 | model: client.languageModel("gpt-4o-mini", { structuredOutputs: true }), |
| 86 | schema: z.object({ |
| 87 | subcollections: z.array(z.string()), |
| 88 | }), |
| 89 | system: `You are given the name of a category for products in an art supply store. |
| 90 | Your task is to generate 10 unique subcollections for this category. Make sure the |
| 91 | subcollection names are broad. |
| 92 | |
| 93 | YOU MUST OUTPUT IN ONLY JSON. |
| 94 | |
| 95 | EXAMPLE: |
| 96 | |
| 97 | INPUT: |
| 98 | Category Name: Art Hitory |
| 99 | |
| 100 | OUTPUT: |
| 101 | { subcollections: ["Art History Books", "Art History CDs", ...] } |
| 102 | |
| 103 | Remember, ONLY RETURN THE JSON of 10 unique subcollections and nothing else. |
| 104 | |
| 105 | MAKE SURE THERE ARE 10 SUBCOLLECTIONS IN THE OUTPUT.`, |
| 106 | prompt: `Category Name: ${cat.name}`, |
| 107 | }); |
| 108 | |
| 109 | const { subcollections: sc } = object; |
| 110 | console.log(`Subcollections generated: ${sc.length}`); |
| 111 | |
| 112 | const categoriesToAdd = sc.map((subcol: string) => ({ |
| 113 | name: subcol, |
| 114 | category_slug: cat.slug, |
| 115 | })); |
| 116 | data.push(...categoriesToAdd); |
| 117 | }); |
| 118 | |
| 119 | await Promise.all(promises); |
| 120 | await db.insert(subcollections).values(data).onConflictDoNothing(); |
| 121 | }; |
| 122 | |
| 123 | // generateSubCollections(); |
| 124 |
nothing calls this directly
no test coverage detected