Propagate context vars in all classes/methods

- Any direct usage of ThreadPoolExecutor or asyncio.run_in_executor needs manual handling of context vars
This commit is contained in:
Nuno Campos
2023-12-29 12:34:03 -08:00
parent 70e5d05952
commit eb5e250188
39 changed files with 338 additions and 368 deletions

View File

@@ -1,10 +1,8 @@
import asyncio
import platform
import warnings
from typing import Any, List, Optional, Type, Union
from langchain_core.callbacks import (
AsyncCallbackManagerForToolRun,
CallbackManagerForToolRun,
)
from langchain_core.pydantic_v1 import BaseModel, Field, root_validator
@@ -77,13 +75,3 @@ class ShellTool(BaseTool):
) -> str:
"""Run commands and return final output."""
return self.process.run(commands)
async def _arun(
self,
commands: Union[str, List[str]],
run_manager: Optional[AsyncCallbackManagerForToolRun] = None,
) -> str:
"""Run commands asynchronously and return final output."""
return await asyncio.get_event_loop().run_in_executor(
None, self.process.run, commands
)