CodeWhale icon indicating copy to clipboard operation
CodeWhale copied to clipboard

Add vision_model registration & vision tools for image input support

Open MMMarcinho opened this issue 6 months ago • 6 comments

Problem

Mainstream DeepSeek models (e.g., deepseek-v4-pro) do not natively support multimodal image input. Offloading image recognition to a dedicated, fast vision-capable LLM allows the main agent to stay focused on reasoning and coding, without being distracted by visual parsing work.

Proposed solution

1. Clipboard image paste (Ctrl+V)

Pressing Ctrl+V in the composer reads the system clipboard. If it contains an image (RGBA bitmap), the TUI encodes it as PNG, persists it to ~/.deepseek/clipboard-images/clipboard-{timestamp}.png, and inserts a text reference into the input buffer:

[image:/home/user/.deepseek/clipboard-images/clipboard-1715030400123456789.png]

A status hint is displayed, e.g. Attached image: 1024x768 PNG (235KB).

This works independently of vision_model — the image is saved to disk and referenced by path so the main model or any sub-agent can read it via standard file tools.

2. Dedicated vision model ([vision_model])

Users can configure a standalone [vision_model] in config.toml. Once enabled via the vision_model feature flag, two built-in vision tools become available:

  • vision_analyze — reads an image file from disk, base64-encodes it, sends it to the configured vision model for analysis
  • vision_ocr — delegates to vision_analyze with an OCR-specific prompt to extract text from images

The vision model runs with fully independent session state, isolated from the main model's context window.

Configure in config.toml

[features]
  vision_model = true 

[vision_model]
  model = ""gemini-3.1-flash-lite-preview"          # vision_model
  provider = "openai"        # optional
  api_key = "..."
  base_url = "https://generativelanguage.googleapis.com/v1beta/openai/"

End-to-end flow

Ctrl+V (clipboard has image) → PNG saved to ~/.deepseek/clipboard-images/ → [image:path] inserted into composer → user types prompt: "what does this screenshot show?" → DeepSeek main model decides to call vision_analyze → tool reads image file, base64-encodes it → independent vision session sends OpenAI-compatible request to Gemini → analysis result flows back → main model → user

Supported image formats

  • Clipboard paste: any RGBA bitmap on the system clipboard
  • File analysis (vision_analyze / vision_ocr): png, jpg/jpeg, gif, webp, bmp, svg

Additional context

Input Image

Image

Input Prompt

Image

Output Result

Image

MMMarcinho avatar May 06 '26 12:05 MMMarcinho

问题背景

主流 DeepSeek 模型(例如 deepseek-v4-pro)原生不支持图片类多模态输入。将图像识别任务交由独立、高性能的视觉大模型处理,可让主智能体专注于逻辑推理与代码编写,无需被图像解析相关工作分散精力。

解决方案

1. 剪贴板图片粘贴(Ctrl+V)

在输入框按下 Ctrl+V 时会读取系统剪贴板内容。若剪贴板中存在图片(RGBA 位图),TUI 会将其编码为 PNG 格式,保存至目录: ~/.deepseek/clipboard-images/clipboard-{timestamp}.png

同时在输入框中插入文本引用标记: [image:/home/user/.deepseek/clipboard-images/clipboard-1715030400123456789.png]

并展示状态提示,例如:已附加图片: 1024x768 PNG (235KB)。

该功能可独立于 vision_model 运行——图片仅落地保存并通过路径引用,主模型或任意子智能体均可通过标准文件工具读取图片。

2. 独立视觉模型(vision_model)

用户可在 config.toml 中配置独立的视觉模型。开启 vision_model 功能开关后,会自动提供两个内置视觉工具:

  • vision_analyze — 读取本地图片文件,进行 Base64 编码,调用已配置的视觉模型完成图像分析
  • vision_ocr — 基于 vision_analyze 能力,内置 OCR 专用提示词,实现图片文字提取

视觉模型拥有完全独立的会话状态,与主模型的上下文窗口相互隔离。

config.toml 配置示例

[features]
  vision_model = true 

[vision_model]
  model = "gemini-3.1-flash-lite-preview"  # 视觉模型
  provider = "openai"        # 可选
  api_key = "..."
  base_url = "https://generativelanguage.googleapis.com/v1beta/openai/"

端到端流程

Ctrl+V(剪贴板包含图片) → 图片保存至 ~/.deepseek/clipboard-images/ → 输入框插入 [image:路径] 引用→ 用户输入提问:what does this screenshot show? → DeepSeek 主模型决定调用 vision_analyze 工具 → 工具读取图片文件并做 Base64 编码 → 独立视觉会话以 OpenAI 兼容格式请求 Gemini → 分析结果回流至主模型 → 最终返回给用户

支持图片格式: 剪贴板粘贴:系统剪贴板中任意 RGBA 位图 文件解析(vision_analyze /vision_ocr):png、jpg/jpeg、gif、webp、bmp、svg

附件图片

Image

MMMarcinho avatar May 06 '26 12:05 MMMarcinho

Resolves https://github.com/Hmbown/DeepSeek-TUI/pull/871

MMMarcinho avatar May 06 '26 12:05 MMMarcinho

great idea - thank you. I had considered adding a moondream option but this helps very much and will prepare us for DS v4 vision

Hmbown avatar May 06 '26 21:05 Hmbown

@Hmbown Thanks I’m wondering if the project already has any vision-related features in progress.If yes, I can adjust my PR to match the existing design.If not, could you please do a code review and give me some suggestions for improvement? I’ll revise it accordingly. :)

MMMarcinho avatar May 07 '26 01:05 MMMarcinho

Closing as completed. Current main has , config, the vision-model tool, , docs in CONFIGURATION/TOOL_SURFACE, and registry wiring that only advertises when the feature and vision config are enabled. Remaining clipboard-image paste UX or provider-specific vision improvements should be filed as narrower follow-ups.

Hmbown avatar Jun 22 '26 19:06 Hmbown

Correction to the closing note above: current main has [features] vision_model, [vision_model] config, the image_analyze vision-model tool, image_ocr, docs in CONFIGURATION/TOOL_SURFACE, and registry wiring that only advertises image_analyze when the feature and vision config are enabled. Remaining clipboard-image paste UX or provider-specific vision improvements should be filed as narrower follow-ups.

Hmbown avatar Jun 22 '26 19:06 Hmbown