Source code for langchain_community.tools.multion.close_session

from typing import TYPE_CHECKING, Optional, Type

from langchain_core.callbacks import (
    CallbackManagerForToolRun,
)
from langchain_core.pydantic_v1 import BaseModel, Field
from langchain_core.tools import BaseTool

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


[docs]class CloseSessionSchema(BaseModel): """更新会话工具的输入。""" sessionId: str = Field( ..., description="""The sessionId, received from one of the createSessions or updateSessions run before""", )
[docs]class MultionCloseSession(BaseTool): """工具,用于关闭提供字段的现有Multion浏览器窗口。 属性: name: 工具的名称。默认值:"close_multion_session" description: 工具的描述。 args_schema: 工具参数的模式。默认值: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}")