diff --git a/9103.jpg_wh860.jpg b/9103.jpg_wh860.jpg new file mode 100644 index 0000000..da102c3 Binary files /dev/null and b/9103.jpg_wh860.jpg differ diff --git a/backend/src/Health.Infrastructure/AI/ai_clients.cs b/backend/src/Health.Infrastructure/AI/ai_clients.cs index 0337c4d..5b27baa 100644 --- a/backend/src/Health.Infrastructure/AI/ai_clients.cs +++ b/backend/src/Health.Infrastructure/AI/ai_clients.cs @@ -85,12 +85,12 @@ public sealed class DeepSeekClient(HttpClient http, IConfiguration config) } /// -/// 千问 VL 视觉客户端(食物识别 + 报告解读) +/// VLM 视觉客户端——支持千问/豆包,通过 .env 切换 /// -public sealed class QwenVisionClient(HttpClient http, IConfiguration config) +public sealed class VisionClient(HttpClient http, IConfiguration config) { private readonly HttpClient _http = http; - private readonly string _model = config["QWEN_VISION_MODEL"] ?? "qwen-vl-max"; + private readonly string _model = config["VLM_MODEL"] ?? "doubao-vision-pro"; private readonly JsonSerializerOptions _jsonOptions = new() { PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower, diff --git a/backend/src/Health.Infrastructure/AI/prompt_manager.cs b/backend/src/Health.Infrastructure/AI/prompt_manager.cs index 17f0e88..fb90712 100644 --- a/backend/src/Health.Infrastructure/AI/prompt_manager.cs +++ b/backend/src/Health.Infrastructure/AI/prompt_manager.cs @@ -71,12 +71,15 @@ public sealed class PromptManager 你是一个营养分析专家,专门为心脏术后患者提供饮食指导。 规则: - 1. 收到VLM食物识别结果后,结合患者档案进行综合分析 - 2. 总热量汇总 - 3. 逐项判断"能不能吃"(基于疾病诊断/过敏/饮食限制/近期指标) - 4. 给出 1-5 星健康评分 - 5. 单项警告 + 整体饮食建议 - 6. 追问餐次归属(早餐/午餐/晚餐/加餐) + 1. 收到VLM食物识别结果后,必须先调用 check_archive 查询患者档案 + 2. 逐项判断"能不能吃": + - 过敏食物 → 严格禁止,红色警告 + - 饮食限制(如低盐/低脂/低糖)→ 黄色提醒 + - 疾病禁忌(如冠心病忌高脂、糖尿病忌高糖)→ 红色警告 + 3. 给出 1-5 星健康评分 + 4. 结合患者档案中的诊断(如冠心病PCI术后)、慢病史(高血压/高血脂等)给出个性化建议 + 5. 单项警告 + 整体饮食建议 + 替代推荐 + 6. 追问餐次归属:早餐/午餐/晚餐/加餐 """; private const string MedicationPrompt = """ diff --git a/backend/src/Health.WebApi/Endpoints/ai_chat_endpoints.cs b/backend/src/Health.WebApi/Endpoints/ai_chat_endpoints.cs index 1076960..ae42229 100644 --- a/backend/src/Health.WebApi/Endpoints/ai_chat_endpoints.cs +++ b/backend/src/Health.WebApi/Endpoints/ai_chat_endpoints.cs @@ -249,8 +249,8 @@ public static class AiChatEndpoints foreach (var file in files) { - if (file.Length > 10 * 1024 * 1024) - return Results.Ok(new { code = 40001, data = (object?)null, message = "文件大小超过 10MB 限制" }); + if (file.Length > 20 * 1024 * 1024) + return Results.Ok(new { code = 40001, data = (object?)null, message = "文件大小超过 20MB 限制" }); var ext = Path.GetExtension(file.FileName).ToLowerInvariant(); if (ext is not ".jpg" and not ".jpeg" and not ".png" and not ".heic") @@ -263,25 +263,18 @@ public static class AiChatEndpoints // 压缩图片后转 base64(VLM API 有请求体大小限制) var compressedPath = Path.Combine(uploadsDir, $"compressed_{safeName}"); - CompressImage(filePath, compressedPath, maxWidth: 860, quality: 65L); + CompressImage(filePath, compressedPath, maxWidth: 960, quality: 72L); var compressedBytes = await File.ReadAllBytesAsync(compressedPath, ct); var base64 = Convert.ToBase64String(compressedBytes); imageUrls.Add($"data:image/jpeg;base64,{base64}"); } var prompt = """ - 你是一个中餐营养分析专家。请仔细识别图片中的所有食物。 - 注意:这是中国食堂的中式菜肴,请用中文名称。 - - 返回 JSON 格式: + 识别图片中所有食物,只返回JSON,不要加任何其他文字: { - "foods": [{"name":"食物名(中文)","portion":"份量","calories":数字,"proteinGrams":数字,"carbsGrams":数字,"fatGrams":数字,"warning":null}], - "totalCalories":总热量, - "warnings":["整体建议"], - "score":1-5 + "foods": [{"name":"中文菜名","portion":"份量","calories":整数}] } - 常见中餐参考:米饭约200g/230卡,炒青菜约200g/80卡,青椒肉丝约200g/200卡,红烧肉约150g/400卡,番茄炒蛋约200g/180卡,麻婆豆腐约200g/220卡。 - 只返回JSON。 + 常见参考:米饭200g/230卡,炒青菜200g/80卡,红烧肉150g/400卡,番茄炒蛋200g/180卡,青椒肉丝200g/200卡。 """; try diff --git a/backend/src/Health.WebApi/uploads/0dbdfe79-c3b0-4a93-8534-47dbe14f3543_test_9103.jpg b/backend/src/Health.WebApi/uploads/0dbdfe79-c3b0-4a93-8534-47dbe14f3543_test_9103.jpg new file mode 100644 index 0000000..da102c3 Binary files /dev/null and b/backend/src/Health.WebApi/uploads/0dbdfe79-c3b0-4a93-8534-47dbe14f3543_test_9103.jpg differ diff --git a/backend/src/Health.WebApi/uploads/17afba67-efe1-4cfe-8b7c-aa795695aaef_test_food.jpg b/backend/src/Health.WebApi/uploads/17afba67-efe1-4cfe-8b7c-aa795695aaef_test_food.jpg new file mode 100644 index 0000000..5492407 Binary files /dev/null and b/backend/src/Health.WebApi/uploads/17afba67-efe1-4cfe-8b7c-aa795695aaef_test_food.jpg differ diff --git a/backend/src/Health.WebApi/uploads/1c648875-1276-4068-bed8-8224ab984f9f_ʳ������һ����������.png b/backend/src/Health.WebApi/uploads/1c648875-1276-4068-bed8-8224ab984f9f_ʳ������һ����������.png new file mode 100644 index 0000000..37b003f Binary files /dev/null and b/backend/src/Health.WebApi/uploads/1c648875-1276-4068-bed8-8224ab984f9f_ʳ������һ����������.png differ diff --git a/backend/src/Health.WebApi/uploads/23f701f4-e4fe-4ea0-a7c8-fe6aaa23dc22_ʳ������һ����������.png b/backend/src/Health.WebApi/uploads/23f701f4-e4fe-4ea0-a7c8-fe6aaa23dc22_ʳ������һ����������.png new file mode 100644 index 0000000..37b003f Binary files /dev/null and b/backend/src/Health.WebApi/uploads/23f701f4-e4fe-4ea0-a7c8-fe6aaa23dc22_ʳ������һ����������.png differ diff --git a/backend/src/Health.WebApi/uploads/3307eab2-01cc-47f0-bd20-bc646b394374_test_food.jpg b/backend/src/Health.WebApi/uploads/3307eab2-01cc-47f0-bd20-bc646b394374_test_food.jpg new file mode 100644 index 0000000..5492407 Binary files /dev/null and b/backend/src/Health.WebApi/uploads/3307eab2-01cc-47f0-bd20-bc646b394374_test_food.jpg differ diff --git a/backend/src/Health.WebApi/uploads/44a0ff7d-ce0c-460e-a557-74d655da1406_ft_q55.jpg b/backend/src/Health.WebApi/uploads/44a0ff7d-ce0c-460e-a557-74d655da1406_ft_q55.jpg new file mode 100644 index 0000000..261fb38 Binary files /dev/null and b/backend/src/Health.WebApi/uploads/44a0ff7d-ce0c-460e-a557-74d655da1406_ft_q55.jpg differ diff --git a/backend/src/Health.WebApi/uploads/5b23688a-2eeb-4ecf-9d51-23ccdeb612c9_ʳ������һ����������.png b/backend/src/Health.WebApi/uploads/5b23688a-2eeb-4ecf-9d51-23ccdeb612c9_ʳ������һ����������.png new file mode 100644 index 0000000..37b003f Binary files /dev/null and b/backend/src/Health.WebApi/uploads/5b23688a-2eeb-4ecf-9d51-23ccdeb612c9_ʳ������һ����������.png differ diff --git a/backend/src/Health.WebApi/uploads/77ce2c3a-ac17-417c-8639-746aa478fc55_test_9103.jpg b/backend/src/Health.WebApi/uploads/77ce2c3a-ac17-417c-8639-746aa478fc55_test_9103.jpg new file mode 100644 index 0000000..da102c3 Binary files /dev/null and b/backend/src/Health.WebApi/uploads/77ce2c3a-ac17-417c-8639-746aa478fc55_test_9103.jpg differ diff --git a/backend/src/Health.WebApi/uploads/7e00bac6-be9c-4d81-9dcd-38e9866f4343_test_food.png b/backend/src/Health.WebApi/uploads/7e00bac6-be9c-4d81-9dcd-38e9866f4343_test_food.png new file mode 100644 index 0000000..37b003f Binary files /dev/null and b/backend/src/Health.WebApi/uploads/7e00bac6-be9c-4d81-9dcd-38e9866f4343_test_food.png differ diff --git a/backend/src/Health.WebApi/uploads/7f16b7d0-e132-4f43-bfc1-60a4c1d47379_test_food_hq.jpg b/backend/src/Health.WebApi/uploads/7f16b7d0-e132-4f43-bfc1-60a4c1d47379_test_food_hq.jpg new file mode 100644 index 0000000..87118a5 Binary files /dev/null and b/backend/src/Health.WebApi/uploads/7f16b7d0-e132-4f43-bfc1-60a4c1d47379_test_food_hq.jpg differ diff --git a/backend/src/Health.WebApi/uploads/8b701209-db31-46bc-8e9e-e8c7af4cb9cf_test_food.png b/backend/src/Health.WebApi/uploads/8b701209-db31-46bc-8e9e-e8c7af4cb9cf_test_food.png new file mode 100644 index 0000000..37b003f Binary files /dev/null and b/backend/src/Health.WebApi/uploads/8b701209-db31-46bc-8e9e-e8c7af4cb9cf_test_food.png differ diff --git a/backend/src/Health.WebApi/uploads/96c66435-90d6-4aa3-b213-b8586f40a391_food_test.jpg b/backend/src/Health.WebApi/uploads/96c66435-90d6-4aa3-b213-b8586f40a391_food_test.jpg new file mode 100644 index 0000000..5c52bb3 Binary files /dev/null and b/backend/src/Health.WebApi/uploads/96c66435-90d6-4aa3-b213-b8586f40a391_food_test.jpg differ diff --git a/backend/src/Health.WebApi/uploads/9b0800a5-27d7-4ad6-a43a-6ba9bb9ac9f7_test_9103.jpg b/backend/src/Health.WebApi/uploads/9b0800a5-27d7-4ad6-a43a-6ba9bb9ac9f7_test_9103.jpg new file mode 100644 index 0000000..da102c3 Binary files /dev/null and b/backend/src/Health.WebApi/uploads/9b0800a5-27d7-4ad6-a43a-6ba9bb9ac9f7_test_9103.jpg differ diff --git a/backend/src/Health.WebApi/uploads/ad73133d-1be7-4a2a-b627-c1344f95c429_test_9103.jpg b/backend/src/Health.WebApi/uploads/ad73133d-1be7-4a2a-b627-c1344f95c429_test_9103.jpg new file mode 100644 index 0000000..da102c3 Binary files /dev/null and b/backend/src/Health.WebApi/uploads/ad73133d-1be7-4a2a-b627-c1344f95c429_test_9103.jpg differ diff --git a/backend/src/Health.WebApi/uploads/c0630e4d-a076-4286-a595-d3ef58f13b3d_test_9103.jpg b/backend/src/Health.WebApi/uploads/c0630e4d-a076-4286-a595-d3ef58f13b3d_test_9103.jpg new file mode 100644 index 0000000..da102c3 Binary files /dev/null and b/backend/src/Health.WebApi/uploads/c0630e4d-a076-4286-a595-d3ef58f13b3d_test_9103.jpg differ diff --git a/backend/src/Health.WebApi/uploads/c145365a-5533-47f3-8a73-3e653b15461b_test_food_mid.jpg b/backend/src/Health.WebApi/uploads/c145365a-5533-47f3-8a73-3e653b15461b_test_food_mid.jpg new file mode 100644 index 0000000..3f8d1ee Binary files /dev/null and b/backend/src/Health.WebApi/uploads/c145365a-5533-47f3-8a73-3e653b15461b_test_food_mid.jpg differ diff --git a/backend/src/Health.WebApi/uploads/compressed_0dbdfe79-c3b0-4a93-8534-47dbe14f3543_test_9103.jpg b/backend/src/Health.WebApi/uploads/compressed_0dbdfe79-c3b0-4a93-8534-47dbe14f3543_test_9103.jpg new file mode 100644 index 0000000..e684337 Binary files /dev/null and b/backend/src/Health.WebApi/uploads/compressed_0dbdfe79-c3b0-4a93-8534-47dbe14f3543_test_9103.jpg differ diff --git a/backend/src/Health.WebApi/uploads/compressed_1c648875-1276-4068-bed8-8224ab984f9f_ʳ������һ����������.png b/backend/src/Health.WebApi/uploads/compressed_1c648875-1276-4068-bed8-8224ab984f9f_ʳ������һ����������.png new file mode 100644 index 0000000..d83aa7b Binary files /dev/null and b/backend/src/Health.WebApi/uploads/compressed_1c648875-1276-4068-bed8-8224ab984f9f_ʳ������һ����������.png differ diff --git a/backend/src/Health.WebApi/uploads/compressed_23f701f4-e4fe-4ea0-a7c8-fe6aaa23dc22_ʳ������һ����������.png b/backend/src/Health.WebApi/uploads/compressed_23f701f4-e4fe-4ea0-a7c8-fe6aaa23dc22_ʳ������һ����������.png new file mode 100644 index 0000000..d83aa7b Binary files /dev/null and b/backend/src/Health.WebApi/uploads/compressed_23f701f4-e4fe-4ea0-a7c8-fe6aaa23dc22_ʳ������һ����������.png differ diff --git a/backend/src/Health.WebApi/uploads/compressed_5b23688a-2eeb-4ecf-9d51-23ccdeb612c9_ʳ������һ����������.png b/backend/src/Health.WebApi/uploads/compressed_5b23688a-2eeb-4ecf-9d51-23ccdeb612c9_ʳ������һ����������.png new file mode 100644 index 0000000..dc69862 Binary files /dev/null and b/backend/src/Health.WebApi/uploads/compressed_5b23688a-2eeb-4ecf-9d51-23ccdeb612c9_ʳ������һ����������.png differ diff --git a/backend/src/Health.WebApi/uploads/compressed_77ce2c3a-ac17-417c-8639-746aa478fc55_test_9103.jpg b/backend/src/Health.WebApi/uploads/compressed_77ce2c3a-ac17-417c-8639-746aa478fc55_test_9103.jpg new file mode 100644 index 0000000..e684337 Binary files /dev/null and b/backend/src/Health.WebApi/uploads/compressed_77ce2c3a-ac17-417c-8639-746aa478fc55_test_9103.jpg differ diff --git a/backend/src/Health.WebApi/uploads/compressed_9b0800a5-27d7-4ad6-a43a-6ba9bb9ac9f7_test_9103.jpg b/backend/src/Health.WebApi/uploads/compressed_9b0800a5-27d7-4ad6-a43a-6ba9bb9ac9f7_test_9103.jpg new file mode 100644 index 0000000..e684337 Binary files /dev/null and b/backend/src/Health.WebApi/uploads/compressed_9b0800a5-27d7-4ad6-a43a-6ba9bb9ac9f7_test_9103.jpg differ diff --git a/backend/src/Health.WebApi/uploads/compressed_ad73133d-1be7-4a2a-b627-c1344f95c429_test_9103.jpg b/backend/src/Health.WebApi/uploads/compressed_ad73133d-1be7-4a2a-b627-c1344f95c429_test_9103.jpg new file mode 100644 index 0000000..e684337 Binary files /dev/null and b/backend/src/Health.WebApi/uploads/compressed_ad73133d-1be7-4a2a-b627-c1344f95c429_test_9103.jpg differ diff --git a/backend/src/Health.WebApi/uploads/compressed_c0630e4d-a076-4286-a595-d3ef58f13b3d_test_9103.jpg b/backend/src/Health.WebApi/uploads/compressed_c0630e4d-a076-4286-a595-d3ef58f13b3d_test_9103.jpg new file mode 100644 index 0000000..e684337 Binary files /dev/null and b/backend/src/Health.WebApi/uploads/compressed_c0630e4d-a076-4286-a595-d3ef58f13b3d_test_9103.jpg differ diff --git a/backend/src/Health.WebApi/uploads/dd601a6e-f5d8-4502-8070-98e61011c67a_test_food.png b/backend/src/Health.WebApi/uploads/dd601a6e-f5d8-4502-8070-98e61011c67a_test_food.png new file mode 100644 index 0000000..37b003f Binary files /dev/null and b/backend/src/Health.WebApi/uploads/dd601a6e-f5d8-4502-8070-98e61011c67a_test_food.png differ diff --git a/backend/uploads/food_test.jpg b/backend/uploads/food_test.jpg new file mode 100644 index 0000000..5c52bb3 Binary files /dev/null and b/backend/uploads/food_test.jpg differ diff --git a/backend/uploads/ft_q50.jpg b/backend/uploads/ft_q50.jpg new file mode 100644 index 0000000..c7fae0c Binary files /dev/null and b/backend/uploads/ft_q50.jpg differ diff --git a/backend/uploads/ft_q55.jpg b/backend/uploads/ft_q55.jpg new file mode 100644 index 0000000..261fb38 Binary files /dev/null and b/backend/uploads/ft_q55.jpg differ diff --git a/backend/uploads/test_9103.jpg b/backend/uploads/test_9103.jpg new file mode 100644 index 0000000..da102c3 Binary files /dev/null and b/backend/uploads/test_9103.jpg differ diff --git a/backend/uploads/test_food.jpg b/backend/uploads/test_food.jpg new file mode 100644 index 0000000..5492407 Binary files /dev/null and b/backend/uploads/test_food.jpg differ diff --git a/backend/uploads/test_food.png b/backend/uploads/test_food.png new file mode 100644 index 0000000..37b003f Binary files /dev/null and b/backend/uploads/test_food.png differ diff --git a/backend/uploads/test_food_hq.jpg b/backend/uploads/test_food_hq.jpg new file mode 100644 index 0000000..87118a5 Binary files /dev/null and b/backend/uploads/test_food_hq.jpg differ diff --git a/backend/uploads/test_food_mid.jpg b/backend/uploads/test_food_mid.jpg new file mode 100644 index 0000000..3f8d1ee Binary files /dev/null and b/backend/uploads/test_food_mid.jpg differ diff --git a/backend/uploads/test_food_small.png b/backend/uploads/test_food_small.png new file mode 100644 index 0000000..b763f07 Binary files /dev/null and b/backend/uploads/test_food_small.png differ diff --git a/食堂三菜一饭热量估算.png b/食堂三菜一饭热量估算.png new file mode 100644 index 0000000..37b003f Binary files /dev/null and b/食堂三菜一饭热量估算.png differ