[P0/严重] Ollama Adapter 将公网 URL 图片当作 base64 字符串直接传递 #2

Open
opened 2026-07-21 21:55:34 +08:00 by thzxx · 0 comments
Owner

问题类型

缺陷 / 严重 / LLM 适配器

文件位置

electron/harness/adapters/ollama.adapter.ts

问题描述

当用户上传图片或 LLM 调用涉及图片消息时,MetonaMessage.images 中可能存储的是 http(s) URL。
当前 Ollama Adapter 的多模态处理直接将 URL 当作 base64 字符串塞入 images: [url] 字段传给 Ollama。
Ollama 无法识别该格式,会抛出 base64 解码错误或返回空响应。

影响

  • Ollama 用户上传任何图片都会导致请求失败
  • 多模态能力完全不可用

建议修复

参考 Agnes AI Adapter 实现:

  1. 检测 image 是否为 http(s) URL
  2. 若是 URL,先用 fetch 下载为 Buffer,再转 base64 dataURL
  3. 若已是 dataURL 或 base64,直接使用
async function resolveImageToBase64(image: string): Promise<string> {
  if (image.startsWith('http')) {
    const res = await fetch(image);
    const buf = Buffer.from(await res.arrayBuffer());
    return `data:${res.headers.get('content-type') ?? 'image/png'};base64,${buf.toString('base64')}`;
  }
  return image;
}
## 问题类型 缺陷 / 严重 / LLM 适配器 ## 文件位置 `electron/harness/adapters/ollama.adapter.ts` ## 问题描述 当用户上传图片或 LLM 调用涉及图片消息时,MetonaMessage.images 中可能存储的是 http(s) URL。 当前 Ollama Adapter 的多模态处理直接将 URL 当作 base64 字符串塞入 `images: [url]` 字段传给 Ollama。 Ollama 无法识别该格式,会抛出 base64 解码错误或返回空响应。 ## 影响 - Ollama 用户上传任何图片都会导致请求失败 - 多模态能力完全不可用 ## 建议修复 参考 Agnes AI Adapter 实现: 1. 检测 image 是否为 http(s) URL 2. 若是 URL,先用 fetch 下载为 Buffer,再转 base64 dataURL 3. 若已是 dataURL 或 base64,直接使用 ```ts async function resolveImageToBase64(image: string): Promise<string> { if (image.startsWith('http')) { const res = await fetch(image); const buf = Buffer.from(await res.arrayBuffer()); return `data:${res.headers.get('content-type') ?? 'image/png'};base64,${buf.toString('base64')}`; } return image; } ```
thzxx added the ????LLM??? labels 2026-07-21 21:55:34 +08:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: MetonaTeam/metona-ai-desktop#2