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

@ -1,20 +1,20 @@
# Make sure to quote any string with @ or ! characters. # Make sure to quote any string with @ or ! characters.
data_storage: bot-store data_storage: bot-store
bot_auth: bot_auth:
username: chatgpt username: chatgpt
password: password1234 password: password1234
homeserver: matrix.example.com homeserver: matrix.example.com
store_path: 'bot-store/' store_path: 'bot-store/'
device_id: ABCDEFGHIJ device_id: ABCDEFGHIJ
openai_api_key: sk-J12J3O12U3J1LK2J310283JIJ1L2K3J openai_api_key: sk-J12J3O12U3J1LK2J310283JIJ1L2K3J
openai_model: gpt-3.5-turbo openai_model: gpt-3.5-turbo
# Who is the bot allowed to respond to? # Who is the bot allowed to respond to?
# Possible values: "all", an array of usernames, or an array homeservers. # 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. # Who can invite the bot? Also applies to DM creation.
# Possible values: "all", an array of usernames, or an array homeservers. # 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? # Should the bot set its avatar on login?
#set_avatar: true #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. # The system message helps set the behavior of the assistant.
# 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:
if isinstance(command, str): logger.debug({'event_id': event.event_id, 'room': room.room_id, 'messages': messages, 'response': text_response})
x = command.replace("\n", "\\n") z = text_response.replace("\n", "\\n")
else: if isinstance(command, str):
x = command x = command.replace("\n", "\\n")
logger.info(f'Reply to {event.event_id} --> "{x}" and bot responded with "{z}"')
else: 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) 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)