@@ -1631,7 +1631,7 @@ def get_weather(location: str) -> str:
1631
1631
"parsed": None,
1632
1632
}
1633
1633
1634
- kwargs: Additional keyword args aren't supported .
1634
+ kwargs: Additional keyword args are passed through to the model .
1635
1635
1636
1636
Returns:
1637
1637
A Runnable that takes same inputs as a :class:`langchain_core.language_models.chat.BaseChatModel`.
@@ -1655,9 +1655,10 @@ def get_weather(location: str) -> str:
1655
1655
1656
1656
.. versionchanged:: 0.3.12
1657
1657
Support for ``tools`` added.
1658
+
1659
+ .. versionchanged:: 0.3.21
1660
+ Pass ``kwargs`` through to the model.
1658
1661
""" # noqa: E501
1659
- if kwargs :
1660
- raise ValueError (f"Received unsupported arguments { kwargs } " )
1661
1662
if strict is not None and method == "json_mode" :
1662
1663
raise ValueError (
1663
1664
"Argument `strict` is not supported with `method`='json_mode'"
@@ -1700,13 +1701,18 @@ def get_weather(location: str) -> str:
1700
1701
)
1701
1702
tool_name = convert_to_openai_tool (schema )["function" ]["name" ]
1702
1703
bind_kwargs = self ._filter_disabled_params (
1703
- tool_choice = tool_name ,
1704
- parallel_tool_calls = False ,
1705
- strict = strict ,
1706
- ls_structured_output_format = {
1707
- "kwargs" : {"method" : method , "strict" : strict },
1708
- "schema" : schema ,
1709
- },
1704
+ ** {
1705
+ ** dict (
1706
+ tool_choice = tool_name ,
1707
+ parallel_tool_calls = False ,
1708
+ strict = strict ,
1709
+ ls_structured_output_format = {
1710
+ "kwargs" : {"method" : method , "strict" : strict },
1711
+ "schema" : schema ,
1712
+ },
1713
+ ),
1714
+ ** kwargs ,
1715
+ }
1710
1716
)
1711
1717
1712
1718
llm = self .bind_tools ([schema ], ** bind_kwargs )
@@ -1721,11 +1727,16 @@ def get_weather(location: str) -> str:
1721
1727
)
1722
1728
elif method == "json_mode" :
1723
1729
llm = self .bind (
1724
- response_format = {"type" : "json_object" },
1725
- ls_structured_output_format = {
1726
- "kwargs" : {"method" : method },
1727
- "schema" : schema ,
1728
- },
1730
+ ** {
1731
+ ** dict (
1732
+ response_format = {"type" : "json_object" },
1733
+ ls_structured_output_format = {
1734
+ "kwargs" : {"method" : method },
1735
+ "schema" : schema ,
1736
+ },
1737
+ ),
1738
+ ** kwargs ,
1739
+ }
1729
1740
)
1730
1741
output_parser = (
1731
1742
PydanticOutputParser (pydantic_object = schema ) # type: ignore[arg-type]
@@ -1739,13 +1750,16 @@ def get_weather(location: str) -> str:
1739
1750
"Received None."
1740
1751
)
1741
1752
response_format = _convert_to_openai_response_format (schema , strict = strict )
1742
- bind_kwargs = dict (
1743
- response_format = response_format ,
1744
- ls_structured_output_format = {
1745
- "kwargs" : {"method" : method , "strict" : strict },
1746
- "schema" : convert_to_openai_tool (schema ),
1747
- },
1748
- )
1753
+ bind_kwargs = {
1754
+ ** dict (
1755
+ response_format = response_format ,
1756
+ ls_structured_output_format = {
1757
+ "kwargs" : {"method" : method , "strict" : strict },
1758
+ "schema" : convert_to_openai_tool (schema ),
1759
+ },
1760
+ ** kwargs ,
1761
+ )
1762
+ }
1749
1763
if tools :
1750
1764
bind_kwargs ["tools" ] = [
1751
1765
convert_to_openai_tool (t , strict = strict ) for t in tools
@@ -2597,7 +2611,7 @@ def get_weather(location: str) -> str:
2597
2611
"parsed": None,
2598
2612
}
2599
2613
2600
- kwargs: Additional keyword args aren't supported .
2614
+ kwargs: Additional keyword args are passed through to the model .
2601
2615
2602
2616
Returns:
2603
2617
A Runnable that takes same inputs as a :class:`langchain_core.language_models.chat.BaseChatModel`.
@@ -2623,6 +2637,12 @@ def get_weather(location: str) -> str:
2623
2637
2624
2638
``method`` default changed from "function_calling" to "json_schema".
2625
2639
2640
+ .. versionchanged:: 0.3.12
2641
+ Support for ``tools`` added.
2642
+
2643
+ .. versionchanged:: 0.3.21
2644
+ Pass ``kwargs`` through to the model.
2645
+
2626
2646
.. dropdown:: Example: schema=Pydantic class, method="json_schema", include_raw=False, strict=True
2627
2647
2628
2648
Note, OpenAI has a number of restrictions on what types of schemas can be
0 commit comments