From f6297ced67ff235e95e58a5cb1bc3cfcd60d2765 Mon Sep 17 00:00:00 2001 From: Saurav Sapkota Date: Sat, 20 Dec 2025 01:47:40 +0530 Subject: [PATCH] fix(openai): handle function_call content in token counting (#34379) --- .../tests/unit_tests/chat_models/test_base.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/libs/partners/openai/tests/unit_tests/chat_models/test_base.py b/libs/partners/openai/tests/unit_tests/chat_models/test_base.py index e59874bf7bc..0f7fad73c99 100644 --- a/libs/partners/openai/tests/unit_tests/chat_models/test_base.py +++ b/libs/partners/openai/tests/unit_tests/chat_models/test_base.py @@ -1001,6 +1001,32 @@ def test_get_num_tokens_from_messages() -> None: actual = llm.get_num_tokens_from_messages(messages) assert actual == 13 + # Test Responses + messages = [ + AIMessage( + [ + { + "type": "function_call", + "name": "multiply", + "arguments": '{"x":5,"y":4}', + "call_id": "call_abc123", + "id": "fc_abc123", + "status": "completed", + }, + ], + tool_calls=[ + { + "type": "tool_call", + "name": "multiply", + "args": {"x": 5, "y": 4}, + "id": "call_abc123", + } + ], + ) + ] + actual = llm.get_num_tokens_from_messages(messages) + assert actual + class Foo(BaseModel): bar: int