From 31d8e415ea0978276e4b49a2ddbd06521c96cd68 Mon Sep 17 00:00:00 2001 From: Cyberes Date: Sat, 18 Mar 2023 15:04:12 -0600 Subject: [PATCH] fix logging --- config.sample.yaml | 24 ++++++++++++------------ matrix_gpt/bot/callbacks.py | 2 +- matrix_gpt/bot/chat_functions.py | 16 ++++++++-------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/config.sample.yaml b/config.sample.yaml index 6df01d5..0bb8137 100644 --- a/config.sample.yaml +++ b/config.sample.yaml @@ -1,20 +1,20 @@ # Make sure to quote any string with @ or ! characters. -data_storage: bot-store +data_storage: bot-store bot_auth: - username: chatgpt - password: password1234 - homeserver: matrix.example.com - store_path: 'bot-store/' - device_id: ABCDEFGHIJ + username: chatgpt + password: password1234 + homeserver: matrix.example.com + store_path: 'bot-store/' + device_id: ABCDEFGHIJ -openai_api_key: sk-J12J3O12U3J1LK2J310283JIJ1L2K3J -openai_model: gpt-3.5-turbo +openai_api_key: sk-J12J3O12U3J1LK2J310283JIJ1L2K3J +openai_model: gpt-3.5-turbo # Who is the bot allowed to respond to? # Possible values: "all", an array of usernames, or an array homeservers. -allowed_to_chat: all +allowed_to_chat: all # Who can invite the bot? Also applies to DM creation. # Possible values: "all", an array of usernames, or an array homeservers. @@ -31,15 +31,15 @@ autojoin_rooms: # Should the bot set its avatar on login? #set_avatar: true -command_prefix: '!c' +command_prefix: '!c' -reply_in_thread: true +reply_in_thread: true # The system message helps set the behavior of the assistant. # For example, you can instruct the assistant with "You are a helpful assistant." #system_prompt: -# Log the full response (prompt + response). +# Log the full response (prompt + response) at debug level. log_full_response: false logout_other_devices: false \ No newline at end of file diff --git a/matrix_gpt/bot/callbacks.py b/matrix_gpt/bot/callbacks.py index fe21794..b528dcc 100644 --- a/matrix_gpt/bot/callbacks.py +++ b/matrix_gpt/bot/callbacks.py @@ -13,7 +13,7 @@ logger = logging.getLogger('MatrixGPT') class Callbacks: - def __init__(self, client: AsyncClient, store: Storage, command_prefix: str, openai, reply_in_thread, allowed_to_invite, allowed_to_chat='all', system_prompt: str = None, log_full_response:bool=False): + def __init__(self, client: AsyncClient, store: Storage, command_prefix: str, openai, reply_in_thread, allowed_to_invite, allowed_to_chat='all', system_prompt: str = None, log_full_response: bool = False): """ Args: client: nio client used to interact with matrix. diff --git a/matrix_gpt/bot/chat_functions.py b/matrix_gpt/bot/chat_functions.py index 3c24f48..0d868bd 100644 --- a/matrix_gpt/bot/chat_functions.py +++ b/matrix_gpt/bot/chat_functions.py @@ -198,7 +198,6 @@ async def process_chat(client, room, event, command, store, openai, thread_root_ ] if system_prompt: messages.insert(0, {"role": "system", "content": system_prompt}, ) - print(messages) response = openai['openai'].ChatCompletion.create( model=openai['model'], @@ -206,15 +205,16 @@ async def process_chat(client, room, event, command, store, openai, thread_root_ temperature=0, ) text_response = response["choices"][0]["message"]["content"].strip().strip('\n') - z = text_response.replace("\n", "\\n") + if log_full_response: - if isinstance(command, str): - x = command.replace("\n", "\\n") - else: - x = command - logger.info(f'Reply to {event.event_id} --> "{x}" and bot responded with "{z}"') + logger.debug({'event_id': event.event_id, 'room': room.room_id, 'messages': messages, 'response': text_response}) + z = text_response.replace("\n", "\\n") + if isinstance(command, str): + x = command.replace("\n", "\\n") else: - logger.info(f'Reply to {event.event_id} --> "{z}"') + x = command + logger.info(f'Reply to {event.event_id} --> "{x}" and bot responded with "{z}"') + 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) store.add_event_id(event.event_id)