more error handling + photos in reply in guest
This commit is contained in:
1 parent
b027361586
commit
a60caf5dba
2 files changed
+34
-14
No files matched your search
@@ -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
|
||||
|
||||
|
||||
+5
-1
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user