core, openai: support custom token encoders (#20762)

This commit is contained in:
ccurme
2024-04-23 09:57:05 -04:00
committed by GitHub
parent b481b73805
commit 7a922f3e48
4 changed files with 21 additions and 1 deletions

View File

@@ -521,6 +521,8 @@ class BaseOpenAI(BaseLLM):
def get_token_ids(self, text: str) -> List[int]:
"""Get the token IDs using the tiktoken package."""
if self.custom_get_token_ids is not None:
return self.custom_get_token_ids(text)
# tiktoken NOT supported for Python < 3.8
if sys.version_info[1] < 8:
return super().get_num_tokens(text)