Skip to content

Commit 5e3cee6

Browse files
authored
core[patch]: make get_all_basemodel_annotations public (#27762)
1 parent 8073146 commit 5e3cee6

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

libs/core/langchain_core/tools/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ def args(self) -> dict:
362362
def tool_call_schema(self) -> Type[BaseModel]:
363363
full_schema = self.get_input_schema()
364364
fields = []
365-
for name, type_ in _get_all_basemodel_annotations(full_schema).items():
365+
for name, type_ in get_all_basemodel_annotations(full_schema).items():
366366
if not _is_injected_arg_type(type_):
367367
fields.append(name)
368368
return _create_subset_model(
@@ -858,7 +858,7 @@ def _is_injected_arg_type(type_: Type) -> bool:
858858
)
859859

860860

861-
def _get_all_basemodel_annotations(
861+
def get_all_basemodel_annotations(
862862
cls: Union[TypeBaseModel, Any], *, default_to_bound: bool = True
863863
) -> Dict[str, Type]:
864864
# cls has no subscript: cls = FooBar
@@ -876,7 +876,7 @@ def _get_all_basemodel_annotations(
876876
orig_bases: Tuple = getattr(cls, "__orig_bases__", tuple())
877877
# cls has subscript: cls = FooBar[int]
878878
else:
879-
annotations = _get_all_basemodel_annotations(
879+
annotations = get_all_basemodel_annotations(
880880
get_origin(cls), default_to_bound=False
881881
)
882882
orig_bases = (cls,)
@@ -890,7 +890,7 @@ def _get_all_basemodel_annotations(
890890
# if class = FooBar inherits from Baz, parent = Baz
891891
if isinstance(parent, type) and is_pydantic_v1_subclass(parent):
892892
annotations.update(
893-
_get_all_basemodel_annotations(parent, default_to_bound=False)
893+
get_all_basemodel_annotations(parent, default_to_bound=False)
894894
)
895895
continue
896896

libs/core/tests/unit_tests/test_tools.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
from langchain_core.tools.base import (
4949
InjectedToolArg,
5050
SchemaAnnotationError,
51-
_get_all_basemodel_annotations,
5251
_is_message_content_block,
5352
_is_message_content_type,
53+
get_all_basemodel_annotations,
5454
)
5555
from langchain_core.utils.function_calling import convert_to_openai_function
5656
from langchain_core.utils.pydantic import PYDANTIC_MAJOR_VERSION, _create_subset_model
@@ -1773,19 +1773,19 @@ class ModelC(Mixin, ModelB):
17731773
c: dict
17741774

17751775
expected = {"a": str, "b": Annotated[ModelA[Dict[str, Any]], "foo"], "c": dict}
1776-
actual = _get_all_basemodel_annotations(ModelC)
1776+
actual = get_all_basemodel_annotations(ModelC)
17771777
assert actual == expected
17781778

17791779
expected = {"a": str, "b": Annotated[ModelA[Dict[str, Any]], "foo"]}
1780-
actual = _get_all_basemodel_annotations(ModelB)
1780+
actual = get_all_basemodel_annotations(ModelB)
17811781
assert actual == expected
17821782

17831783
expected = {"a": Any}
1784-
actual = _get_all_basemodel_annotations(ModelA)
1784+
actual = get_all_basemodel_annotations(ModelA)
17851785
assert actual == expected
17861786

17871787
expected = {"a": int}
1788-
actual = _get_all_basemodel_annotations(ModelA[int])
1788+
actual = get_all_basemodel_annotations(ModelA[int])
17891789
assert actual == expected
17901790

17911791
D = TypeVar("D", bound=Union[str, int])
@@ -1799,7 +1799,7 @@ class ModelD(ModelC, Generic[D]):
17991799
"c": dict,
18001800
"d": Union[str, int, None],
18011801
}
1802-
actual = _get_all_basemodel_annotations(ModelD)
1802+
actual = get_all_basemodel_annotations(ModelD)
18031803
assert actual == expected
18041804

18051805
expected = {
@@ -1808,7 +1808,7 @@ class ModelD(ModelC, Generic[D]):
18081808
"c": dict,
18091809
"d": Union[int, None],
18101810
}
1811-
actual = _get_all_basemodel_annotations(ModelD[int])
1811+
actual = get_all_basemodel_annotations(ModelD[int])
18121812
assert actual == expected
18131813

18141814

@@ -1830,19 +1830,19 @@ class ModelC(Mixin, ModelB):
18301830
c: dict
18311831

18321832
expected = {"a": str, "b": Annotated[ModelA[Dict[str, Any]], "foo"], "c": dict}
1833-
actual = _get_all_basemodel_annotations(ModelC)
1833+
actual = get_all_basemodel_annotations(ModelC)
18341834
assert actual == expected
18351835

18361836
expected = {"a": str, "b": Annotated[ModelA[Dict[str, Any]], "foo"]}
1837-
actual = _get_all_basemodel_annotations(ModelB)
1837+
actual = get_all_basemodel_annotations(ModelB)
18381838
assert actual == expected
18391839

18401840
expected = {"a": Any}
1841-
actual = _get_all_basemodel_annotations(ModelA)
1841+
actual = get_all_basemodel_annotations(ModelA)
18421842
assert actual == expected
18431843

18441844
expected = {"a": int}
1845-
actual = _get_all_basemodel_annotations(ModelA[int])
1845+
actual = get_all_basemodel_annotations(ModelA[int])
18461846
assert actual == expected
18471847

18481848
D = TypeVar("D", bound=Union[str, int])
@@ -1856,7 +1856,7 @@ class ModelD(ModelC, Generic[D]):
18561856
"c": dict,
18571857
"d": Union[str, int, None],
18581858
}
1859-
actual = _get_all_basemodel_annotations(ModelD)
1859+
actual = get_all_basemodel_annotations(ModelD)
18601860
assert actual == expected
18611861

18621862
expected = {
@@ -1865,7 +1865,7 @@ class ModelD(ModelC, Generic[D]):
18651865
"c": dict,
18661866
"d": Union[int, None],
18671867
}
1868-
actual = _get_all_basemodel_annotations(ModelD[int])
1868+
actual = get_all_basemodel_annotations(ModelD[int])
18691869
assert actual == expected
18701870

18711871

0 commit comments

Comments
 (0)