chore: 回退至稳定版本,清理测试文件
- 回退 VLM prompt 至稳定的通用食物识别版本 - 保持 VisionClient 重命名和 VLM_* 配置键 - 清理所有测试图片和临时文件
@@ -232,7 +232,7 @@ public static class AiChatEndpoints
|
||||
// VLM 食物识别
|
||||
app.MapPost("/api/ai/analyze-food-image", async (
|
||||
HttpRequest httpRequest, HttpContext http,
|
||||
QwenVisionClient visionClient, AppDbContext db,
|
||||
VisionClient visionClient, AppDbContext db,
|
||||
CancellationToken ct) =>
|
||||
{
|
||||
var userId = GetUserId(http);
|
||||
@@ -242,8 +242,6 @@ public static class AiChatEndpoints
|
||||
var files = form.Files.GetFiles("images");
|
||||
if (files == null || files.Count == 0)
|
||||
return Results.Ok(new { code = 40001, data = (object?)null, message = "请上传至少一张图片" });
|
||||
if (files.Count > 8)
|
||||
return Results.Ok(new { code = 40001, data = (object?)null, message = "一次最多上传 8 张图片" });
|
||||
|
||||
var imageUrls = new List<string>();
|
||||
var uploadsDir = Path.Combine(Directory.GetCurrentDirectory(), "uploads");
|
||||
@@ -272,19 +270,9 @@ public static class AiChatEndpoints
|
||||
}
|
||||
|
||||
var prompt = """
|
||||
你是一个专业营养师。请仔细分析这些食物照片(可能是同一餐不同角度拍摄)。
|
||||
|
||||
要求:
|
||||
1. 识别所有食物,用中文名称
|
||||
2. 根据多角度照片综合判断份量,尽量精准
|
||||
3. 估算每项的热量、蛋白质、碳水、脂肪(克)
|
||||
|
||||
只返回JSON:
|
||||
识别图片中所有食物,用中文名称,只返回JSON:
|
||||
{
|
||||
"foods": [
|
||||
{"name":"食物名","portion":"份量描述","calories":整数,"proteinGrams":整数,"carbsGrams":整数,"fatGrams":整数}
|
||||
],
|
||||
"totalCalories":整数
|
||||
"foods": [{"name":"食物名","portion":"份量","calories":整数}]
|
||||
}
|
||||
""";
|
||||
|
||||
|
||||
@@ -73,10 +73,10 @@ builder.Services.AddHttpClient<DeepSeekClient>(client =>
|
||||
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", builder.Configuration["DEEPSEEK_API_KEY"] ?? "");
|
||||
client.Timeout = TimeSpan.FromSeconds(60);
|
||||
});
|
||||
builder.Services.AddHttpClient<QwenVisionClient>(client =>
|
||||
builder.Services.AddHttpClient<VisionClient>(client =>
|
||||
{
|
||||
client.BaseAddress = new Uri((builder.Configuration["QWEN_BASE_URL"] ?? "https://dashscope.aliyuncs.com/compatible-mode/v1").TrimEnd('/') + "/");
|
||||
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", builder.Configuration["QWEN_API_KEY"] ?? "");
|
||||
client.BaseAddress = new Uri((builder.Configuration["VLM_BASE_URL"] ?? "https://dashscope.aliyuncs.com/compatible-mode/v1").TrimEnd('/') + "/");
|
||||
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", builder.Configuration["VLM_API_KEY"] ?? "");
|
||||
client.Timeout = TimeSpan.FromSeconds(60);
|
||||
});
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 114 KiB |
|
Before Width: | Height: | Size: 82 KiB |
|
Before Width: | Height: | Size: 5.2 MiB |
|
Before Width: | Height: | Size: 5.2 MiB |
|
Before Width: | Height: | Size: 82 KiB |
|
Before Width: | Height: | Size: 112 KiB |
|
Before Width: | Height: | Size: 5.2 MiB |
|
Before Width: | Height: | Size: 5.2 MiB |
|
Before Width: | Height: | Size: 114 KiB |
|
Before Width: | Height: | Size: 5.2 MiB |
|
Before Width: | Height: | Size: 420 KiB |
|
Before Width: | Height: | Size: 5.2 MiB |
|
Before Width: | Height: | Size: 181 KiB |
|
Before Width: | Height: | Size: 114 KiB |
|
Before Width: | Height: | Size: 114 KiB |
|
Before Width: | Height: | Size: 114 KiB |
|
Before Width: | Height: | Size: 231 KiB |
|
Before Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 77 KiB |
|
Before Width: | Height: | Size: 77 KiB |
|
Before Width: | Height: | Size: 77 KiB |
|
Before Width: | Height: | Size: 162 KiB |
|
Before Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 5.2 MiB |
|
Before Width: | Height: | Size: 181 KiB |
|
Before Width: | Height: | Size: 107 KiB |
|
Before Width: | Height: | Size: 112 KiB |
|
Before Width: | Height: | Size: 114 KiB |
|
Before Width: | Height: | Size: 82 KiB |
|
Before Width: | Height: | Size: 5.2 MiB |
|
Before Width: | Height: | Size: 420 KiB |
|
Before Width: | Height: | Size: 231 KiB |
|
Before Width: | Height: | Size: 2.9 MiB |