faster logging

This commit is contained in:
Cyberes 2023-03-22 16:44:17 -06:00
parent 7bfc02ebbd
commit 9139edcb60
2 changed files with 14 additions and 9 deletions

View File

@ -110,7 +110,8 @@ async def main():
log_full_response=config_data['logging'].get('log_full_response', False), log_full_response=config_data['logging'].get('log_full_response', False),
system_prompt=config_data['openai'].get('system_prompt'), system_prompt=config_data['openai'].get('system_prompt'),
injected_system_prompt=config_data['openai'].get('injected_system_prompt', False), 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.message, RoomMessageText)
client.add_event_callback(callbacks.invite_event_filtered_callback, InviteMemberEvent) client.add_event_callback(callbacks.invite_event_filtered_callback, InviteMemberEvent)

View File

@ -28,7 +28,8 @@ class Callbacks:
system_prompt: str = None, system_prompt: str = None,
log_full_response: bool = False, log_full_response: bool = False,
injected_system_prompt: str = False, injected_system_prompt: str = False,
openai_temperature: float = 0 openai_temperature: float = 0,
log_level=logging.INFO
): ):
""" """
Args: Args:
@ -52,6 +53,7 @@ class Callbacks:
self.injected_system_prompt = injected_system_prompt self.injected_system_prompt = injected_system_prompt
self.openai_obj = openai_obj self.openai_obj = openai_obj
self.openai_temperature = openai_temperature self.openai_temperature = openai_temperature
self.log_level = log_level
async def message(self, room: MatrixRoom, event: RoomMessageText) -> None: async def message(self, room: MatrixRoom, event: RoomMessageText) -> None:
"""Callback for when a message event is received """Callback for when a message event is received
@ -150,14 +152,16 @@ class Callbacks:
) )
await command.process() await command.process()
else: else:
debug = { if self.log_level == logging.DEBUG:
'command_prefix': msg.startswith(f'{self.command_prefix} '), # This may be a little slow
'is_dm': room.member_count == 2, debug = {
'is_thread': is_thread(event), 'command_prefix': msg.startswith(f'{self.command_prefix} '),
'is_our_thread': await is_this_our_thread(self.client, room, event, 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: async def invite(self, room: MatrixRoom, event: InviteMemberEvent) -> None:
"""Callback for when an invite is received. Join the room specified in the invite. """Callback for when an invite is received. Join the room specified in the invite.