Skip to content

Commit 1dffce2

Browse files
committed
move create_docstring method outside the class.
1 parent 5cc8978 commit 1dffce2

File tree

1 file changed

+12
-13
lines changed
  • packages/toolbox-core/src/toolbox_core

1 file changed

+12
-13
lines changed

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def __init__(
8282

8383
# the following properties are set to help anyone that might inspect it determine usage
8484
self.__name__ = name
85-
self.__doc__ = self._create_docstring()
85+
self.__doc__ = create_docstring(self.__description, self.__params)
8686
self.__signature__ = Signature(
8787
parameters=inspect_type_params, return_annotation=str
8888
)
@@ -96,18 +96,6 @@ def __init__(
9696
# map of parameter name to value (or callable that produces that value)
9797
self.__bound_parameters = bound_params
9898

99-
def _create_docstring(self) -> str:
100-
"""Convert a tool schema into its function docstring"""
101-
docstring = self.__description
102-
if not self.__params:
103-
return docstring
104-
docstring += "\n\nArgs:"
105-
for p in self.__params:
106-
docstring += (
107-
f"\n {p.name} ({p.to_param().annotation.__name__}): {p.description}"
108-
)
109-
return docstring
110-
11199
def __copy(
112100
self,
113101
session: Optional[ClientSession] = None,
@@ -278,6 +266,17 @@ def bind_parameters(
278266
bound_params=types.MappingProxyType(all_bound_params),
279267
)
280268

269+
def create_docstring(description: str, params: Sequence[ParameterSchema]) -> str:
270+
"""Convert tool description and params into its function docstring"""
271+
docstring = description
272+
if not params:
273+
return docstring
274+
docstring += "\n\nArgs:"
275+
for p in params:
276+
docstring += (
277+
f"\n {p.name} ({p.to_param().annotation.__name__}): {p.description}"
278+
)
279+
return docstring
281280

282281
def identify_required_authn_params(
283282
req_authn_params: Mapping[str, list[str]], auth_service_names: Iterable[str]

0 commit comments

Comments
 (0)