From 96a83fd8242c69fa8b4912ca17deb18d1064d27d Mon Sep 17 00:00:00 2001 From: hibobmaster <32976627+hibobmaster@users.noreply.github.com> Date: Sat, 23 Dec 2023 21:16:37 +0800 Subject: [PATCH] Fallback to gpt-3.5-turbo when caculate tokens using custom model --- src/gptbot.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gptbot.py b/src/gptbot.py index 454e0a1..31e9c72 100644 --- a/src/gptbot.py +++ b/src/gptbot.py @@ -122,13 +122,13 @@ class Chatbot: """ Get token count """ + _engine = self.engine if self.engine not in ENGINES: - raise NotImplementedError( - f"Engine {self.engine} is not supported. Select from {ENGINES}", - ) + # use gpt-3.5-turbo to caculate token + _engine = "gpt-3.5-turbo" tiktoken.model.MODEL_TO_ENCODING["gpt-4"] = "cl100k_base" - encoding = tiktoken.encoding_for_model(self.engine) + encoding = tiktoken.encoding_for_model(_engine) num_tokens = 0 for message in self.conversation[convo_id]: