mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-26 22:05:29 +00:00
openai[patch]: update configurable model dumps (#26101)
This commit is contained in:
@@ -6,6 +6,7 @@ from langchain_core.language_models import BaseChatModel
|
|||||||
from langchain_core.messages import HumanMessage
|
from langchain_core.messages import HumanMessage
|
||||||
from langchain_core.prompts import ChatPromptTemplate
|
from langchain_core.prompts import ChatPromptTemplate
|
||||||
from langchain_core.runnables import RunnableConfig, RunnableSequence
|
from langchain_core.runnables import RunnableConfig, RunnableSequence
|
||||||
|
from pydantic import SecretStr
|
||||||
|
|
||||||
from langchain.chat_models.base import __all__, init_chat_model
|
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")
|
@pytest.mark.requires("langchain_openai")
|
||||||
@mock.patch.dict(
|
@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:
|
def test_configurable() -> None:
|
||||||
model = init_chat_model()
|
model = init_chat_model()
|
||||||
@@ -96,25 +97,46 @@ def test_configurable() -> None:
|
|||||||
for method in ("get_num_tokens", "get_num_tokens_from_messages"):
|
for method in ("get_num_tokens", "get_num_tokens_from_messages"):
|
||||||
assert hasattr(model_with_config, method)
|
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,
|
"name": None,
|
||||||
"bound": {
|
"bound": {
|
||||||
|
"name": None,
|
||||||
|
"cache": None,
|
||||||
|
"disable_streaming": False,
|
||||||
"model_name": "gpt-4o",
|
"model_name": "gpt-4o",
|
||||||
"model": "gpt-4o",
|
|
||||||
"stream": False,
|
|
||||||
"n": 1,
|
|
||||||
"temperature": 0.7,
|
"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": {
|
"kwargs": {
|
||||||
"tools": [
|
"tools": [
|
||||||
{
|
{
|
||||||
"type": "function",
|
"type": "function",
|
||||||
"function": {
|
"function": {"name": "foo", "description": "foo", "parameters": {}},
|
||||||
"name": "foo",
|
|
||||||
"description": "foo",
|
|
||||||
"parameters": {},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -127,7 +149,7 @@ def test_configurable() -> None:
|
|||||||
|
|
||||||
@pytest.mark.requires("langchain_openai", "langchain_anthropic")
|
@pytest.mark.requires("langchain_openai", "langchain_anthropic")
|
||||||
@mock.patch.dict(
|
@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:
|
def test_configurable_with_default() -> None:
|
||||||
model = init_chat_model("gpt-4o", configurable_fields="any", config_prefix="bar")
|
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):
|
with pytest.raises(ImportError):
|
||||||
model_with_config.get_num_tokens_from_messages([(HumanMessage("foo"))]) # type: ignore[attr-defined]
|
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,
|
"name": None,
|
||||||
"bound": {
|
"bound": {
|
||||||
|
"name": None,
|
||||||
|
"cache": None,
|
||||||
|
"disable_streaming": False,
|
||||||
"model": "claude-3-sonnet-20240229",
|
"model": "claude-3-sonnet-20240229",
|
||||||
"max_tokens": 1024,
|
"max_tokens": 1024,
|
||||||
"temperature": None,
|
"temperature": None,
|
||||||
"top_k": None,
|
"top_k": None,
|
||||||
"top_p": 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": {},
|
"model_kwargs": {},
|
||||||
"streaming": False,
|
"streaming": False,
|
||||||
"max_retries": 2,
|
"stream_usage": True,
|
||||||
"default_request_timeout": None,
|
|
||||||
"_type": "anthropic-chat",
|
|
||||||
},
|
},
|
||||||
"kwargs": {
|
"kwargs": {
|
||||||
"tools": [{"name": "foo", "description": "foo", "input_schema": {}}]
|
"tools": [{"name": "foo", "description": "foo", "input_schema": {}}]
|
||||||
|
Reference in New Issue
Block a user