language->value === 'ms' ? 'Bahasa Malaysia' : 'English'; $products = self::productList($store); return <<name} Category: {$store->category->label()} Write all store text in: {$language} Brand description from the merchant: """ {$store->description} """ {$products} TEXT; } /** * The store's real products, so the AI can link a "featured_product" section to one. * Empty when the store has no active products yet. */ public static function productList(Store $store): string { $products = $store->products()->active()->orderBy('name')->limit(40)->get(['slug', 'name', 'price']); if ($products->isEmpty()) { return ''; } $lines = $products ->map(fn (Product $product) => '- '.$product->slug.': '.$product->name.' (RM '.number_format($product->price / 100, 2).')') ->implode("\n"); return << $plan */ public static function editPrompt(array $plan, string $instruction, string $products = ''): string { $json = json_encode($plan, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); return << $errors */ public static function repairPrompt(string $originalPrompt, string $rejectedAnswer, array $errors): string { $list = implode("\n", array_map(fn (string $error) => '- '.$error, array_slice($errors, 0, 25))); return << $variants) { $rules = []; foreach (PlanSchema::contentRules($type) as $field => $fieldRules) { $rules[$field] = implode('|', array_map( fn (string $rule) => str_starts_with($rule, 'regex:') ? 'format' : $rule, $fieldRules, )); } $sections .= "## $type\nvariants: ".implode(', ', $variants)."\ncontent: ".json_encode($rules, $flags)."\n\n"; } $example = json_encode(SamplePlan::forName('Example Store'), $flags); return <<