mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-29 15:28:54 +00:00
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>
68 lines
2.1 KiB
Python
68 lines
2.1 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 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}")
|