Skip to content

Commit 45bcdca

Browse files
committed
move to_pydantic_model outside the class
1 parent 98169e6 commit 45bcdca

File tree

1 file changed

+14
-14
lines changed
  • packages/toolbox-core/src/toolbox_core

1 file changed

+14
-14
lines changed

packages/toolbox-core/src/toolbox_core/tool.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __init__(
8181
self.__url = f"{base_url}/api/tool/{name}/invoke"
8282
self.__description = description
8383
self.__params = params
84-
self.__pydantic_model = self._to_pydantic_model()
84+
self.__pydantic_model = to_pydantic_model(self.__params)
8585

8686
inspect_type_params = [param.to_param() for param in self.__params]
8787

@@ -102,19 +102,6 @@ def __init__(
102102
# map of parameter name to value (or callable that produces that value)
103103
self.__bound_parameters = bound_params
104104

105-
def _to_pydantic_model(self) -> Type[BaseModel]:
106-
"""Converts the given manifest schema to a Pydantic BaseModel class."""
107-
field_definitions = {}
108-
for field in self.__params:
109-
field_definitions[field.name] = cast(
110-
Any,
111-
(
112-
field.to_param().annotation,
113-
Field(description=field.description),
114-
),
115-
)
116-
return create_model("tool_model", **field_definitions)
117-
118105
def __copy(
119106
self,
120107
session: Optional[ClientSession] = None,
@@ -327,3 +314,16 @@ def identify_required_authn_params(
327314
if required:
328315
required_params[param] = services
329316
return required_params
317+
318+
def to_pydantic_model(params: Sequence[ParameterSchema]) -> Type[BaseModel]:
319+
"""Converts the given parameters to a Pydantic BaseModel class."""
320+
field_definitions = {}
321+
for field in params:
322+
field_definitions[field.name] = cast(
323+
Any,
324+
(
325+
field.to_param().annotation,
326+
Field(description=field.description),
327+
),
328+
)
329+
return create_model("tool_model", **field_definitions)

0 commit comments

Comments
 (0)