From 7572e45d2a74641794bc5beaacfff68a4ab9e9a2 Mon Sep 17 00:00:00 2001 From: Apple Date: Fri, 21 Nov 2025 01:16:33 -0800 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=B4=D0=BE=D0=B4=D0=B0=D0=BD=D0=BE=20?= =?UTF-8?q?=D0=BE=D0=B1=D1=80=D0=BE=D0=B1=D0=BA=D1=83=20=D1=84=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=20=D0=B4=D0=BB=D1=8F=20Helion=20=D0=B1=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20Swapper=20vision-8b?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gateway-bot/http_api.py | 91 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/gateway-bot/http_api.py b/gateway-bot/http_api.py index d2dba679..eb903b3a 100644 --- a/gateway-bot/http_api.py +++ b/gateway-bot/http_api.py @@ -917,6 +917,97 @@ async def helion_telegram_webhook(update: TelegramUpdate): await send_telegram_message(chat_id, "Наразі підтримуються тільки PDF-документи. Інші формати (docx, zip, тощо) будуть додані пізніше.", helion_token) return {"ok": False, "error": "Unsupported document type"} + # Check if it's a photo + photo = update.message.get("photo") + if photo: + # Telegram sends multiple sizes, get the largest one (last in array) + photo_obj = photo[-1] if isinstance(photo, list) else photo + file_id = photo_obj.get("file_id") if isinstance(photo_obj, dict) else None + + if file_id: + logger.info(f"Helion: Photo from {username} (tg:{user_id}), file_id: {file_id}") + + try: + # Get file path from Telegram + helion_token = os.getenv("HELION_TELEGRAM_BOT_TOKEN") + file_path = await get_telegram_file_path(file_id) + if not file_path: + raise HTTPException(status_code=400, detail="Failed to get file from Telegram") + + # Build file URL + file_url = f"https://api.telegram.org/file/bot{helion_token}/{file_path}" + + # Send "Processing..." message + await send_telegram_message(chat_id, "📸 Обробляю фото через Vision-8b модель...", helion_token) + + # Send to Router with specialist_vision_8b model (Swapper) + router_request = { + "message": f"Опиши це зображення детально, зосередься на технічних деталях EcoMiner/BioMiner якщо вони є: {file_url}", + "mode": "chat", + "agent": "helion", + "metadata": { + "source": "telegram", + "dao_id": dao_id, + "user_id": f"tg:{user_id}", + "session_id": f"tg:{chat_id}:{dao_id}", + "username": username, + "chat_id": chat_id, + "file_id": file_id, + "file_url": file_url, + "has_image": True, + }, + "context": { + "agent_name": HELION_NAME, + "system_prompt": HELION_SYSTEM_PROMPT, + }, + } + + # Override LLM to use specialist_vision_8b for image understanding + router_request["metadata"]["use_llm"] = "specialist_vision_8b" + + # Send to Router + logger.info(f"Helion: Sending photo to Router with vision-8b: file_url={file_url[:50]}...") + response = await send_to_router(router_request) + + # Extract response + if isinstance(response, dict) and response.get("ok"): + answer_text = response.get("data", {}).get("text") or response.get("response", "") + + if answer_text: + # Photo processed successfully + await send_telegram_message( + chat_id, + f"✅ **Фото оброблено**\n\n{answer_text}", + helion_token + ) + + # Save to memory for context + await memory_client.save_chat_turn( + agent_id="helion", + team_id=dao_id, + user_id=f"tg:{user_id}", + message=f"[Photo: {file_id}]", + response=answer_text, + channel_id=chat_id, + scope="short_term" + ) + + return {"ok": True, "agent": "helion", "model": "specialist_vision_8b"} + else: + await send_telegram_message(chat_id, "Фото оброблено, але не вдалося отримати опис.", helion_token) + return {"ok": False, "error": "No description in response"} + else: + error_msg = response.get("error", "Unknown error") if isinstance(response, dict) else "Router error" + logger.error(f"Helion: Vision-8b error: {error_msg}") + await send_telegram_message(chat_id, f"Вибач, не вдалося обробити фото: {error_msg}", helion_token) + return {"ok": False, "error": error_msg} + + except Exception as e: + logger.error(f"Helion: Photo processing failed: {e}", exc_info=True) + helion_token = os.getenv("HELION_TELEGRAM_BOT_TOKEN") + await send_telegram_message(chat_id, "Вибач, не вдалося обробити фото. Переконайся, що Swapper Service з vision-8b моделлю запущений.", helion_token) + return {"ok": False, "error": "Photo processing failed"} + # Get message text text = update.message.get("text", "") if not text: