mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-07 22:11:51 +00:00
openai[patch]: ignore file blocks when counting tokens (#30601)
OpenAI does not appear to document how it transforms PDF pages to images, which determines how tokens are counted: https://platform.openai.com/docs/guides/pdf-files?api-mode=chat#usage-considerations Currently these block types raise ValueError inside `get_num_tokens_from_messages`. Here we update to generate a warning and continue.
This commit is contained in:
@@ -1298,6 +1298,12 @@ class BaseChatOpenAI(BaseChatModel):
|
||||
encoding.encode(val["function"]["arguments"])
|
||||
)
|
||||
num_tokens += len(encoding.encode(val["function"]["name"]))
|
||||
elif val["type"] == "file":
|
||||
warnings.warn(
|
||||
"Token counts for file inputs are not supported. "
|
||||
"Ignoring file inputs."
|
||||
)
|
||||
pass
|
||||
else:
|
||||
raise ValueError(
|
||||
f"Unrecognized content block type\n\n{val}"
|
||||
|
Reference in New Issue
Block a user