feat: image upload in chat with OCR text extraction#588
Merged
Conversation
Upload images (JPEG, PNG, WebP, GIF, max 10MB) directly in admin chat.
Images are stored in data/chat_images/{session_id}/, with thumbnails.
OCR via pytesseract (optional dep) extracts text and injects it into
the message sent to LLM as "[Текст с изображения]" block.
Images have lifecycle tied to chat sessions — when a session is deleted,
its images are cleaned up from disk. Supports paste (Ctrl+V) of images
from clipboard, drag-and-drop via file input, and multiple uploads.
Backend:
- ChatMessage.extra_data column (JSON) stores image metadata
- modules/chat/image_service.py: upload, OCR, thumbnail, cleanup
- Upload endpoint: POST /admin/chat/sessions/{id}/upload-image
- Serve endpoint: GET /admin/chat/images/{session_id}/{filename}
- Image IDs passed in SendMessageRequest.image_ids
- Cleanup hooks in ChatService.delete_session/delete_sessions_bulk
Frontend:
- ChatImage interface, uploadImage API method
- Image upload button (ImagePlus icon) next to mic in chat input
- Pending image thumbnails preview above textarea
- Clipboard paste intercepts image/* types
- Image attachments rendered in message bubbles with click-to-fullscreen
- OCR badge indicator on images with extracted text
- i18n: uploadImage + removeImage in ru/en/kk
Migration: scripts/migrate_add_extra_data_to_chat_messages.py
## NEWS
🖼️ **Загрузка фото в чат с распознаванием текста**
Теперь в чат можно загружать изображения — фото документов, скриншоты,
сканы. Система автоматически распознаёт текст (OCR) и отправляет его
ассистенту вместе с вашим вопросом. Можно вставлять через Ctrl+V
или кнопку загрузки. Фото хранятся ровно столько, сколько живёт чат —
при удалении чата удаляются и все вложения.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
data/chat_images/{session_id}/[Текст с изображения]blockChatService.delete_sessionhooks)extra_dataTEXT column onchat_messages(JSON metadata for images)scripts/migrate_add_extra_data_to_chat_messages.pypytesseract>=0.3.10(optional — requirestesseract-ocrsystem package)uploadImage+removeImagekeys in ru/en/kkNEWS
🖼️ Загрузка фото в чат с распознаванием текста
Теперь в чат можно загружать изображения — фото документов, скриншоты,
сканы. Система автоматически распознаёт текст (OCR) и отправляет его
ассистенту вместе с вашим вопросом. Можно вставлять через Ctrl+V
или кнопку загрузки. Фото хранятся ровно столько, сколько живёт чат —
при удалении чата удаляются и все вложения.
Test plan
data/chat_images/{session_id}/directory removedpython scripts/migrate_add_extra_data_to_chat_messages.pycd admin && npm run build✅🤖 Generated with Claude Code