From 65bf724a0b0e64fb9c6ae396413daa2684112164 Mon Sep 17 00:00:00 2001 From: Kumi Date: Sun, 19 Nov 2023 16:06:59 +0100 Subject: [PATCH] feat: Add method to check if room uses assistant This commit adds a new method `room_uses_assistant` to the OpenAI class. This method allows checking whether a given room uses an assistant. It uses the `room_settings` table in the database to determine if the specified room has the `openai_assistant` setting. --- src/gptbot/classes/openai.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/gptbot/classes/openai.py b/src/gptbot/classes/openai.py index 8a1603d..c46dd28 100644 --- a/src/gptbot/classes/openai.py +++ b/src/gptbot/classes/openai.py @@ -138,6 +138,22 @@ class OpenAI: user=user ) + async def room_uses_assistant(self, room: str) -> bool: + """Returns whether a room uses an assistant. + + Args: + room (str): The room to check. + + Returns: + bool: Whether the room uses an assistant. + """ + + with closing(self.bot.database.cursor()) as cursor: + cursor.execute("SELECT value FROM room_settings WHERE room_id = ? AND setting = ?", (room, "openai_assistant")) + result = cursor.fetchone() + + return result is not None + async def generate_chat_response(self, messages: List[Dict[str, str]], user: Optional[str] = None, room: Optional[str] = None) -> Tuple[str, int]: """Generate a response to a chat message.