more error handling + photos in reply in guest
This commit is contained in:
1 parent
b027361586
commit
a60caf5dba
2 files changed
+22
-2
No files matched your search
@@ -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,7 +180,8 @@ async def guest_middleware(handler, event, data):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
try:
|
||||||
await data["bot"](
|
await data["bot"](
|
||||||
AnswerGuestQuery(
|
AnswerGuestQuery(
|
||||||
guest_query_id=message.guest_query_id,
|
guest_query_id=message.guest_query_id,
|
||||||
@@ -183,6 +195,10 @@ async def guest_middleware(handler, event, data):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"{RED} -- send guest - {e}{RESET}")
|
||||||
|
else:
|
||||||
|
print(f"{YELLOW} -- markdown - {e}{RESET}")
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
|
if "*" in config.get("model", ""):
|
||||||
model = config.get("model").split("*", 2)
|
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:
|
||||||
|
|||||||
Reference in new issue
Block a user