feat: ai prompt change
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user