fix routing to tiktoken encoder (#866)

makefile-update-1
Harrison Chase 1 year ago committed by GitHub
parent e9ef08862d
commit 777aaff841
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -277,8 +277,13 @@ class BaseOpenAI(BaseLLM, BaseModel):
"This is needed in order to calculate get_num_tokens. "
"Please it install it with `pip install tiktoken`."
)
encoder = "gpt2"
if self.model_name in ("text-davinci-003", "text-davinci-002"):
encoder = "p50k_base"
if self.model_name.startswith("code"):
encoder = "p50k_base"
# create a GPT-3 encoder instance
enc = tiktoken.get_encoding("gpt2")
enc = tiktoken.get_encoding(encoder)
# encode the text using the GPT-3 encoder
tokenized_text = enc.encode(text)

Loading…
Cancel
Save