feat: adds support to automatically fallback to the default encoding (#596)

* feat: adds support to automatically fallbackk to the default encoding

* fix: use the correct method
This commit is contained in:
Ayo Ayibiowu
2024-05-10 16:54:45 +02:00
committed by GitHub
parent f0c9e80d33
commit dedaafd863

View File

@@ -42,9 +42,9 @@ class TokenCalcHandler(BaseCallbackHandler):
def on_llm_start(
self, serialized: Dict[str, Any], prompts: List[str], **kwargs: Any
) -> None:
if "gpt" in self.model:
try:
encoding = tiktoken.encoding_for_model(self.model)
else:
except KeyError:
encoding = tiktoken.get_encoding("cl100k_base")
if self.token_cost_process is None: