fix logging

This commit is contained in:
Cyberes 2023-03-18 15:04:12 -06:00
parent f5ad27d434
commit 31d8e415ea
3 changed files with 21 additions and 21 deletions

View File

@ -39,7 +39,7 @@ reply_in_thread: true
# For example, you can instruct the assistant with "You are a helpful assistant." # For example, you can instruct the assistant with "You are a helpful assistant."
#system_prompt: #system_prompt:
# Log the full response (prompt + response). # Log the full response (prompt + response) at debug level.
log_full_response: false log_full_response: false
logout_other_devices: false logout_other_devices: false

View File

@ -13,7 +13,7 @@ logger = logging.getLogger('MatrixGPT')
class Callbacks: 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: Args:
client: nio client used to interact with matrix. client: nio client used to interact with matrix.

View File

@ -198,7 +198,6 @@ async def process_chat(client, room, event, command, store, openai, thread_root_
] ]
if system_prompt: if system_prompt:
messages.insert(0, {"role": "system", "content": system_prompt}, ) messages.insert(0, {"role": "system", "content": system_prompt}, )
print(messages)
response = openai['openai'].ChatCompletion.create( response = openai['openai'].ChatCompletion.create(
model=openai['model'], model=openai['model'],
@ -206,15 +205,16 @@ async def process_chat(client, room, event, command, store, openai, thread_root_
temperature=0, temperature=0,
) )
text_response = response["choices"][0]["message"]["content"].strip().strip('\n') text_response = response["choices"][0]["message"]["content"].strip().strip('\n')
z = text_response.replace("\n", "\\n")
if log_full_response: if log_full_response:
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): if isinstance(command, str):
x = command.replace("\n", "\\n") x = command.replace("\n", "\\n")
else: else:
x = command x = command
logger.info(f'Reply to {event.event_id} --> "{x}" and bot responded with "{z}"') logger.info(f'Reply to {event.event_id} --> "{x}" and bot responded with "{z}"')
else:
logger.info(f'Reply to {event.event_id} --> "{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) 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) await client.room_typing(room.room_id, typing_state=False, timeout=3000)
store.add_event_id(event.event_id) store.add_event_id(event.event_id)