From e7883d5b9fe8daef43dcd147d125cf3980ee38a2 Mon Sep 17 00:00:00 2001 From: Koshik Debanath <48962097+kowshik24@users.noreply.github.com> Date: Sat, 29 Mar 2025 02:02:09 +0600 Subject: [PATCH] langchain-openai: Support token counting for o-series models in ChatOpenAI (#30542) Related to #30344 Add support for token counting for o-series models in `test_token_counts.py`. * **Update `_MODELS` and `_CHAT_MODELS` dictionaries** - Add "o1", "o3", and "gpt-4o" to `_MODELS` and `_CHAT_MODELS` dictionaries. * **Update token counts** - Add token counts for "o1", "o3", and "gpt-4o" models. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/langchain-ai/langchain/pull/30542?shareId=ab208bf7-80a3-4b8d-80c4-2287486fedae). --- libs/partners/openai/tests/unit_tests/test_token_counts.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/partners/openai/tests/unit_tests/test_token_counts.py b/libs/partners/openai/tests/unit_tests/test_token_counts.py index 6ffcda94c86..24466231ed7 100644 --- a/libs/partners/openai/tests/unit_tests/test_token_counts.py +++ b/libs/partners/openai/tests/unit_tests/test_token_counts.py @@ -10,10 +10,13 @@ _EXPECTED_NUM_TOKENS = { "gpt-4": 12, "gpt-4-32k": 12, "gpt-3.5-turbo": 12, + "o1": 12, + "o3": 12, + "gpt-4o": 11, } _MODELS = models = ["ada", "babbage", "curie", "davinci"] -_CHAT_MODELS = ["gpt-4", "gpt-4-32k", "gpt-3.5-turbo"] +_CHAT_MODELS = ["gpt-4", "gpt-4-32k", "gpt-3.5-turbo", "o1", "o3", "gpt-4o"] @pytest.mark.xfail(reason="Old models require different tiktoken cached file")