aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhuker667 <huker@tuta.io>2026-05-22 20:04:26 +0300
committerhuker667 <huker@tuta.io>2026-05-22 20:04:26 +0300
commita60caf5dbab7399d472e254879f9742b3c26d180 (patch)
treea6918778bf97fa992eb4938eb6e1dcdd0285cf1b
parentb027361586f776292260afff871c85b05359cf3d (diff)
downloaduzbekgpt-a60caf5dbab7399d472e254879f9742b3c26d180.tar.gz
uzbekgpt-a60caf5dbab7399d472e254879f9742b3c26d180.tar.bz2
uzbekgpt-a60caf5dbab7399d472e254879f9742b3c26d180.zip
more error handling + photos in reply in guest
-rw-r--r--main.py42
-rw-r--r--supergenerator.py6
2 files changed, 34 insertions, 14 deletions
diff --git a/main.py b/main.py
index 12c29a9..0ac3886 100644
--- a/main.py
+++ b/main.py
@@ -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
diff --git a/supergenerator.py b/supergenerator.py
index ef1ddeb..4b5dbf9 100644
--- a/supergenerator.py
+++ b/supergenerator.py
@@ -149,7 +149,11 @@ async def generate(
user_contexts[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"]
if stream_cf == "native" and user_id == chat_id: