diff --git a/main.py b/main.py index 80f08fe..ec5877d 100755 --- a/main.py +++ b/main.py @@ -110,7 +110,8 @@ async def main(): log_full_response=config_data['logging'].get('log_full_response', False), system_prompt=config_data['openai'].get('system_prompt'), injected_system_prompt=config_data['openai'].get('injected_system_prompt', False), - openai_temperature=config_data['openai'].get('temperature', 0) + openai_temperature=config_data['openai'].get('temperature', 0), + log_level=log_level ) client.add_event_callback(callbacks.message, RoomMessageText) client.add_event_callback(callbacks.invite_event_filtered_callback, InviteMemberEvent) diff --git a/matrix_gpt/bot/callbacks.py b/matrix_gpt/bot/callbacks.py index c7914ba..01323db 100644 --- a/matrix_gpt/bot/callbacks.py +++ b/matrix_gpt/bot/callbacks.py @@ -28,7 +28,8 @@ class Callbacks: system_prompt: str = None, log_full_response: bool = False, injected_system_prompt: str = False, - openai_temperature: float = 0 + openai_temperature: float = 0, + log_level=logging.INFO ): """ Args: @@ -52,6 +53,7 @@ class Callbacks: self.injected_system_prompt = injected_system_prompt self.openai_obj = openai_obj self.openai_temperature = openai_temperature + self.log_level = log_level async def message(self, room: MatrixRoom, event: RoomMessageText) -> None: """Callback for when a message event is received @@ -150,14 +152,16 @@ class Callbacks: ) await command.process() else: - debug = { - 'command_prefix': msg.startswith(f'{self.command_prefix} '), - 'is_dm': room.member_count == 2, - 'is_thread': is_thread(event), - 'is_our_thread': await is_this_our_thread(self.client, room, event, self.command_prefix) + if self.log_level == logging.DEBUG: + # This may be a little slow + debug = { + 'command_prefix': msg.startswith(f'{self.command_prefix} '), + 'is_dm': room.member_count == 2, + 'is_thread': is_thread(event), + 'is_our_thread': await is_this_our_thread(self.client, room, event, self.command_prefix) - } - logger.debug(f"Bot not reacting to event {event.event_id}: {json.dumps(debug)}") + } + logger.debug(f"Bot not reacting to event {event.event_id}: {json.dumps(debug)}") async def invite(self, room: MatrixRoom, event: InviteMemberEvent) -> None: """Callback for when an invite is received. Join the room specified in the invite.