added tokens() function to Message and Chat

This commit is contained in:
2023-09-01 08:57:54 +02:00
parent 93290da5b5
commit 7f612bfc17
2 changed files with 19 additions and 0 deletions
+7
View File
@@ -129,6 +129,13 @@ class Chat:
tags |= m.filter_tags(prefix, contain)
return tags
def tokens(self) -> int:
"""
Returns the nr. of AI language tokens used by all messages in this chat.
If unknown, 0 is returned.
"""
return sum(m.tokens() for m in self.messages)
def print(self, dump: bool = False, source_code_only: bool = False,
with_tags: bool = False, with_file: bool = False,
paged: bool = True) -> None: