Skip to content

Commit

Permalink
Fix: Use Union instead of | to improve compatibility, fix #15244 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
chyroc authored Dec 28, 2023
1 parent 6a5a2fb commit 6fb3cc6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions libs/community/langchain_community/chat_models/gpt_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ def _generate(
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
Expand All @@ -259,8 +259,8 @@ async def _agenerate(
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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,
Expand Down Expand Up @@ -197,11 +197,11 @@ def run_command(
"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)

Expand Down
4 changes: 2 additions & 2 deletions libs/core/langchain_core/output_parsers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def invoke(

async def ainvoke(
self,
input: str | BaseMessage,
input: Union[str, BaseMessage],
config: Optional[RunnableConfig] = None,
**kwargs: Optional[Any],
) -> T:
Expand Down Expand Up @@ -185,7 +185,7 @@ def invoke(

async def ainvoke(
self,
input: str | BaseMessage,
input: Union[str, BaseMessage],
config: Optional[RunnableConfig] = None,
**kwargs: Optional[Any],
) -> T:
Expand Down
2 changes: 1 addition & 1 deletion libs/core/langchain_core/tracers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def _get_execution_order(self, parent_run_id: Optional[str] = None) -> int:

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:
Expand Down

0 comments on commit 6fb3cc6

Please sign in to comment.