initial commit
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
"""MutliOn Client API tools."""
|
||||
|
||||
from langchain_community.tools.multion.close_session import MultionCloseSession
|
||||
from langchain_community.tools.multion.create_session import MultionCreateSession
|
||||
from langchain_community.tools.multion.update_session import MultionUpdateSession
|
||||
|
||||
__all__ = ["MultionCreateSession", "MultionUpdateSession", "MultionCloseSession"]
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,57 @@
|
||||
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}")
|
||||
@@ -0,0 +1,67 @@
|
||||
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 CreateSessionSchema(BaseModel):
|
||||
"""Input for CreateSessionTool."""
|
||||
|
||||
query: str = Field(
|
||||
...,
|
||||
description="The query to run in multion agent.",
|
||||
)
|
||||
url: str = Field(
|
||||
"https://www.google.com/",
|
||||
description="""The Url to run the agent at. Note: accepts only secure \
|
||||
links having https://""",
|
||||
)
|
||||
|
||||
|
||||
class MultionCreateSession(BaseTool):
|
||||
"""Tool that creates a new Multion Browser Window with provided fields.
|
||||
|
||||
Attributes:
|
||||
name: The name of the tool. Default: "create_multion_session"
|
||||
description: The description of the tool.
|
||||
args_schema: The schema for the tool's arguments.
|
||||
"""
|
||||
|
||||
name: str = "create_multion_session"
|
||||
description: str = """
|
||||
Create a new web browsing session based on a user's command or request. \
|
||||
The command should include the full info required for the session. \
|
||||
Also include an url (defaults to google.com if no better option) \
|
||||
to start the session. \
|
||||
Use this tool to create a new Browser Window with provided fields. \
|
||||
Always the first step to run any activities that can be done using browser.
|
||||
"""
|
||||
args_schema: Type[CreateSessionSchema] = CreateSessionSchema
|
||||
|
||||
def _run(
|
||||
self,
|
||||
query: str,
|
||||
url: Optional[str] = "https://www.google.com/",
|
||||
run_manager: Optional[CallbackManagerForToolRun] = None,
|
||||
) -> dict:
|
||||
try:
|
||||
response = multion.new_session({"input": query, "url": url})
|
||||
return {
|
||||
"sessionId": response["session_id"],
|
||||
"Response": response["message"],
|
||||
}
|
||||
except Exception as e:
|
||||
raise Exception(f"An error occurred: {e}")
|
||||
@@ -0,0 +1,74 @@
|
||||
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 UpdateSessionSchema(BaseModel):
|
||||
"""Input for UpdateSessionTool."""
|
||||
|
||||
sessionId: str = Field(
|
||||
...,
|
||||
description="""The sessionID,
|
||||
received from one of the createSessions run before""",
|
||||
)
|
||||
query: str = Field(
|
||||
...,
|
||||
description="The query to run in multion agent.",
|
||||
)
|
||||
url: str = Field(
|
||||
"https://www.google.com/",
|
||||
description="""The Url to run the agent at. \
|
||||
Note: accepts only secure links having https://""",
|
||||
)
|
||||
|
||||
|
||||
class MultionUpdateSession(BaseTool):
|
||||
"""Tool that updates an existing Multion Browser Window with provided fields.
|
||||
|
||||
Attributes:
|
||||
name: The name of the tool. Default: "update_multion_session"
|
||||
description: The description of the tool.
|
||||
args_schema: The schema for the tool's arguments. Default: UpdateSessionSchema
|
||||
"""
|
||||
|
||||
name: str = "update_multion_session"
|
||||
description: str = """Use this tool to update \
|
||||
an existing corresponding Multion Browser Window with provided fields. \
|
||||
Note: sessionId must be received from previous Browser window creation."""
|
||||
args_schema: Type[UpdateSessionSchema] = UpdateSessionSchema
|
||||
sessionId: str = ""
|
||||
|
||||
def _run(
|
||||
self,
|
||||
sessionId: str,
|
||||
query: str,
|
||||
url: Optional[str] = "https://www.google.com/",
|
||||
run_manager: Optional[CallbackManagerForToolRun] = None,
|
||||
) -> dict:
|
||||
try:
|
||||
try:
|
||||
response = multion.update_session(
|
||||
sessionId, {"input": query, "url": url}
|
||||
)
|
||||
content = {"sessionId": sessionId, "Response": response["message"]}
|
||||
self.sessionId = sessionId
|
||||
return content
|
||||
except Exception as e:
|
||||
print(f"{e}, retrying...") # noqa: T201
|
||||
return {"error": f"{e}", "Response": "retrying..."}
|
||||
except Exception as e:
|
||||
raise Exception(f"An error occurred: {e}")
|
||||
Reference in New Issue
Block a user