File tree 2 files changed +25
-0
lines changed
langchain_openai/chat_models
tests/unit_tests/chat_models
2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -1298,6 +1298,12 @@ def get_num_tokens_from_messages(
1298
1298
encoding .encode (val ["function" ]["arguments" ])
1299
1299
)
1300
1300
num_tokens += len (encoding .encode (val ["function" ]["name" ]))
1301
+ elif val ["type" ] == "file" :
1302
+ warnings .warn (
1303
+ "Token counts for file inputs are not supported. "
1304
+ "Ignoring file inputs."
1305
+ )
1306
+ pass
1301
1307
else :
1302
1308
raise ValueError (
1303
1309
f"Unrecognized content block type\n \n { val } "
Original file line number Diff line number Diff line change @@ -752,6 +752,25 @@ def test_get_num_tokens_from_messages() -> None:
752
752
actual = llm .get_num_tokens_from_messages (messages )
753
753
assert expected == actual
754
754
755
+ # Test file inputs
756
+ messages = [
757
+ HumanMessage (
758
+ [
759
+ "Summarize this document." ,
760
+ {
761
+ "type" : "file" ,
762
+ "file" : {
763
+ "filename" : "my file" ,
764
+ "file_data" : "data:application/pdf;base64,<data>" ,
765
+ },
766
+ },
767
+ ]
768
+ )
769
+ ]
770
+ with pytest .warns (match = "file inputs are not supported" ):
771
+ actual = llm .get_num_tokens_from_messages (messages )
772
+ assert actual == 13
773
+
755
774
756
775
class Foo (BaseModel ):
757
776
bar : int
You can’t perform that action at this time.
0 commit comments