From 98805b18786af5bbdc01e4aa56f658417f66f9bc Mon Sep 17 00:00:00 2001 From: Cyberes Date: Sun, 19 Mar 2023 19:46:07 -0600 Subject: [PATCH] t --- matrix_gpt/bot/chat_functions.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/matrix_gpt/bot/chat_functions.py b/matrix_gpt/bot/chat_functions.py index 965b9fa..6cdf817 100644 --- a/matrix_gpt/bot/chat_functions.py +++ b/matrix_gpt/bot/chat_functions.py @@ -2,7 +2,6 @@ import asyncio import functools import logging import time -import traceback from types import ModuleType from typing import List, Optional, Union @@ -183,7 +182,7 @@ async def process_chat( return await loop.run_in_executor(None, functools.partial(openai_obj.ChatCompletion.create, model=openai_model, messages=messages, temperature=openai_temperature, timeout=20)) # r = openai_obj.ChatCompletion.create(model=openai_model, messages=messages, temperature=openai_temperature, timeout=20) - text_response = response = None + response = None for i in range(openai_retries): try: task = asyncio.create_task(generate(timeout=20)) @@ -192,17 +191,14 @@ async def process_chat( if response is not None: break except Exception as e: # (stopit.utils.TimeoutException, openai.error.APIConnectionError) - logger.warning(f'Got exception when trying to reply to event {event.event_id}, retrying: {e}') + logger.warning(f'Got exception when generating response to event {event.event_id}, retrying: {e}') await client.room_typing(room.room_id, typing_state=True, timeout=15000) time.sleep(2) continue - except Exception as e: - logger.critical(f'OpenAI API error: {e}\n{traceback.format_exc()}') - await react_to_event(client, room.room_id, event.event_id, '❌') - return if response is None: - logger.critical(f'OpenAI API timeout for event {event.event_id} in room {room.room_id}.') + logger.critical(f'Could not generate response to event {event.event_id} in room {room.room_id}.') + await client.room_typing(room.room_id, typing_state=False, timeout=15000) await react_to_event(client, room.room_id, event.event_id, '❌') return text_response = response["choices"][0]["message"]["content"].strip().strip('\n') @@ -222,6 +218,8 @@ async def process_chat( resp = await send_text_to_room(client, room.room_id, text_response, reply_to_event_id=event.event_id, thread=True, thread_root_id=thread_root_id if thread_root_id else event.event_id) await client.room_typing(room.room_id, typing_state=False, timeout=3000) + print(thread_root_id) + store.add_event_id(event.event_id) if not isinstance(resp, RoomSendResponse): logger.critical(f'Failed to respond to event {event.event_id} in room {room.room_id}:\n{vars(resp)}')