Skip to content

Commit 5d33732

Browse files
authored
core[patch]: make get_all_basemodel_annotations public (#27761)
1 parent 94ea950 commit 5d33732

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

libs/core/langchain_core/tools/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ def args(self) -> dict:
449449
def tool_call_schema(self) -> type[BaseModel]:
450450
full_schema = self.get_input_schema()
451451
fields = []
452-
for name, type_ in _get_all_basemodel_annotations(full_schema).items():
452+
for name, type_ in get_all_basemodel_annotations(full_schema).items():
453453
if not _is_injected_arg_type(type_):
454454
fields.append(name)
455455
return _create_subset_model(
@@ -962,7 +962,7 @@ def _is_injected_arg_type(type_: type) -> bool:
962962
)
963963

964964

965-
def _get_all_basemodel_annotations(
965+
def get_all_basemodel_annotations(
966966
cls: Union[TypeBaseModel, Any], *, default_to_bound: bool = True
967967
) -> dict[str, type]:
968968
# cls has no subscript: cls = FooBar
@@ -980,7 +980,7 @@ def _get_all_basemodel_annotations(
980980
orig_bases: tuple = getattr(cls, "__orig_bases__", ())
981981
# cls has subscript: cls = FooBar[int]
982982
else:
983-
annotations = _get_all_basemodel_annotations(
983+
annotations = get_all_basemodel_annotations(
984984
get_origin(cls), default_to_bound=False
985985
)
986986
orig_bases = (cls,)
@@ -994,7 +994,7 @@ def _get_all_basemodel_annotations(
994994
# if class = FooBar inherits from Baz, parent = Baz
995995
if isinstance(parent, type) and is_pydantic_v1_subclass(parent):
996996
annotations.update(
997-
_get_all_basemodel_annotations(parent, default_to_bound=False)
997+
get_all_basemodel_annotations(parent, default_to_bound=False)
998998
)
999999
continue
10001000

libs/core/tests/unit_tests/runnables/test_runnable.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,6 +1891,13 @@ async def test_prompt_with_chat_model_async(
18911891
)
18921892

18931893

1894+
@pytest.mark.skipif(
1895+
condition=sys.version_info[1] == 13,
1896+
reason=(
1897+
"temporary, py3.13 exposes some invalid assumptions about order of batch async "
1898+
"executions."
1899+
),
1900+
)
18941901
@freeze_time("2023-01-01")
18951902
async def test_prompt_with_llm(
18961903
mocker: MockerFixture, snapshot: SnapshotAssertion

libs/core/tests/unit_tests/test_tools.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
from langchain_core.tools.base import (
4848
InjectedToolArg,
4949
SchemaAnnotationError,
50-
_get_all_basemodel_annotations,
5150
_is_message_content_block,
5251
_is_message_content_type,
52+
get_all_basemodel_annotations,
5353
)
5454
from langchain_core.utils.function_calling import convert_to_openai_function
5555
from langchain_core.utils.pydantic import PYDANTIC_MAJOR_VERSION, _create_subset_model
@@ -1904,19 +1904,19 @@ class ModelC(Mixin, ModelB):
19041904
c: dict
19051905

19061906
expected = {"a": str, "b": Annotated[ModelA[dict[str, Any]], "foo"], "c": dict}
1907-
actual = _get_all_basemodel_annotations(ModelC)
1907+
actual = get_all_basemodel_annotations(ModelC)
19081908
assert actual == expected
19091909

19101910
expected = {"a": str, "b": Annotated[ModelA[dict[str, Any]], "foo"]}
1911-
actual = _get_all_basemodel_annotations(ModelB)
1911+
actual = get_all_basemodel_annotations(ModelB)
19121912
assert actual == expected
19131913

19141914
expected = {"a": Any}
1915-
actual = _get_all_basemodel_annotations(ModelA)
1915+
actual = get_all_basemodel_annotations(ModelA)
19161916
assert actual == expected
19171917

19181918
expected = {"a": int}
1919-
actual = _get_all_basemodel_annotations(ModelA[int])
1919+
actual = get_all_basemodel_annotations(ModelA[int])
19201920
assert actual == expected
19211921

19221922
D = TypeVar("D", bound=Union[str, int])
@@ -1930,7 +1930,7 @@ class ModelD(ModelC, Generic[D]):
19301930
"c": dict,
19311931
"d": Union[str, int, None],
19321932
}
1933-
actual = _get_all_basemodel_annotations(ModelD)
1933+
actual = get_all_basemodel_annotations(ModelD)
19341934
assert actual == expected
19351935

19361936
expected = {
@@ -1939,7 +1939,7 @@ class ModelD(ModelC, Generic[D]):
19391939
"c": dict,
19401940
"d": Union[int, None],
19411941
}
1942-
actual = _get_all_basemodel_annotations(ModelD[int])
1942+
actual = get_all_basemodel_annotations(ModelD[int])
19431943
assert actual == expected
19441944

19451945

@@ -1961,19 +1961,19 @@ class ModelC(Mixin, ModelB):
19611961
c: dict
19621962

19631963
expected = {"a": str, "b": Annotated[ModelA[dict[str, Any]], "foo"], "c": dict}
1964-
actual = _get_all_basemodel_annotations(ModelC)
1964+
actual = get_all_basemodel_annotations(ModelC)
19651965
assert actual == expected
19661966

19671967
expected = {"a": str, "b": Annotated[ModelA[dict[str, Any]], "foo"]}
1968-
actual = _get_all_basemodel_annotations(ModelB)
1968+
actual = get_all_basemodel_annotations(ModelB)
19691969
assert actual == expected
19701970

19711971
expected = {"a": Any}
1972-
actual = _get_all_basemodel_annotations(ModelA)
1972+
actual = get_all_basemodel_annotations(ModelA)
19731973
assert actual == expected
19741974

19751975
expected = {"a": int}
1976-
actual = _get_all_basemodel_annotations(ModelA[int])
1976+
actual = get_all_basemodel_annotations(ModelA[int])
19771977
assert actual == expected
19781978

19791979
D = TypeVar("D", bound=Union[str, int])
@@ -1987,7 +1987,7 @@ class ModelD(ModelC, Generic[D]):
19871987
"c": dict,
19881988
"d": Union[str, int, None],
19891989
}
1990-
actual = _get_all_basemodel_annotations(ModelD)
1990+
actual = get_all_basemodel_annotations(ModelD)
19911991
assert actual == expected
19921992

19931993
expected = {
@@ -1996,7 +1996,7 @@ class ModelD(ModelC, Generic[D]):
19961996
"c": dict,
19971997
"d": Union[int, None],
19981998
}
1999-
actual = _get_all_basemodel_annotations(ModelD[int])
1999+
actual = get_all_basemodel_annotations(ModelD[int])
20002000
assert actual == expected
20012001

20022002

0 commit comments

Comments
 (0)