added current conversation stats to /stats

This commit is contained in:
Carl Sverre
2023-03-21 09:43:51 -07:00
parent 792d9c2432
commit 5e9dd9a846
2 changed files with 19 additions and 2 deletions

View File

@@ -28,6 +28,16 @@ class OpenAIHelper:
self.conversations: dict[int: list] = {} # {chat_id: history}
self.last_updated: dict[int: datetime] = {} # {chat_id: last_update_timestamp}
def get_conversation_stats(self, chat_id: int) -> tuple[int, int]:
"""
Gets the number of messages and tokens used in the conversation.
:param chat_id: The chat ID
:return: A tuple containing the number of messages and tokens used
"""
if chat_id not in self.conversations:
self.reset_chat_history(chat_id)
return (len(self.conversations[chat_id]), self.__count_tokens(self.conversations[chat_id]))
async def get_chat_response(self, chat_id: int, query: str) -> Union[tuple[str, str], str]:
"""
Gets a response from the GPT-3 model.