r"""Convert a list of Python synchronous functions to Python asynchronous functions. Args: funcs (list[FunctionTool]): List of Python synchronous functions in the :obj:`FunctionTool` format. Returns: list[FunctionTool]: List of Python asynchronous functions
(funcs: list[FunctionTool])
| 18 | |
| 19 | |
| 20 | def sync_funcs_to_async(funcs: list[FunctionTool]) -> list[FunctionTool]: |
| 21 | r"""Convert a list of Python synchronous functions to Python |
| 22 | asynchronous functions. |
| 23 | |
| 24 | Args: |
| 25 | funcs (list[FunctionTool]): List of Python synchronous |
| 26 | functions in the :obj:`FunctionTool` format. |
| 27 | |
| 28 | Returns: |
| 29 | list[FunctionTool]: List of Python asynchronous functions |
| 30 | in the :obj:`FunctionTool` format. |
| 31 | """ |
| 32 | async_funcs = [] |
| 33 | for func in funcs: |
| 34 | sync_func = func.func |
| 35 | |
| 36 | def async_callable(*args, **kwargs): |
| 37 | return asyncio.to_thread(sync_func, *args, **kwargs) # noqa: B023 |
| 38 | |
| 39 | async_funcs.append( |
| 40 | FunctionTool(async_callable, deepcopy(func.openai_tool_schema)) |
| 41 | ) |
| 42 | return async_funcs |
nothing calls this directly
no test coverage detected