langchain/libs/community/langchain_community/tools/multion/close_session.py
Erick Friis c2a3021bb0
multiple: pydantic 2 compatibility, v0.3 (#26443)
Signed-off-by: ChengZi <chen.zhang@zilliz.com>
Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com>
Co-authored-by: Dan O'Donovan <dan.odonovan@gmail.com>
Co-authored-by: Tom Daniel Grande <tomdgrande@gmail.com>
Co-authored-by: Grande <Tom.Daniel.Grande@statsbygg.no>
Co-authored-by: Bagatur <baskaryan@gmail.com>
Co-authored-by: ccurme <chester.curme@gmail.com>
Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
Co-authored-by: Tomaz Bratanic <bratanic.tomaz@gmail.com>
Co-authored-by: ZhangShenao <15201440436@163.com>
Co-authored-by: Friso H. Kingma <fhkingma@gmail.com>
Co-authored-by: ChengZi <chen.zhang@zilliz.com>
Co-authored-by: Nuno Campos <nuno@langchain.dev>
Co-authored-by: Morgante Pell <morgantep@google.com>
2024-09-13 14:38:45 -07:00

58 lines
1.7 KiB
Python

from typing import TYPE_CHECKING, Optional, Type
from langchain_core.callbacks import (
CallbackManagerForToolRun,
)
from langchain_core.tools import BaseTool
from pydantic import BaseModel, Field
if TYPE_CHECKING:
# This is for linting and IDE typehints
import multion
else:
try:
# We do this so pydantic can resolve the types when instantiating
import multion
except ImportError:
pass
class CloseSessionSchema(BaseModel):
"""Input for UpdateSessionTool."""
sessionId: str = Field(
...,
description="""The sessionId, received from one of the createSessions
or updateSessions run before""",
)
class MultionCloseSession(BaseTool):
"""Tool that closes an existing Multion Browser Window with provided fields.
Attributes:
name: The name of the tool. Default: "close_multion_session"
description: The description of the tool.
args_schema: The schema for the tool's arguments. Default: UpdateSessionSchema
"""
name: str = "close_multion_session"
description: str = """Use this tool to close \
an existing corresponding Multion Browser Window with provided fields. \
Note: SessionId must be received from previous Browser window creation."""
args_schema: Type[CloseSessionSchema] = CloseSessionSchema
sessionId: str = ""
def _run(
self,
sessionId: str,
run_manager: Optional[CallbackManagerForToolRun] = None,
) -> None:
try:
try:
multion.close_session(sessionId)
except Exception as e:
print(f"{e}, retrying...") # noqa: T201
except Exception as e:
raise Exception(f"An error occurred: {e}")