This commit is contained in:
2023-10-20 19:22:08 +02:00
parent c858e62a81
commit f35fff4f6a
+2 -3
View File
@@ -335,7 +335,7 @@ async def on_message(message):
# *=========================================== Define Functions
def num_tokens_from_string(string, model):
def num_tokens_from_string(message, model):
"""
The function `num_tokens_from_string` returns the number of tokens in a given string.
@@ -347,10 +347,9 @@ def num_tokens_from_string(string, model):
tokens_per_name = 1
chat_gpt_encoding = tiktoken.encoding_for_model(model)
num_tokens = len(chat_gpt_encoding.encode(string))
num_tokens = 0
num_tokens += tokens_per_message
for keys, values in string.items():
for keys, values in message.items():
num_tokens += len(chat_gpt_encoding.encode(values))
if keys == "role":
num_tokens += tokens_per_name