feat: VLM 模型切换 qwen3-vl-plus + Diet Agent 患者档案联动
- VLM 模型切换为 qwen3-vl-plus(中餐识别准确率大幅提升) - VLM Prompt 简化为仅识别食物名+份量+热量 - 营养分析/禁忌提醒移至 Diet Agent(可查患者档案) - Diet Agent Prompt 强化:过敏→红色警告,低盐低脂→黄色提醒 - 上传限制调整至 20MB - 服务端图片压缩参数优化(960px/Q72)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user