From 410b238abb18e59dd4b0f2aca53361681c8d968a Mon Sep 17 00:00:00 2001 From: mamad Date: Fri, 28 Aug 2026 21:21:41 +0330 Subject: [PATCH] admin_bot: attach sample test image when testing vision-enabled provider --- services/admin_bot.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/services/admin_bot.py b/services/admin_bot.py index 19f4f74..50863ee 100644 --- a/services/admin_bot.py +++ b/services/admin_bot.py @@ -1867,19 +1867,41 @@ class AdminBotService: repo=self.repo ) t0 = time.time() - test_prompt = "Say hello and return JSON with keys: status (ok), message (Hello from Copykar), and ping (pong)." + test_img_path = None + if getattr(prof, "supports_vision", False): + test_img_path = "/app/data/media/vision_test.jpg" if os.path.exists("/app") else "/projects/telegram-bots/copykar/data/media/vision_test.jpg" + if not os.path.exists(test_img_path): + try: + from PIL import Image, ImageDraw + os.makedirs(os.path.dirname(test_img_path), exist_ok=True) + img = Image.new('RGB', (400, 200), color=(240, 240, 240)) + d = ImageDraw.Draw(img) + d.rectangle([(20, 20), (380, 180)], outline=(0, 120, 215), width=4) + d.text((50, 80), 'CODE: COPYKAR-TEST-7799', fill=(200, 30, 30)) + img.save(test_img_path) + except Exception: + test_img_path = None + + if test_img_path: + test_prompt = "Say hello, analyze the attached image, and return JSON with keys: status (ok), message (Hello from Copykar), ping (pong), and image_seen (describe what text/code is visible in the image)." + else: + test_prompt = "Say hello and return JSON with keys: status (ok), message (Hello from Copykar), and ping (pong)." + try: res = await test_client.generate_json( prompt=test_prompt, system_prompt="You are a test agent. Always reply with valid JSON only.", - action_name="test_provider_profile" + action_name="test_provider_profile", + image_path=test_img_path ) latency = time.time() - t0 res_text = json.dumps(res, ensure_ascii=False, indent=2) + vision_info = "🟢 ارسال و با تصویر پردازش شد" if test_img_path else "⚪️ فقط متن (غیرفعال)" card = ( f"🧪 نتیجه تست ارائه‌دهنده «{prof.name}»:\n\n" f"• 🔌 Provider: {prof.provider_type}\n" f"• 🏷 Model: {prof.model}\n" + f"• 🖼 پردازش تصویر: {vision_info}\n" f"• ⏱ مدت زمان: {latency:.2f}s\n" f"• 📊 وضعیت: ✅ موفق (Success)\n\n" f"📥 Input Prompt:\n{test_prompt}\n\n"