mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-08 12:31:49 +00:00
[OpenAI]: Encoding Model (#31402)
- **Description:** Small Fix for when getting the encoder in case of KeyError and using the correct encoder for newer models - **Issue:** #31390
This commit is contained in:
parent
40bd71caa5
commit
42eb356a44
@ -1259,8 +1259,12 @@ class BaseChatOpenAI(BaseChatModel):
|
||||
try:
|
||||
encoding = tiktoken.encoding_for_model(model)
|
||||
except KeyError:
|
||||
model = "cl100k_base"
|
||||
encoding = tiktoken.get_encoding(model)
|
||||
encoder = "cl100k_base"
|
||||
if self.model_name.startswith("gpt-4o") or self.model_name.startswith(
|
||||
"gpt-4.1"
|
||||
):
|
||||
encoder = "o200k_base"
|
||||
encoding = tiktoken.get_encoding(encoder)
|
||||
return model, encoding
|
||||
|
||||
def get_token_ids(self, text: str) -> list[int]:
|
||||
|
Loading…
Reference in New Issue
Block a user