Phase 17: Multimodal image understanding via analyze_image tool

Dual-model approach (C): Qwen3-8B handles conversation, Qwen2.5-VL-7B
analyzes images on demand via analyze_image LangChain tool.

- services/model/mlx_vision_model.py: MlxVisionModel (mlx-vlm wrapper, lazy load)
- services/agent/tools.py: make_vision_tool(vision_model, image_path)
- agent_service.py: stream_response(image_path=None), dynamic tool binding
  via config["image_path"] — thread-safe per-request rebinding
- container.py: vision_model Singleton provider
- config.py: vision_enabled, vision_model_id, vision_max_tokens
- api.py: image_base64 in ChatRequest, decode to temp file, cleanup after stream

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
sal
2026-06-02 13:52:10 +09:00
parent bdb6fd83c4
commit 68f741af72
8 changed files with 355 additions and 18 deletions
+18 -4
View File
@@ -479,13 +479,27 @@ docker-compose.yml
---
## Phase 17 — 멀티모달 이미지 이해 ★☆☆
## Phase 17 — 멀티모달 이미지 이해 ★☆☆
**배경**: 이유식 사진 → 재료 분석, 금융 서류 사진 → 내용 해석 등.
**제약**: Qwen3-14B는 이미지 미지원 → `mlx-community/Qwen2.5-VL-7B-Instruct-4bit` 교체 필요.
**구현 방식**: Dual-model C방식 — analyze_image 도구
**난이도**: 높음 | **임팩트**: 높음 (장기 과제)
| 모델 | 역할 |
|------|------|
| Qwen3-8B-4bit | 대화·추론 (항상 로드) |
| Qwen2.5-VL-7B-Instruct-4bit | 이미지 분석 (lazy load) |
- `services/model/mlx_vision_model.py` — MlxVisionModel (mlx-vlm 래퍼, lazy load)
- `services/agent/tools.py` — `make_vision_tool(vision_model, image_path)` 추가
- `agent_service.py` — `stream_response(image_path=None)`, config 경유 vision tool 동적 주입
- `api.py` — `image_base64` 필드 추가, temp 파일 저장 후 응답 완료 시 삭제
- `youlbot-webui` — `image_input` 컴포넌트 추가, ChatService.chat(image_path=) 연결
- `.env` — `VISION_ENABLED=true`, `VISION_MODEL_ID` 설정
**실행 방법**: API 서버 재시작 후 WebUI 이미지 첨부 버튼으로 사진 전송
**난이도**: 높음 | **임팩트**: 높음
---
@@ -529,4 +543,4 @@ Phase 20 RAGAS 평가 → Phase 15 (모델선택) → Phase 16 (Docke
| Phase 20 RAGAS 평가 | ✅ 완료 | — | — | — |
| Phase 15 모델 선택 | 🔲 미완 | 중간 | 중간 | 4순위 |
| Phase 16 Docker | 🔲 미완 | 높음 | 중간 | 5순위 |
| Phase 17 멀티모달 | 🔲 미완 | 높음 | 높음 | 6순위 |
| Phase 17 멀티모달 | ✅ 완료 | | | |