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.
This commit is contained in:
Kumi 2023-11-19 16:06:59 +01:00
parent 54f56c1b1a
commit 65bf724a0b
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -138,6 +138,22 @@ class OpenAI:
user=user 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]: 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. """Generate a response to a chat message.