feat: ai prompt change

This commit is contained in:
2026-05-21 12:54:56 +02:00
parent 6ac36e3de4
commit 2d6e4db390
2 changed files with 71 additions and 5 deletions
+33 -3
View File
@@ -9,6 +9,7 @@ use App\Enums\MealPostVisibility;
use App\Models\MealPosts;
use App\Models\User;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
@@ -86,19 +87,48 @@ class AiMealPostGenerator
private function mealPrompt(): string
{
$season = now()->locale('fr')->translatedFormat('F');
$recentMainIngredients = $this->recentMainIngredientsToAvoid();
$avoidRecentIngredients = $recentMainIngredients === []
? '- Aucun ingredient recent a eviter pour cette generation.'
: '- Evite les ingredients principaux deja utilises dans les 10 derniers repas: '.implode(', ', $recentMainIngredients).'.';
return <<<PROMPT
Genere un plat aleatoire pour le mois de {$season}.
Genere un plat completement aleatoire, sans tenir compte du mois actuel, de la saison ou des produits de saison.
Contraintes:
- Le plat doit etre realiste, appetissant et suffisamment different des classiques trop evidents.
- Choisis librement la cuisine, le pays, le moment de la journee et les ingredients.
- Retourne une seule portion avec calories, macros et ingredients coherents.
- Evite les aliments impossibles a representer clairement en photo.
- Auncun texte sur l'image
{$avoidRecentIngredients}
- Aucun texte sur l'image.
PROMPT;
}
/**
* @return string[]
*/
private function recentMainIngredientsToAvoid(): array
{
return MealPosts::query()
->with([
'ingredients' => function (HasMany $query): void {
$query->where('position', '<=', 3);
},
])
->latest('eaten_at')
->limit(10)
->get()
->flatMap(fn (MealPosts $mealPost): array => $mealPost->ingredients
->pluck('ingredient')
->all())
->map(fn (mixed $ingredient): string => $this->cleanString($ingredient, 255))
->filter()
->unique(fn (string $ingredient): string => Str::lower($ingredient))
->values()
->all();
}
private function imagePrompt(array $draft): string
{
$prompt = $this->cleanString($draft['image_prompt'] ?? '', 1500);