|
18 | 18 | from inspect import Signature
|
19 | 19 | from typing import (
|
20 | 20 | Any,
|
| 21 | + Awaitable, |
21 | 22 | Callable,
|
22 | 23 | Iterable,
|
23 | 24 | Mapping,
|
@@ -181,12 +182,12 @@ async def __call__(self, *args: Any, **kwargs: Any) -> str:
|
181 | 182 |
|
182 | 183 | # apply bounded parameters
|
183 | 184 | for param, value in self.__bound_parameters.items():
|
184 |
| - payload[param] = await get_value(value) |
| 185 | + payload[param] = await resolve_value(value) |
185 | 186 |
|
186 | 187 | # create headers for auth services
|
187 | 188 | headers = {}
|
188 | 189 | for auth_service, token_getter in self.__auth_service_token_getters.items():
|
189 |
| - headers[f"{auth_service}_token"] = await get_value(token_getter) |
| 190 | + headers[f"{auth_service}_token"] = await resolve_value(token_getter) |
190 | 191 |
|
191 | 192 | async with self.__session.post(
|
192 | 193 | self.__url,
|
@@ -328,10 +329,21 @@ def params_to_pydantic_model(
|
328 | 329 | return create_model(tool_name, **field_definitions)
|
329 | 330 |
|
330 | 331 |
|
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 |
| 332 | +async def resolve_value( |
| 333 | + source: Union[Callable[[], Awaitable[Any]], Callable[[], Any], Any], |
| 334 | +) -> Any: |
| 335 | + """ |
| 336 | + Asynchronously or synchronously resolves a given source to its value. |
| 337 | +
|
| 338 | + Args: |
| 339 | + source: The value, a callable returning a value, or a callable |
| 340 | + returning an awaitable value. |
| 341 | +
|
| 342 | + Returns: |
| 343 | + The resolved value. |
| 344 | + """ |
| 345 | + if asyncio.iscoroutinefunction(source): |
| 346 | + return await source() |
| 347 | + elif callable(source): |
| 348 | + return source() |
| 349 | + return source |
0 commit comments