Skip to content

Commit a945a4b

Browse files
committed
feat: Add support for async token getters to ToolboxTool
1 parent d3e20e5 commit a945a4b

File tree

1 file changed

+11
-6
lines changed
  • packages/toolbox-core/src/toolbox_core

1 file changed

+11
-6
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,12 @@ async def __call__(self, *args: Any, **kwargs: Any) -> str:
181181

182182
# apply bounded parameters
183183
for param, value in self.__bound_parameters.items():
184-
if asyncio.iscoroutinefunction(value):
185-
value = await value()
186-
elif callable(value):
187-
value = value()
188-
payload[param] = value
184+
payload[param] = await get_value(value)
189185

190186
# create headers for auth services
191187
headers = {}
192188
for auth_service, token_getter in self.__auth_service_token_getters.items():
193-
headers[f"{auth_service}_token"] = token_getter()
189+
headers[f"{auth_service}_token"] = await get_value(token_getter)
194190

195191
async with self.__session.post(
196192
self.__url,
@@ -330,3 +326,12 @@ def params_to_pydantic_model(
330326
),
331327
)
332328
return create_model(tool_name, **field_definitions)
329+
330+
331+
async def get_value(func: Callable[[], Any]) -> Any:
332+
"""Asynchronously or synchronously gets the value from a callable."""
333+
if asyncio.iscoroutinefunction(func):
334+
return await func()
335+
elif callable(func):
336+
return func()
337+
return func

0 commit comments

Comments
 (0)