mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-04 12:18:24 +00:00
add async support for tools (#10058)
This commit is contained in:
parent
c710c7303f
commit
566ce06f4a
@ -273,7 +273,11 @@ class ChildTool(BaseTool):
|
||||
Add run_manager: Optional[AsyncCallbackManagerForToolRun] = None
|
||||
to child implementations to enable tracing,
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
return await asyncio.get_running_loop().run_in_executor(
|
||||
None,
|
||||
partial(self._run, **kwargs),
|
||||
*args,
|
||||
)
|
||||
|
||||
def _to_args_and_kwargs(self, tool_input: Union[str, Dict]) -> Tuple[Tuple, Dict]:
|
||||
# For backwards compatibility, if run_input is a string,
|
||||
@ -522,7 +526,10 @@ class Tool(BaseTool):
|
||||
if new_argument_supported
|
||||
else await self.coroutine(*args, **kwargs)
|
||||
)
|
||||
raise NotImplementedError("Tool does not support async")
|
||||
else:
|
||||
return await asyncio.get_running_loop().run_in_executor(
|
||||
None, partial(self._run, run_manager=run_manager, **kwargs), *args
|
||||
)
|
||||
|
||||
# TODO: this is for backwards compatibility, remove in future
|
||||
def __init__(
|
||||
@ -634,7 +641,12 @@ class StructuredTool(BaseTool):
|
||||
if new_argument_supported
|
||||
else await self.coroutine(*args, **kwargs)
|
||||
)
|
||||
raise NotImplementedError("Tool does not support async")
|
||||
return await asyncio.get_running_loop().run_in_executor(
|
||||
None,
|
||||
self._run,
|
||||
partial(self._run, run_manager=run_manager, **kwargs),
|
||||
*args,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_function(
|
||||
|
Loading…
Reference in New Issue
Block a user