core,integrations[minor]: Dont error on fields in model_kwargs (#27110)

Given the current erroring behavior, every time we've moved a kwarg from
model_kwargs and made it its own field that was a breaking change.
Updating this behavior to support the old instantiations /
serializations.

Assuming build_extra_kwargs was not something that itself is being used
externally and needs to be kept backwards compatible
This commit is contained in:
Bagatur
2024-10-04 11:30:27 -07:00
committed by GitHub
parent 0495b7f441
commit 4935a14314
17 changed files with 91 additions and 68 deletions

View File

@@ -30,9 +30,12 @@ def test_openai_model_kwargs() -> None:
assert llm.model_kwargs == {"foo": "bar"}
def test_openai_invalid_model_kwargs() -> None:
with pytest.raises(ValueError):
OpenAI(model_kwargs={"model_name": "foo"})
def test_openai_fields_in_model_kwargs() -> None:
"""Test that for backwards compatibility fields can be passed in as model_kwargs."""
llm = OpenAI(model_kwargs={"model_name": "foo"})
assert llm.model_name == "foo"
llm = OpenAI(model_kwargs={"model": "foo"})
assert llm.model_name == "foo"
def test_openai_incorrect_field() -> None: