admin_bot: attach sample test image when testing vision-enabled provider
This commit is contained in:
+24
-2
@@ -1867,19 +1867,41 @@ class AdminBotService:
|
|||||||
repo=self.repo
|
repo=self.repo
|
||||||
)
|
)
|
||||||
t0 = time.time()
|
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:
|
try:
|
||||||
res = await test_client.generate_json(
|
res = await test_client.generate_json(
|
||||||
prompt=test_prompt,
|
prompt=test_prompt,
|
||||||
system_prompt="You are a test agent. Always reply with valid JSON only.",
|
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
|
latency = time.time() - t0
|
||||||
res_text = json.dumps(res, ensure_ascii=False, indent=2)
|
res_text = json.dumps(res, ensure_ascii=False, indent=2)
|
||||||
|
vision_info = "🟢 ارسال و با تصویر پردازش شد" if test_img_path else "⚪️ فقط متن (غیرفعال)"
|
||||||
card = (
|
card = (
|
||||||
f"🧪 <b>نتیجه تست ارائهدهنده «{prof.name}»:</b>\n\n"
|
f"🧪 <b>نتیجه تست ارائهدهنده «{prof.name}»:</b>\n\n"
|
||||||
f"• 🔌 <b>Provider:</b> <code>{prof.provider_type}</code>\n"
|
f"• 🔌 <b>Provider:</b> <code>{prof.provider_type}</code>\n"
|
||||||
f"• 🏷 <b>Model:</b> <code>{prof.model}</code>\n"
|
f"• 🏷 <b>Model:</b> <code>{prof.model}</code>\n"
|
||||||
|
f"• 🖼 <b>پردازش تصویر:</b> {vision_info}\n"
|
||||||
f"• ⏱ <b>مدت زمان:</b> {latency:.2f}s\n"
|
f"• ⏱ <b>مدت زمان:</b> {latency:.2f}s\n"
|
||||||
f"• 📊 <b>وضعیت:</b> ✅ موفق (Success)\n\n"
|
f"• 📊 <b>وضعیت:</b> ✅ موفق (Success)\n\n"
|
||||||
f"📥 <b>Input Prompt:</b>\n<code>{test_prompt}</code>\n\n"
|
f"📥 <b>Input Prompt:</b>\n<code>{test_prompt}</code>\n\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user