Skip to content

The agent engineering platform.

fix(openai): handle function_call content in token counting (#34379)

Saurav Sapkotaf6297ced67ff
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 e59874bf7b..0f7fad73c9 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