MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / sync_funcs_to_async

Function sync_funcs_to_async

camel/utils/async_func.py:20–42  ·  view source on GitHub ↗

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])

Source from the content-addressed store, hash-verified

18
19
20def 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

Callers

nothing calls this directly

Calls 1

FunctionToolClass · 0.90

Tested by

no test coverage detected