more error handling + photos in reply in guest

This commit is contained in:
huker667 committed 2026-05-22 20:04:26 +03:00
1 parent b027361586
commit a60caf5dba
2 files changed
+34 -14

No files matched your search

+29 -13
View File
@@ -132,6 +132,17 @@ async def guest_middleware(handler, event, data):
else:
replied_text = None
prompt = ""
if replied and replied.photo and IMAGE_MODEL != "":
try:
photo = replied.photo[-1]
file_bytes = await bot.download(photo)
image_bytes = file_bytes.read()
b64_image = base64.b64encode(image_bytes).decode("utf-8")
image_text = await image2text(image=b64_image)
except Exception as e:
image_text = "произошла ошибка при анализе фото"
print(f"{RED} -- photo - {e}{RESET}")
prompt = f"{prompt}<фото в ответе>{image_text}</фото в ответе>\n"
if message.photo and IMAGE_MODEL != "":
try:
photo = message.photo[-1]
@@ -142,7 +153,7 @@ async def guest_middleware(handler, event, data):
except Exception as e:
image_text = "произошла ошибка при анализе фото"
print(f"{RED} -- photo - {e}{RESET}")
prompt = f"<фото>{image_text}</фото>\n"
prompt = f"{prompt}<фото>{image_text}</фото>\n"
prompt = f"{prompt}\n{user_text}"
if replied_text:
@@ -169,20 +180,25 @@ async def guest_middleware(handler, event, data):
),
)
)
except Exception:
await data["bot"](
AnswerGuestQuery(
guest_query_id=message.guest_query_id,
result=InlineQueryResultArticle(
id="1",
title="ok",
input_message_content=InputTextMessageContent(
message_text=result,
parse_mode="None"
except Exception as e:
try:
await data["bot"](
AnswerGuestQuery(
guest_query_id=message.guest_query_id,
result=InlineQueryResultArticle(
id="1",
title="ok",
input_message_content=InputTextMessageContent(
message_text=result,
parse_mode="None"
),
),
),
)
)
)
except Exception as e:
print(f"{RED} -- send guest - {e}{RESET}")
else:
print(f"{YELLOW} -- markdown - {e}{RESET}")
return