A temporary measure to account for user error in #1437.
Will have to look into bug in:
def get_token_count(self, convo_id: str = "default") -> int:
"""
Get token count
"""
if self.engine not in ENGINES:
raise NotImplementedError(f"Unsupported engine {self.engine}")
tiktoken.model.MODEL_TO_ENCODING["gpt-4"] = "cl100k_base"
encoding = tiktoken.encoding_for_model(self.engine)
num_tokens = 0
for message in self.conversation[convo_id]:
# every message follows <im_start>{role/name}\n{content}<im_end>\n
num_tokens += 5
for key, value in message.items():
num_tokens += len(encoding.encode(value))
if key == "name": # if there's a name, the role is omitted
num_tokens += 5 # role is always required and always 1 token
num_tokens += 5 # every reply is primed with <im_start>assistant
return num_tokens
A temporary measure to account for user error in #1437.
Will have to look into bug in: