fix logging
This commit is contained in:
parent
f5ad27d434
commit
31d8e415ea
|
@ -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
|
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue