From 84bf541108468502b0c92b2767d1417edb8fa8f6 Mon Sep 17 00:00:00 2001 From: Cyberes Date: Mon, 8 Apr 2024 00:11:19 -0600 Subject: [PATCH] fix system prompts and logging --- matrix_gpt/callbacks.py | 3 +-- matrix_gpt/chat_functions.py | 2 +- matrix_gpt/generate.py | 19 ++----------------- 3 files changed, 4 insertions(+), 20 deletions(-) diff --git a/matrix_gpt/callbacks.py b/matrix_gpt/callbacks.py index 3d2e7b0..9d6a283 100644 --- a/matrix_gpt/callbacks.py +++ b/matrix_gpt/callbacks.py @@ -10,14 +10,13 @@ from .config import global_config from .handle_actions import do_reply_msg, do_reply_threaded_msg, do_join_channel, sound_off from .matrix import MatrixClientHelper -logger = logging.getLogger('MatrixGPT') class MatrixBotCallbacks: def __init__(self, client: MatrixClientHelper): self.client_helper = client self.client: AsyncClient = client.client - self.logger = logging.getLogger('ExportBot').getChild('MatrixBotCallbacks') + self.logger = logging.getLogger('MatrixGPT').getChild('MatrixBotCallbacks') self.startup_ts = time.time() * 1000 async def handle_message(self, room: MatrixRoom, requestor_event: RoomMessageText) -> None: diff --git a/matrix_gpt/chat_functions.py b/matrix_gpt/chat_functions.py index 6a355a1..e2c0ace 100644 --- a/matrix_gpt/chat_functions.py +++ b/matrix_gpt/chat_functions.py @@ -6,7 +6,7 @@ from nio import AsyncClient, Event, MatrixRoom, RoomGetEventResponse, RoomMessag from matrix_gpt.config import global_config from matrix_gpt.generate_clients.command_info import CommandInfo -logger = logging.getLogger('ChatFunctions') +logger = logging.getLogger('MatrixGPT').getChild('ChatFunctions') def is_thread(event: RoomMessageText): diff --git a/matrix_gpt/generate.py b/matrix_gpt/generate.py index 12f8181..e7f95ce 100644 --- a/matrix_gpt/generate.py +++ b/matrix_gpt/generate.py @@ -10,27 +10,12 @@ from matrix_gpt.api_client_manager import api_client_helper from matrix_gpt.config import global_config from matrix_gpt.generate_clients.command_info import CommandInfo -logger = logging.getLogger('ProcessChat') +logger = logging.getLogger('MatrixGPT').getChild('Generate') # TODO: process_chat() will set typing as false after generating. # TODO: If there is still another query in-progress that typing state will be overwritten by the one that just finished. -def assemble_messages(messages: list, mode: str): - if mode == 'openai': - - system_prompt = global_config['openai'].get('system_prompt', '') - injected_system_prompt = global_config['openai'].get('injected_system_prompt', '') - elif mode == 'anth': - human_role = 'user' - bot_role = 'assistant' - system_prompt = global_config['anthropic'].get('system_prompt', '') - injected_system_prompt = global_config['anthropic'].get('injected_system_prompt', '') - else: - raise Exception - - return messages - async def generate_ai_response( client_helper: MatrixClientHelper, @@ -46,7 +31,7 @@ async def generate_ai_response( await client.room_typing(room.room_id, typing_state=True, timeout=global_config['response_timeout'] * 1000) api_client = api_client_helper.get_client(command_info.api_type) - messages = api_client.assemble_context(msg) + messages = api_client.assemble_context(msg, system_prompt=command_info.system_prompt, injected_system_prompt=command_info.injected_system_prompt) response = None try: