id
stringlengths
14
15
text
stringlengths
35
2.51k
source
stringlengths
61
154
1a735b9a8632-1
) return thread_data async def _arun( self, thread_id: str, run_manager: Optional[AsyncCallbackManagerForToolRun] = None, ) -> Dict: """Run the tool.""" raise NotImplementedError
https://api.python.langchain.com/en/latest/_modules/langchain/tools/gmail/get_thread.html
cecf4ce8f514-0
Source code for langchain.tools.gmail.get_message import base64 import email from typing import Dict, Optional, Type from pydantic import BaseModel, Field from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain.tools.gmail.base import GmailBaseTool f...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/gmail/get_message.html
cecf4ce8f514-1
"snippet": message_data["snippet"], "body": body, "subject": subject, "sender": sender, } async def _arun( self, message_id: str, run_manager: Optional[AsyncCallbackManagerForToolRun] = None, ) -> Dict: """Run the tool.""" raise...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/gmail/get_message.html
7d2e0e49621c-0
Source code for langchain.tools.gmail.create_draft import base64 from email.message import EmailMessage from typing import List, Optional, Type from pydantic import BaseModel, Field from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain.tools.gmail....
https://api.python.langchain.com/en/latest/_modules/langchain/tools/gmail/create_draft.html
7d2e0e49621c-1
draft_message["Subject"] = subject if cc is not None: draft_message["Cc"] = ", ".join(cc) if bcc is not None: draft_message["Bcc"] = ", ".join(bcc) encoded_message = base64.urlsafe_b64encode(draft_message.as_bytes()).decode() return {"message": {"raw": encoded_mes...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/gmail/create_draft.html
b32f87b91635-0
Source code for langchain.tools.gmail.base """Base class for Gmail tools.""" from __future__ import annotations from typing import TYPE_CHECKING from pydantic import Field from langchain.tools.base import BaseTool from langchain.tools.gmail.utils import build_resource_service if TYPE_CHECKING: # This is for linting...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/gmail/base.html
e6fc3ca16c57-0
Source code for langchain.tools.gmail.send_message """Send Gmail messages.""" import base64 from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from typing import Any, Dict, List, Optional, Union from pydantic import BaseModel, Field from langchain.callbacks.manager import ( AsyncCal...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/gmail/send_message.html
e6fc3ca16c57-1
"""Create a message for an email.""" mime_message = MIMEMultipart() mime_message.attach(MIMEText(message, "html")) mime_message["To"] = ", ".join(to if isinstance(to, list) else [to]) mime_message["Subject"] = subject if cc is not None: mime_message["Cc"] = ", ".join(...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/gmail/send_message.html
e6fc3ca16c57-2
to: Union[str, List[str]], subject: str, cc: Optional[Union[str, List[str]]] = None, bcc: Optional[Union[str, List[str]]] = None, run_manager: Optional[AsyncCallbackManagerForToolRun] = None, ) -> str: """Run the tool asynchronously.""" raise NotImplementedError(f"The...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/gmail/send_message.html
124b4ab75105-0
Source code for langchain.tools.graphql.tool import json from typing import Optional from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain.tools.base import BaseTool from langchain.utilities.graphql import GraphQLAPIWrapper [docs]class BaseGraphQLT...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/graphql/tool.html
bfe5f55efde3-0
Source code for langchain.tools.spark_sql.tool # flake8: noqa """Tools for interacting with Spark SQL.""" from typing import Any, Dict, Optional from pydantic import BaseModel, Extra, Field, root_validator from langchain.base_language import BaseLanguageModel from langchain.callbacks.manager import ( AsyncCallbackM...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/spark_sql/tool.html
bfe5f55efde3-1
"""Execute the query, return the results or an error message.""" return self.db.run_no_throw(query) async def _arun( self, query: str, run_manager: Optional[AsyncCallbackManagerForToolRun] = None, ) -> str: raise NotImplementedError("QuerySqlDbTool does not support async"...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/spark_sql/tool.html
bfe5f55efde3-2
def _run( self, tool_input: str = "", run_manager: Optional[CallbackManagerForToolRun] = None, ) -> str: """Get the schema for a specific table.""" return ", ".join(self.db.get_usable_table_names()) async def _arun( self, tool_input: str = "", run_...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/spark_sql/tool.html
bfe5f55efde3-3
raise ValueError( "LLM chain for QueryCheckerTool need to use ['query'] as input_variables " "for the embedded prompt" ) return values def _run( self, query: str, run_manager: Optional[CallbackManagerForToolRun] = None, ) -> str: ...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/spark_sql/tool.html
6bb2a9417ea7-0
Source code for langchain.tools.google_search.tool """Tool for the Google search API.""" from typing import Optional from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain.tools.base import BaseTool from langchain.utilities.google_search import Goog...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/google_search/tool.html
6bb2a9417ea7-1
api_wrapper: GoogleSearchAPIWrapper def _run( self, query: str, run_manager: Optional[CallbackManagerForToolRun] = None, ) -> str: """Use the tool.""" return str(self.api_wrapper.results(query, self.num_results)) async def _arun( self, query: str, ...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/google_search/tool.html
5dbf9c91ce12-0
Source code for langchain.tools.google_places.tool """Tool for the Google search API.""" from typing import Optional, Type from pydantic import BaseModel, Field from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain.tools.base import BaseTool from l...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/google_places/tool.html
ef3721a08bf7-0
Source code for langchain.tools.searx_search.tool """Tool for the SearxNG search API.""" from typing import Optional from pydantic import Extra from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain.tools.base import BaseTool, Field from langchain.u...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/searx_search/tool.html
ef3721a08bf7-1
"Useful for when you need to answer questions about current events." "Input should be a search query. Output is a JSON array of the query results" ) wrapper: SearxSearchWrapper num_results: int = 4 kwargs: dict = Field(default_factory=dict) [docs] class Config: """Pydantic config.""" ...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/searx_search/tool.html
8c0629ab0ac8-0
Source code for langchain.tools.json.tool # flake8: noqa """Tools for working with JSON specs.""" from __future__ import annotations import json import re from pathlib import Path from typing import Dict, List, Optional, Union from pydantic import BaseModel from langchain.callbacks.manager import ( AsyncCallbackMan...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/json/tool.html
8c0629ab0ac8-1
try: items = _parse_input(text) val = self.dict_ for i in items: if i: val = val[i] if not isinstance(val, dict): raise ValueError( f"Value at path `{text}` is not a dict, get the value directly." ...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/json/tool.html
8c0629ab0ac8-2
""" spec: JsonSpec def _run( self, tool_input: str, run_manager: Optional[CallbackManagerForToolRun] = None, ) -> str: return self.spec.keys(tool_input) async def _arun( self, tool_input: str, run_manager: Optional[AsyncCallbackManagerForToolRun] =...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/json/tool.html
11de45472249-0
Source code for langchain.tools.human.tool """Tool for asking human input.""" from typing import Callable, Optional from pydantic import Field from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain.tools.base import BaseTool def _print_func(text: st...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/human/tool.html
7a6e51a3ec42-0
Source code for langchain.tools.ddg_search.tool """Tool for the DuckDuckGo search API.""" import warnings from typing import Any, Optional from pydantic import Field from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain.tools.base import BaseTool f...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/ddg_search/tool.html
7a6e51a3ec42-1
description = ( "A wrapper around Duck Duck Go Search. " "Useful for when you need to answer questions about current events. " "Input should be a search query. Output is a JSON array of the query results" ) num_results: int = 4 api_wrapper: DuckDuckGoSearchAPIWrapper = Field( ...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/ddg_search/tool.html
e2075c2e12d4-0
Source code for langchain.tools.openweathermap.tool """Tool for the OpenWeatherMap API.""" from typing import Optional from pydantic import Field from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain.tools.base import BaseTool from langchain.utilit...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/openweathermap/tool.html
452998a9f00e-0
Source code for langchain.tools.interaction.tool """Tools for interacting with the user.""" import warnings from typing import Any from langchain.tools.human.tool import HumanInputRun [docs]def StdInInquireTool(*args: Any, **kwargs: Any) -> HumanInputRun: """Tool for asking the user for input.""" warnings.warn(...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/interaction/tool.html
391fa322fbd9-0
Source code for langchain.tools.youtube.search """ Adapted from https://github.com/venuv/langchain_yt_tools CustomYTSearchTool searches YouTube videos related to a person and returns a specified number of video URLs. Input to this tool should be a comma separated list, - the first part contains a person name - and th...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/youtube/search.html
391fa322fbd9-1
num_results = int(values[1]) else: num_results = 2 return self._search(person, num_results) async def _arun( self, query: str, run_manager: Optional[AsyncCallbackManagerForToolRun] = None, ) -> str: """Use the tool asynchronously.""" raise NotI...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/youtube/search.html
9499f6ad6036-0
Source code for langchain.tools.wikipedia.tool """Tool for the Wikipedia API.""" from typing import Optional from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain.tools.base import BaseTool from langchain.utilities.wikipedia import WikipediaAPIWrap...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/wikipedia/tool.html
8d812c1ddf58-0
Source code for langchain.tools.google_serper.tool """Tool for the Serper.dev Google Search API.""" from typing import Optional from pydantic.fields import Field from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain.tools.base import BaseTool from ...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/google_serper/tool.html
8d812c1ddf58-1
) api_wrapper: GoogleSerperAPIWrapper = Field(default_factory=GoogleSerperAPIWrapper) def _run( self, query: str, run_manager: Optional[CallbackManagerForToolRun] = None, ) -> str: """Use the tool.""" return str(self.api_wrapper.results(query)) async def _arun( ...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/google_serper/tool.html
ab76686547b3-0
Source code for langchain.tools.wolfram_alpha.tool """Tool for the Wolfram Alpha API.""" from typing import Optional from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain.tools.base import BaseTool from langchain.utilities.wolfram_alpha import Wolf...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/wolfram_alpha/tool.html
d7d2faaf24e3-0
Source code for langchain.tools.azure_cognitive_services.utils import os import tempfile from urllib.parse import urlparse import requests [docs]def detect_file_src_type(file_path: str) -> str: """Detect if the file is local or remote.""" if os.path.isfile(file_path): return "local" parsed_url = url...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/azure_cognitive_services/utils.html
4028e2425f09-0
Source code for langchain.tools.azure_cognitive_services.form_recognizer from __future__ import annotations import logging from typing import Any, Dict, List, Optional from pydantic import root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from ...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/azure_cognitive_services/form_recognizer.html
4028e2425f09-1
) azure_cogs_endpoint = get_from_dict_or_env( values, "azure_cogs_endpoint", "AZURE_COGS_ENDPOINT" ) try: from azure.ai.formrecognizer import DocumentAnalysisClient from azure.core.credentials import AzureKeyCredential values["doc_analysis_client"]...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/azure_cognitive_services/form_recognizer.html
4028e2425f09-2
"prebuilt-document", document ) elif document_src_type == "remote": poller = self.doc_analysis_client.begin_analyze_document_from_url( "prebuilt-document", document_path ) else: raise ValueError(f"Invalid document path: {document_path}"...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/azure_cognitive_services/form_recognizer.html
4028e2425f09-3
) -> str: """Use the tool.""" try: document_analysis_result = self._document_analysis(query) if not document_analysis_result: return "No good document analysis result was found" return self._format_document_analysis_result(document_analysis_result) ...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/azure_cognitive_services/form_recognizer.html
e62e2a0eeedc-0
Source code for langchain.tools.azure_cognitive_services.text2speech from __future__ import annotations import logging import tempfile from typing import Any, Dict, Optional from pydantic import root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, )...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/azure_cognitive_services/text2speech.html
e62e2a0eeedc-1
) try: import azure.cognitiveservices.speech as speechsdk values["speech_config"] = speechsdk.SpeechConfig( subscription=azure_cogs_key, region=azure_cogs_region ) except ImportError: raise ImportError( "azure-cognitiveservi...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/azure_cognitive_services/text2speech.html
e62e2a0eeedc-2
def _run( self, query: str, run_manager: Optional[CallbackManagerForToolRun] = None, ) -> str: """Use the tool.""" try: speech_file = self._text2speech(query, self.speech_language) return speech_file except Exception as e: raise Run...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/azure_cognitive_services/text2speech.html
dc1cfbb25756-0
Source code for langchain.tools.azure_cognitive_services.speech2text from __future__ import annotations import logging import time from typing import Any, Dict, Optional from pydantic import root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) fro...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/azure_cognitive_services/speech2text.html
dc1cfbb25756-1
values, "azure_cogs_key", "AZURE_COGS_KEY" ) azure_cogs_region = get_from_dict_or_env( values, "azure_cogs_region", "AZURE_COGS_REGION" ) try: import azure.cognitiveservices.speech as speechsdk values["speech_config"] = speechsdk.SpeechConfig( ...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/azure_cognitive_services/speech2text.html
dc1cfbb25756-2
try: import azure.cognitiveservices.speech as speechsdk except ImportError: pass audio_src_type = detect_file_src_type(audio_path) if audio_src_type == "local": audio_config = speechsdk.AudioConfig(filename=audio_path) elif audio_src_type == "remote": ...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/azure_cognitive_services/speech2text.html
fe89b7dad17b-0
Source code for langchain.tools.azure_cognitive_services.image_analysis from __future__ import annotations import logging from typing import Any, Dict, Optional from pydantic import root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langcha...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/azure_cognitive_services/image_analysis.html
fe89b7dad17b-1
values, "azure_cogs_endpoint", "AZURE_COGS_ENDPOINT" ) try: import azure.ai.vision as sdk values["vision_service"] = sdk.VisionServiceOptions( endpoint=azure_cogs_endpoint, key=azure_cogs_key ) values["analysis_options"] = sdk.ImageAnalysis...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/azure_cognitive_services/image_analysis.html
fe89b7dad17b-2
res_dict["objects"] = [obj.name for obj in result.objects] if result.tags is not None: res_dict["tags"] = [tag.name for tag in result.tags] if result.text is not None: res_dict["text"] = [line.content for line in result.text.lines] else: error_...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/azure_cognitive_services/image_analysis.html
fe89b7dad17b-3
try: image_analysis_result = self._image_analysis(query) if not image_analysis_result: return "No good image analysis result was found" return self._format_image_analysis_result(image_analysis_result) except Exception as e: raise RuntimeError(f"Err...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/azure_cognitive_services/image_analysis.html
9fd5f2a4f3d3-0
Source code for langchain.tools.openapi.utils.api_models """Pydantic models for parsing an OpenAPI spec.""" import logging from enum import Enum from typing import Any, Dict, List, Optional, Sequence, Tuple, Type, Union from openapi_schema_pydantic import MediaType, Parameter, Reference, RequestBody, Schema from pydant...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/openapi/utils/api_models.html
9fd5f2a4f3d3-1
'Unsupported APIPropertyLocation "{location}"' " for parameter {name}. " + f"Valid values are {[loc.value for loc in SUPPORTED_LOCATIONS]}" ) SCHEMA_TYPE = Union[str, Type, tuple, None, Enum] [docs]class APIPropertyBase(BaseModel): """Base model for an API property.""" # The name of the parameter is req...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/openapi/utils/api_models.html
9fd5f2a4f3d3-2
"""The path/how it's being passed to the endpoint.""" @staticmethod def _cast_schema_list_type(schema: Schema) -> Optional[Union[str, Tuple[str, ...]]]: type_ = schema.type if not isinstance(type_, list): return type_ else: return tuple(type_) @staticmethod ...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/openapi/utils/api_models.html
9fd5f2a4f3d3-3
raise NotImplementedError("Objects not yet supported") elif schema_type in PRIMITIVE_TYPES: if schema.enum: schema_type = APIProperty._get_schema_type_for_enum(parameter, schema) else: # Directly use the primitive type pass else: ...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/openapi/utils/api_models.html
9fd5f2a4f3d3-4
location = APIPropertyLocation.from_str(parameter.param_in) cls._validate_location( location, parameter.name, ) cls._validate_content(parameter.content) schema = cls._get_schema(parameter, spec) schema_type = cls._get_schema_type(parameter, schema) ...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/openapi/utils/api_models.html
9fd5f2a4f3d3-5
prop_schema = spec.get_referenced_schema(prop_schema) else: continue properties.append( cls.from_schema( schema=prop_schema, name=prop_name, required=prop_name in required_props, ...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/openapi/utils/api_models.html
9fd5f2a4f3d3-6
references_used = [] schema_type = schema.type properties: List[APIRequestBodyProperty] = [] if schema_type == "object" and schema.properties: schema_type, properties = cls._process_object_schema( schema, spec, references_used ) elif schema_type ==...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/openapi/utils/api_models.html
9fd5f2a4f3d3-7
schema = media_type_obj.media_type_schema if isinstance(schema, Reference): references_used.append(schema.ref.split("/")[-1]) schema = spec.get_referenced_schema(schema) if schema is None: raise ValueError( f"Could not resolve schema for media type: {m...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/openapi/utils/api_models.html
9fd5f2a4f3d3-8
return cls( description=request_body.description, properties=properties, media_type=media_type, ) [docs]class APIOperation(BaseModel): """A model for a single API operation.""" operation_id: str = Field(alias="operation_id") """The unique identifier of the operati...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/openapi/utils/api_models.html
9fd5f2a4f3d3-9
) else: logger.warning( INVALID_LOCATION_TEMPL.format( location=param.param_in, name=param.name ) + " Ignoring optional parameter" ) pass return properties [docs] @c...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/openapi/utils/api_models.html
9fd5f2a4f3d3-10
properties=properties, request_body=api_request_body, ) [docs] @staticmethod def ts_type_from_python(type_: SCHEMA_TYPE) -> str: if type_ is None: # TODO: Handle Nones better. These often result when # parsing specs that are < v3 return "any" ...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/openapi/utils/api_models.html
9fd5f2a4f3d3-11
) return "\n".join(formatted_props) [docs] def to_typescript(self) -> str: """Get typescript string representation of the operation.""" operation_name = self.operation_id params = [] if self.request_body: formatted_request_body_props = self._format_nested_propertie...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/openapi/utils/api_models.html
28a8b85d3ce3-0
Source code for langchain.tools.playwright.extract_text from __future__ import annotations from typing import Optional, Type from pydantic import BaseModel, root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain.tools.playwright.base ...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/playwright/extract_text.html
28a8b85d3ce3-1
async def _arun( self, run_manager: Optional[AsyncCallbackManagerForToolRun] = None ) -> str: """Use the tool.""" if self.async_browser is None: raise ValueError(f"Asynchronous browser not provided to {self.name}") # Use Beautiful Soup since it's faster than looping throu...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/playwright/extract_text.html
6918288cb21d-0
Source code for langchain.tools.playwright.utils """Utilities for the Playwright browser tools.""" from __future__ import annotations import asyncio from typing import TYPE_CHECKING, Any, Coroutine, TypeVar if TYPE_CHECKING: from playwright.async_api import Browser as AsyncBrowser from playwright.async_api impo...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/playwright/utils.html
6918288cb21d-1
return context.pages[-1] [docs]def create_async_playwright_browser(headless: bool = True) -> AsyncBrowser: """ Create a async playwright browser. Args: headless: Whether to run the browser in headless mode. Defaults to True. Returns: AsyncBrowser: The playwright browser. """ from...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/playwright/utils.html
46488152fb9d-0
Source code for langchain.tools.playwright.extract_hyperlinks from __future__ import annotations import json from typing import TYPE_CHECKING, Any, Optional, Type from pydantic import BaseModel, Field, root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToo...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/playwright/extract_hyperlinks.html
46488152fb9d-1
soup = BeautifulSoup(html_content, "lxml") # Find all the anchor elements and extract their href attributes anchors = soup.find_all("a") if absolute_urls: base_url = page.url links = [urljoin(base_url, anchor.get("href", "")) for anchor in anchors] else: ...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/playwright/extract_hyperlinks.html
9ab7688ab9e7-0
Source code for langchain.tools.playwright.navigate_back from __future__ import annotations from typing import Optional, Type from pydantic import BaseModel from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain.tools.playwright.base import BaseBrow...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/playwright/navigate_back.html
9ab7688ab9e7-1
response = await page.go_back() if response: return ( f"Navigated back to the previous page with URL '{response.url}'." f" Status code {response.status}" ) else: return "Unable to navigate back; no previous page in the history"
https://api.python.langchain.com/en/latest/_modules/langchain/tools/playwright/navigate_back.html
1a3569fbdb7a-0
Source code for langchain.tools.playwright.navigate from __future__ import annotations from typing import Optional, Type from pydantic import BaseModel, Field from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain.tools.playwright.base import BaseBr...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/playwright/navigate.html
1a3569fbdb7a-1
response = await page.goto(url) status = response.status if response else "unknown" return f"Navigating to {url} returned status code {status}"
https://api.python.langchain.com/en/latest/_modules/langchain/tools/playwright/navigate.html
9be64c2b81e2-0
Source code for langchain.tools.playwright.get_elements from __future__ import annotations import json from typing import TYPE_CHECKING, List, Optional, Sequence, Type from pydantic import BaseModel, Field from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) fro...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/playwright/get_elements.html
9be64c2b81e2-1
) -> List[dict]: """Get elements matching the given CSS selector.""" elements = page.query_selector_all(selector) results = [] for element in elements: result = {} for attribute in attributes: if attribute == "innerText": val: Optional[str] = element.inner_tex...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/playwright/get_elements.html
9be64c2b81e2-2
raise ValueError(f"Asynchronous browser not provided to {self.name}") page = await aget_current_page(self.async_browser) # Navigate to the desired webpage before using this tool results = await _aget_elements(page, selector, attributes) return json.dumps(results, ensure_ascii=False)
https://api.python.langchain.com/en/latest/_modules/langchain/tools/playwright/get_elements.html
58c85248a116-0
Source code for langchain.tools.playwright.base from __future__ import annotations from typing import TYPE_CHECKING, Optional, Tuple, Type from pydantic import root_validator from langchain.tools.base import BaseTool if TYPE_CHECKING: from playwright.async_api import Browser as AsyncBrowser from playwright.sync...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/playwright/base.html
58c85248a116-1
raise ValueError("Either async_browser or sync_browser must be specified.") return values [docs] @classmethod def from_browser( cls, sync_browser: Optional[SyncBrowser] = None, async_browser: Optional[AsyncBrowser] = None, ) -> BaseBrowserTool: """Instantiate the tool....
https://api.python.langchain.com/en/latest/_modules/langchain/tools/playwright/base.html
f9c66e8653f3-0
Source code for langchain.tools.playwright.current_page from __future__ import annotations from typing import Optional, Type from pydantic import BaseModel from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain.tools.playwright.base import BaseBrows...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/playwright/current_page.html
2cc0da41cdcb-0
Source code for langchain.tools.playwright.click from __future__ import annotations from typing import Optional, Type from pydantic import BaseModel, Field from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain.tools.playwright.base import BaseBrows...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/playwright/click.html
2cc0da41cdcb-1
# Navigate to the desired webpage before using this tool selector_effective = self._selector_effective(selector=selector) from playwright.sync_api import TimeoutError as PlaywrightTimeoutError try: page.click( selector_effective, strict=self.playwright...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/playwright/click.html
c198df582014-0
Source code for langchain.tools.shell.tool import asyncio import platform import warnings from typing import List, Optional, Type, Union from pydantic import BaseModel, Field, root_validator from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain.too...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/shell/tool.html
c198df582014-1
name: str = "terminal" """Name of tool.""" description: str = f"Run shell commands on this {_get_platform()} machine." """Description of tool.""" args_schema: Type[BaseModel] = ShellInput """Schema for input arguments.""" def _run( self, commands: Union[str, List[str]], r...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/shell/tool.html
93cf69b51c00-0
Source code for langchain.tools.metaphor_search.tool """Tool for the Metaphor search API.""" from typing import Dict, List, Optional, Union from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain.tools.base import BaseTool from langchain.utilities.me...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/metaphor_search/tool.html
93cf69b51c00-1
return repr(e) async def _arun( self, query: str, num_results: int, include_domains: Optional[List[str]] = None, exclude_domains: Optional[List[str]] = None, start_crawl_date: Optional[str] = None, end_crawl_date: Optional[str] = None, start_published_...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/metaphor_search/tool.html
5df74d70d560-0
Source code for langchain.tools.scenexplain.tool """Tool for the SceneXplain API.""" from typing import Optional from pydantic import BaseModel, Field from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain.tools.base import BaseTool from langchain.u...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/scenexplain/tool.html
8dd6ed266abc-0
Source code for langchain.tools.file_management.utils import sys from pathlib import Path from typing import Optional from pydantic import BaseModel [docs]def is_relative_to(path: Path, root: Path) -> bool: """Check if path is relative to root.""" if sys.version_info >= (3, 9): # No need for a try/excep...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/file_management/utils.html
8dd6ed266abc-1
if not is_relative_to(full_path, root): raise FileValidationError( f"Path {user_path} is outside of the allowed directory {root}" ) return full_path
https://api.python.langchain.com/en/latest/_modules/langchain/tools/file_management/utils.html
a3da68b1acc7-0
Source code for langchain.tools.file_management.read from typing import Optional, Type from pydantic import BaseModel, Field from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain.tools.base import BaseTool from langchain.tools.file_management.utils...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/file_management/read.html
fe89cc7ff80f-0
Source code for langchain.tools.file_management.copy import shutil from typing import Optional, Type from pydantic import BaseModel, Field from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain.tools.base import BaseTool from langchain.tools.file_ma...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/file_management/copy.html
fe89cc7ff80f-1
except Exception as e: return "Error: " + str(e) async def _arun( self, source_path: str, destination_path: str, run_manager: Optional[AsyncCallbackManagerForToolRun] = None, ) -> str: # TODO: Add aiofiles method raise NotImplementedError
https://api.python.langchain.com/en/latest/_modules/langchain/tools/file_management/copy.html
f4c48d19e1c0-0
Source code for langchain.tools.file_management.list_dir import os from typing import Optional, Type from pydantic import BaseModel, Field from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain.tools.base import BaseTool from langchain.tools.file_ma...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/file_management/list_dir.html
b6baef693c51-0
Source code for langchain.tools.file_management.move import shutil from typing import Optional, Type from pydantic import BaseModel, Field from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain.tools.base import BaseTool from langchain.tools.file_ma...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/file_management/move.html
b6baef693c51-1
try: # shutil.move expects str args in 3.8 shutil.move(str(source_path_), destination_path_) return f"File moved successfully from {source_path} to {destination_path}." except Exception as e: return "Error: " + str(e) async def _arun( self, sou...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/file_management/move.html
c3cb3b6bf9bd-0
Source code for langchain.tools.file_management.write from typing import Optional, Type from pydantic import BaseModel, Field from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain.tools.base import BaseTool from langchain.tools.file_management.util...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/file_management/write.html
c3cb3b6bf9bd-1
except Exception as e: return "Error: " + str(e) async def _arun( self, file_path: str, text: str, append: bool = False, run_manager: Optional[AsyncCallbackManagerForToolRun] = None, ) -> str: # TODO: Add aiofiles method raise NotImplementedErr...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/file_management/write.html
8bc6fda779eb-0
Source code for langchain.tools.file_management.delete import os from typing import Optional, Type from pydantic import BaseModel, Field from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain.tools.base import BaseTool from langchain.tools.file_mana...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/file_management/delete.html
7e77a6af34f5-0
Source code for langchain.tools.file_management.file_search import fnmatch import os from typing import Optional, Type from pydantic import BaseModel, Field from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain.tools.base import BaseTool from langc...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/file_management/file_search.html
7e77a6af34f5-1
matches.append(relative_path) if matches: return "\n".join(matches) else: return f"No files found for pattern {pattern} in directory {dir_path}" except Exception as e: return "Error: " + str(e) async def _arun( self, dir_pat...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/file_management/file_search.html
1d81dac07857-0
Source code for langchain.tools.requests.tool # flake8: noqa """Tools for making requests to an API endpoint.""" import json from typing import Any, Dict, Optional from pydantic import BaseModel from langchain.callbacks.manager import ( AsyncCallbackManagerForToolRun, CallbackManagerForToolRun, ) from langchain...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/requests/tool.html
1d81dac07857-1
[docs]class RequestsPostTool(BaseRequestsTool, BaseTool): """Tool for making a POST request to an API endpoint.""" name = "requests_post" description = """Use this when you want to POST to a website. Input should be a json string with two keys: "url" and "data". The value of "url" should be a string...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/requests/tool.html
1d81dac07857-2
Input should be a json string with two keys: "url" and "data". The value of "url" should be a string, and the value of "data" should be a dictionary of key-value pairs you want to PATCH to the url. Be careful to always use double quotes for strings in the json string The output will be the text respons...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/requests/tool.html
1d81dac07857-3
key-value pairs you want to PUT to the url. Be careful to always use double quotes for strings in the json string. The output will be the text response of the PUT request. """ def _run( self, text: str, run_manager: Optional[CallbackManagerForToolRun] = None ) -> str: """Run the tool...
https://api.python.langchain.com/en/latest/_modules/langchain/tools/requests/tool.html