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: else:
replied_text = None replied_text = None
prompt = "" 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 != "": if message.photo and IMAGE_MODEL != "":
try: try:
photo = message.photo[-1] photo = message.photo[-1]
@@ -142,7 +153,7 @@ async def guest_middleware(handler, event, data):
except Exception as e: except Exception as e:
image_text = "произошла ошибка при анализе фото" image_text = "произошла ошибка при анализе фото"
print(f"{RED} -- photo - {e}{RESET}") print(f"{RED} -- photo - {e}{RESET}")
prompt = f"<фото>{image_text}</фото>\n" prompt = f"{prompt}<фото>{image_text}</фото>\n"
prompt = f"{prompt}\n{user_text}" prompt = f"{prompt}\n{user_text}"
if replied_text: if replied_text:
@@ -169,20 +180,25 @@ async def guest_middleware(handler, event, data):
), ),
) )
) )
except Exception: except Exception as e:
await data["bot"]( try:
AnswerGuestQuery( await data["bot"](
guest_query_id=message.guest_query_id, AnswerGuestQuery(
result=InlineQueryResultArticle( guest_query_id=message.guest_query_id,
id="1", result=InlineQueryResultArticle(
title="ok", id="1",
input_message_content=InputTextMessageContent( title="ok",
message_text=result, input_message_content=InputTextMessageContent(
parse_mode="None" 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 return
+5 -1
View File
@@ -149,7 +149,11 @@ async def generate(
user_contexts[user_id] = [] user_contexts[user_id] = []
config = get_user_config(user_id) config = get_user_config(user_id)
model = config.get("model").split("*", 2) if "*" in config.get("model", ""):
model = config.get("model").split("*", 2)
else:
print(f"{RED} -- err model - failed to get prov&model in \"{config.get('model','')}\"{RESET}")
return "произошла ошибка при парсинге вашей выбранной модели. либо хост бота гандон либо тебе надо сменить модель в настройках!!"
stream_cf = config["stream"] stream_cf = config["stream"]
if stream_cf == "native" and user_id == chat_id: if stream_cf == "native" and user_id == chat_id: