This commit is contained in:
Your Name
2026-06-03 11:39:36 +08:00
parent a3bae1555a
commit ec4e0b9f29
22 changed files with 1353 additions and 646 deletions
+37 -4
View File
@@ -499,8 +499,10 @@ class DailyDietAiLogic
3. 严禁:白馒头、油条、粘豆包、糯米饭、西瓜、含糖饮料、白稀饭(杂面窝头、玉米碴粥除外)。
4. 低 GI 优先;农村家常;禁止轻食/沙拉/藜麦等词。
5. lunch 字段写法:蛋白菜放前面,淀粉(如有)放最后且注明「小半碗/一个」。
6. 只输出 JSON
{"breakfast":"...","lunch":"...","dinner":"...","tips":"...","avoid":["...","..."]}
6. 早餐必须包含「驼奶粉」(温水冲服,适量),可与粥、蛋、菜并列写。
7. drinks 单独写全天喝什么:温开水为主;可写驼奶粉冲饮时间;严禁含糖饮料、果汁、酒。
8. 只输出 JSON
{"breakfast":"...","drinks":"...","lunch":"...","dinner":"...","tips":"...","avoid":["...","..."]}
SYS;
$user = sprintf(
@@ -544,9 +546,11 @@ SYS;
2. 淀粉(粥/饭/面/饼/窝头/薯/南瓜)每餐最多 1 种,早中晚互不相同。
3. 严禁白馒头、油条、粘豆包、糯米饭、西瓜、含糖饮料。
4. 农村家常饭,禁止轻食/沙拉/藜麦。
5. 早餐必须含驼奶粉(温水冲服);喝的单独一行。
严格按下面 5 行格式输出,不要 JSON、不要 markdown、不要多余解释:
早餐:(具体食物)
严格按下面 6 行格式输出,不要 JSON、不要 markdown、不要多余解释:
早餐:(具体食物,须含驼奶粉
喝的:(温开水、驼奶粉冲饮安排等,忌甜饮)
午餐:(具体食物,蛋白放前)
晚餐:(具体食物)
提示:(一句土话提醒)
@@ -593,6 +597,7 @@ SYS;
$map = [
'breakfast' => null,
'drinks' => null,
'lunch' => null,
'dinner' => null,
'tips' => null,
@@ -602,6 +607,9 @@ SYS;
if (preg_match('/早餐[:]\s*(.+)$/mu', $text, $m)) {
$map['breakfast'] = trim(preg_split('/\R/u', $m[1])[0] ?? $m[1]);
}
if (preg_match('/喝的[:]\s*(.+)$/mu', $text, $m)) {
$map['drinks'] = trim(preg_split('/\R/u', $m[1])[0] ?? $m[1]);
}
if (preg_match('/午餐[:]\s*(.+)$/mu', $text, $m)) {
$map['lunch'] = trim(preg_split('/\R/u', $m[1])[0] ?? $m[1]);
}
@@ -623,6 +631,7 @@ SYS;
$out = [
'breakfast' => (string) $map['breakfast'],
'drinks' => (string) ($map['drinks'] ?? ''),
'lunch' => (string) ($map['lunch'] ?? ''),
'dinner' => (string) ($map['dinner'] ?? ''),
'tips' => (string) ($map['tips'] ?? ''),
@@ -632,6 +641,29 @@ SYS;
return $out;
}
/**
* 产品要求:早餐含驼奶粉,并单独给出「喝的」
*
* @param array<string, mixed> $plan
* @return array<string, mixed>
*/
private static function applyDietProductDefaults(array $plan): array
{
$breakfast = trim((string) ($plan['breakfast'] ?? ''));
if ($breakfast !== '' && mb_strpos($breakfast, '驼奶粉') === false && mb_strpos($breakfast, '驼奶') === false) {
$plan['breakfast'] = '驼奶粉(温水冲服)、' . $breakfast;
}
$drinks = trim((string) ($plan['drinks'] ?? ''));
if ($drinks === '') {
$plan['drinks'] = '白天多喝温开水;早餐按量冲驼奶粉,别喝甜饮料、果汁。';
} elseif (mb_strpos($drinks, '驼奶') === false) {
$plan['drinks'] = $drinks . ';早餐已安排驼奶粉';
}
return $plan;
}
/**
* 规范化 AI 三餐方案;校验未过也保留 AI 文案(避免流式展示后被规则模板覆盖)
*
@@ -640,6 +672,7 @@ SYS;
*/
private static function finalizeAiRecommendPlan(array $parsed): array
{
$parsed = self::applyDietProductDefaults($parsed);
$checked = DietMealValidator::validateAndNormalize($parsed);
$data = $checked['plan'];
$data['source'] = 'ai';