From 76564edd3a0eb610cbd771489d89307c5b17e837 Mon Sep 17 00:00:00 2001 From: Bagatur <22008038+baskaryan@users.noreply.github.com> Date: Thu, 5 Sep 2024 13:26:40 -0400 Subject: [PATCH] openai[patch]: update configurable model dumps (#26101) --- .../tests/unit_tests/chat_models/test_base.py | 61 ++++++++++++++----- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/libs/langchain/tests/unit_tests/chat_models/test_base.py b/libs/langchain/tests/unit_tests/chat_models/test_base.py index 8a9ed7d434c..f33cddf7acb 100644 --- a/libs/langchain/tests/unit_tests/chat_models/test_base.py +++ b/libs/langchain/tests/unit_tests/chat_models/test_base.py @@ -6,6 +6,7 @@ from langchain_core.language_models import BaseChatModel from langchain_core.messages import HumanMessage from langchain_core.prompts import ChatPromptTemplate from langchain_core.runnables import RunnableConfig, RunnableSequence +from pydantic import SecretStr from langchain.chat_models.base import __all__, init_chat_model @@ -56,7 +57,7 @@ def test_init_unknown_provider() -> None: @pytest.mark.requires("langchain_openai") @mock.patch.dict( - os.environ, {"OPENAI_API_KEY": "foo", "ANTHROPIC_API_KEY": "foo"}, clear=True + os.environ, {"OPENAI_API_KEY": "foo", "ANTHROPIC_API_KEY": "bar"}, clear=True ) def test_configurable() -> None: model = init_chat_model() @@ -96,25 +97,46 @@ def test_configurable() -> None: for method in ("get_num_tokens", "get_num_tokens_from_messages"): assert hasattr(model_with_config, method) - assert model_with_config.dict() == { # type: ignore[attr-defined] + assert model_with_config.model_dump() == { # type: ignore[attr-defined] "name": None, "bound": { + "name": None, + "cache": None, + "disable_streaming": False, "model_name": "gpt-4o", - "model": "gpt-4o", - "stream": False, - "n": 1, "temperature": 0.7, - "_type": "openai-chat", + "model_kwargs": {}, + "openai_api_key": SecretStr("foo"), + "openai_api_base": None, + "openai_organization": None, + "openai_proxy": None, + "request_timeout": None, + "max_retries": 2, + "presence_penalty": None, + "frequency_penalty": None, + "seed": None, + "logprobs": None, + "top_logprobs": None, + "logit_bias": None, + "streaming": False, + "n": 1, + "top_p": None, + "max_tokens": None, + "tiktoken_model_name": None, + "default_headers": None, + "default_query": None, + "http_client": None, + "http_async_client": None, + "stop": None, + "extra_body": None, + "include_response_headers": False, + "stream_usage": False, }, "kwargs": { "tools": [ { "type": "function", - "function": { - "name": "foo", - "description": "foo", - "parameters": {}, - }, + "function": {"name": "foo", "description": "foo", "parameters": {}}, } ] }, @@ -127,7 +149,7 @@ def test_configurable() -> None: @pytest.mark.requires("langchain_openai", "langchain_anthropic") @mock.patch.dict( - os.environ, {"OPENAI_API_KEY": "foo", "ANTHROPIC_API_KEY": "foo"}, clear=True + os.environ, {"OPENAI_API_KEY": "foo", "ANTHROPIC_API_KEY": "bar"}, clear=True ) def test_configurable_with_default() -> None: model = init_chat_model("gpt-4o", configurable_fields="any", config_prefix="bar") @@ -164,19 +186,26 @@ def test_configurable_with_default() -> None: with pytest.raises(ImportError): model_with_config.get_num_tokens_from_messages([(HumanMessage("foo"))]) # type: ignore[attr-defined] - assert model_with_config.dict() == { # type: ignore[attr-defined] + assert model_with_config.model_dump() == { # type: ignore[attr-defined] "name": None, "bound": { + "name": None, + "cache": None, + "disable_streaming": False, "model": "claude-3-sonnet-20240229", "max_tokens": 1024, "temperature": None, "top_k": None, "top_p": None, + "default_request_timeout": None, + "max_retries": 2, + "stop_sequences": None, + "anthropic_api_url": "https://api.anthropic.com", + "anthropic_api_key": SecretStr("bar"), + "default_headers": None, "model_kwargs": {}, "streaming": False, - "max_retries": 2, - "default_request_timeout": None, - "_type": "anthropic-chat", + "stream_usage": True, }, "kwargs": { "tools": [{"name": "foo", "description": "foo", "input_schema": {}}]