fix system prompt
This commit is contained in:
parent
db011cc992
commit
a5cabe767d
9
main.py
9
main.py
|
@ -67,7 +67,7 @@ def retry(msg=None):
|
|||
|
||||
async def main():
|
||||
# Logging in with a new device each time seems to fix encryption errors
|
||||
device_id = str(uuid4())
|
||||
device_id = config_data['bot_auth'].get('device_id', str(uuid4()))
|
||||
|
||||
matrix_helper = MatrixNioGPTHelper(
|
||||
auth_file=Path(config_data['bot_auth']['store_path'], 'bot_auth.json'),
|
||||
|
@ -75,7 +75,7 @@ async def main():
|
|||
passwd=config_data['bot_auth']['password'],
|
||||
homeserver=config_data['bot_auth']['homeserver'],
|
||||
store_path=config_data['bot_auth']['store_path'],
|
||||
device_id=device_id # config_data['bot_auth'].get('device_id')
|
||||
device_id=device_id,
|
||||
)
|
||||
client = matrix_helper.client
|
||||
|
||||
|
@ -115,7 +115,7 @@ async def main():
|
|||
return False
|
||||
|
||||
# Login succeeded!
|
||||
logger.info(f"Logged in as {client.user_id}")
|
||||
logger.info(f"Logged in as {client.user_id} using device {device_id}.")
|
||||
if config_data.get('autojoin_rooms'):
|
||||
for room in config_data.get('autojoin_rooms'):
|
||||
r = await client.join(room)
|
||||
|
@ -124,8 +124,9 @@ async def main():
|
|||
time.sleep(1.5)
|
||||
|
||||
# Log out old devices to keep the session clean
|
||||
devices = (await client.devices()).devices
|
||||
devices = list((await client.devices()).devices)
|
||||
device_list = [x.id for x in devices]
|
||||
if device_id in device_list:
|
||||
device_list.remove(device_id)
|
||||
x = await client.delete_devices(device_list, {
|
||||
"type": "m.login.password",
|
||||
|
|
|
@ -84,10 +84,9 @@ class Callbacks:
|
|||
await process_chat(self.client, room, event, api_data, self.store, self.openai, thread_root_id=thread_content[0].event_id, system_prompt=self.system_prompt)
|
||||
return
|
||||
elif msg.startswith(f'{self.command_prefix} ') or room.member_count == 2:
|
||||
# Otherwise if this is in a 1-1 with the bot or features a command prefix,
|
||||
# treat it as a command
|
||||
# Otherwise if this is in a 1-1 with the bot or features a command prefix, treat it as a command.
|
||||
msg = event.body if not event.body.startswith(self.command_prefix) else event.body[len(self.command_prefix):].strip() # Remove the command prefix
|
||||
command = Command(self.client, self.store, msg, room, event, self.openai, self.reply_in_thread)
|
||||
command = Command(self.client, self.store, msg, room, event, self.openai, self.reply_in_thread, system_prompt=self.system_prompt)
|
||||
await command.process()
|
||||
|
||||
async def invite(self, room: MatrixRoom, event: InviteMemberEvent) -> None:
|
||||
|
@ -190,10 +189,8 @@ class Callbacks:
|
|||
# f"it (your reminders will NOT be deleted, but the bot may respond to existing "
|
||||
# f"commands a second time).")
|
||||
|
||||
red_x_and_lock_emoji = "❌ 🔐"
|
||||
|
||||
# React to the undecryptable event with some emoji
|
||||
await react_to_event(self.client, room.room_id, event.event_id, red_x_and_lock_emoji, )
|
||||
if event.server_timestamp > self.startup_ts:
|
||||
await react_to_event(self.client, room.room_id, event.event_id, "❌ 🔐")
|
||||
|
||||
async def unknown(self, room: MatrixRoom, event: UnknownEvent) -> None:
|
||||
"""Callback for when an event with a type that is unknown to matrix-nio is received.
|
||||
|
|
|
@ -205,7 +205,6 @@ async def process_chat(client, room, event, command, store, openai, thread_root_
|
|||
messages=messages,
|
||||
temperature=0,
|
||||
)
|
||||
logger.debug(response)
|
||||
text_response = response["choices"][0]["message"]["content"].strip().strip('\n')
|
||||
logger.info(f'Reply to {event.event_id} --> "{command}" and bot responded with "{text_response}"')
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue