Skip to content

The agent engineering platform.

Fix: Use `Union` instead of `|` to improve compatibility, fix #15244 (#15245)

chyroc6fb3cc6f27e7
diff --git a/libs/community/langchain_community/chat_models/gpt_router.py b/libs/community/langchain_community/chat_models/gpt_router.py
index 1e53f41a3d..ac91200ed4 100644
--- a/libs/community/langchain_community/chat_models/gpt_router.py
+++ b/libs/community/langchain_community/chat_models/gpt_router.py
@@ -233,8 +233,8 @@ class GPTRouter(BaseChatModel):
self,
messages: List[BaseMessage],
stop: Optional[List[str]] = None,
- run_manager: CallbackManagerForLLMRun | None = None,
- stream: bool | None = None,
+ run_manager: Optional[CallbackManagerForLLMRun] = None,
+ stream: Optional[bool] = None,
**kwargs: Any,
) -> ChatResult:
should_stream = stream if stream is not None else self.streaming
@@ -259,8 +259,8 @@ class GPTRouter(BaseChatModel):
self,
messages: List[BaseMessage],
stop: Optional[List[str]] = None,
- run_manager: AsyncCallbackManagerForLLMRun | None = None,
- stream: bool | None = None,
+ run_manager: Optional[AsyncCallbackManagerForLLMRun] = None,
+ stream: Optional[bool] = None,
**kwargs: Any,
) -> ChatResult:
should_stream = stream if stream is not None else self.streaming
diff --git a/libs/community/langchain_community/tools/e2b_data_analysis/tool.py b/libs/community/langchain_community/tools/e2b_data_analysis/tool.py
index 0794b87469..242b305e1b 100644
--- a/libs/community/langchain_community/tools/e2b_data_analysis/tool.py
+++ b/libs/community/langchain_community/tools/e2b_data_analysis/tool.py
@@ -5,7 +5,7 @@ import json
import os
from io import StringIO
from sys import version_info
-from typing import IO, TYPE_CHECKING, Any, Callable, List, Optional, Type
+from typing import IO, TYPE_CHECKING, Any, Callable, List, Optional, Type, Union
from langchain_core.callbacks import (
AsyncCallbackManagerForToolRun,
@@ -197,11 +197,11 @@ class E2BDataAnalysisTool(BaseTool):
"exit_code": output.exit_code,
}
- def install_python_packages(self, package_names: str | List[str]) -> None:
+ def install_python_packages(self, package_names: Union[str, List[str]]) -> None:
"""Install python packages in the sandbox."""
self.session.install_python_packages(package_names)
- def install_system_packages(self, package_names: str | List[str]) -> None:
+ def install_system_packages(self, package_names: Union[str, List[str]]) -> None:
"""Install system packages (via apt) in the sandbox."""
self.session.install_system_packages(package_names)
diff --git a/libs/core/langchain_core/output_parsers/base.py b/libs/core/langchain_core/output_parsers/base.py
index 4f8588b205..c5c2e379e8 100644
--- a/libs/core/langchain_core/output_parsers/base.py
+++ b/libs/core/langchain_core/output_parsers/base.py
@@ -96,7 +96,7 @@ class BaseGenerationOutputParser(
async def ainvoke(
self,
- input: str | BaseMessage,
+ input: Union[str, BaseMessage],
config: Optional[RunnableConfig] = None,
**kwargs: Optional[Any],
) -> T:
@@ -185,7 +185,7 @@ class BaseOutputParser(
async def ainvoke(
self,
- input: str | BaseMessage,
+ input: Union[str, BaseMessage],
config: Optional[RunnableConfig] = None,
**kwargs: Optional[Any],
) -> T:
diff --git a/libs/core/langchain_core/tracers/base.py b/libs/core/langchain_core/tracers/base.py
index a963fa02b3..9d36e8d45b 100644
--- a/libs/core/langchain_core/tracers/base.py
+++ b/libs/core/langchain_core/tracers/base.py
@@ -118,7 +118,7 @@ class BaseTracer(BaseCallbackHandler, ABC):
return parent_run.child_execution_order + 1
- def _get_run(self, run_id: UUID, run_type: str | None = None) -> Run:
+ def _get_run(self, run_id: UUID, run_type: Optional[str] = None) -> Run:
try:
run = self.run_map[str(run_id)]
except KeyError as exc: