Update features and dependencies

This commit is contained in:
Arnaud
2026-07-01 11:10:37 +02:00
parent 9d9dfb46c6
commit 8b57a3fd87
107 changed files with 14654 additions and 458 deletions
+13 -5
View File
@@ -11,7 +11,7 @@ const MealPlanSchema = z.object({
description: z.string().max(300),
ingredients: z.array(z.object({
rawName: z.string(),
quantity: z.string().optional(),
quantity: z.number().optional(),
unit: z.string().optional(),
})).max(20),
steps: z.array(z.object({
@@ -36,8 +36,9 @@ export async function generateMealPlan(
pantryItems?: string[];
days?: Array<"mon" | "tue" | "wed" | "thu" | "fri" | "sat" | "sun">;
pantryMode?: boolean;
difficulty?: "easy" | "medium" | "hard";
},
config?: AiConfig,
config?: AiConfig & { userContext?: string },
locale?: string
): Promise<GeneratedMealPlan> {
const model = resolveModel(config);
@@ -45,28 +46,35 @@ export async function generateMealPlan(
const servings = options.servings ?? 2;
const days = options.days ?? ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
const pantryMode = options.pantryMode ?? false;
const difficulty = options.difficulty;
const dietaryClause = options.dietaryPrefs?.trim()
? `Dietary requirements: ${options.dietaryPrefs.trim()}.`
: "";
const difficultyClause = difficulty
? `All recipes must be ${difficulty} difficulty: ${{ easy: "simple techniques, few steps, everyday ingredients", medium: "moderate skill, standard techniques", hard: "advanced techniques, multiple components" }[difficulty]}.`
: "";
const pantryClause =
options.pantryItems && options.pantryItems.length > 0
? `Available pantry ingredients to use: ${options.pantryItems.slice(0, 20).join(", ")}.`
: "";
const systemPrompt = pantryMode
? `You are a professional nutritionist and chef. Generate a meal plan that maximizes use of the provided pantry items. Prefer meals using multiple pantry ingredients. Minimize additional shopping required. Vary cuisines and cooking methods where possible. Make meals achievable for home cooks. Respond in ${lang}.`
: `You are a professional nutritionist and chef. Generate balanced, practical, and delicious weekly meal plans. Vary cuisines and cooking methods throughout the week. Make meals achievable for home cooks. Respond in ${lang}.`;
? `You are a professional nutritionist and chef. Generate a meal plan that maximizes use of the provided pantry items. Prefer meals using multiple pantry ingredients. Minimize additional shopping required. Vary cuisines and cooking methods where possible. Make meals achievable for home cooks. For ingredients: quantity must be a number only (e.g. 0.25, 1.5, 2), unit is a separate string (e.g. 'cup', 'tbsp', 'g', 'ml'). Never combine quantity and unit. Respond in ${lang}.`
: `You are a professional nutritionist and chef. Generate balanced, practical, and delicious weekly meal plans. Vary cuisines and cooking methods throughout the week. Make meals achievable for home cooks. For ingredients: quantity must be a number only (e.g. 0.25, 1.5, 2), unit is a separate string (e.g. 'cup', 'tbsp', 'g', 'ml'). Never combine quantity and unit. Respond in ${lang}.`;
const systemPromptWithContext = systemPrompt + (config?.userContext ? `\n\nUser preferences and context:\n${config.userContext}` : "");
const { object } = await generateObject({
model,
schema: MealPlanSchema,
system: systemPrompt,
system: systemPromptWithContext,
prompt: [
`Generate a meal plan for ${days.length} day(s): ${days.join(", ")}.`,
`Include breakfast, lunch, and dinner for each day.`,
`Plan for ${servings} servings per meal.`,
dietaryClause,
difficultyClause,
pantryClause,
pantryMode
? "Prioritize using the listed pantry ingredients across as many meals as possible. Minimize ingredients that need to be purchased."