fix: VLM 食物识别全链路修复 + 用药 Agent Prompt 优化

- 图片上传自动压缩(max 860px, JPEG Q65),解决大图超 API 129KB 限制
- 修复 VLM 传 file:// 本地路径 Bug,改为 base64 data URL
- VLM Prompt 优化为中文食堂场景,附带常见中餐热量参考
- 千问 API 错误信息透传,方便调试
- 用药 Agent Prompt 加查询规则:先调 manage_medication 再回答
- 新增 System.Drawing.Common 依赖用于服务端图片压缩
This commit is contained in:
MingNian
2026-06-02 13:44:14 +08:00
parent 0e7f0a0b80
commit 27cc920a4a
4 changed files with 57 additions and 17 deletions

View File

@@ -129,7 +129,11 @@ public sealed class QwenVisionClient(HttpClient http, IConfiguration config)
var json = JsonSerializer.Serialize(request, _jsonOptions);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await _http.PostAsync("chat/completions", content, ct);
response.EnsureSuccessStatusCode();
if (!response.IsSuccessStatusCode)
{
var errorBody = await response.Content.ReadAsStringAsync(ct);
throw new HttpRequestException($"VLM API {response.StatusCode}: {errorBody}");
}
var body = await response.Content.ReadAsStringAsync(ct);
return JsonSerializer.Deserialize<ChatCompletionResponse>(body, _jsonOptions)!;
}

View File

@@ -83,11 +83,12 @@ public sealed class PromptManager
1. ///
2. "早饭后"
3.
4.
5.
1. manage_medication(action="query")
2. ///
3. "早饭后"
4.
5.
6.
""";
private const string ReportPrompt = """