id stringlengths 14 16 | text stringlengths 4 1.28k | source stringlengths 54 121 |
|---|---|---|
3872b4afaaf5-2 | )
try:
import azure.ai.vision as sdk
values["vision_service"] = sdk.VisionServiceOptions(
endpoint=azure_cogs_endpoint, key=azure_cogs_key
)
values["analysis_options"] = sdk.ImageAnalysisOptions()
values["analysis_options"].features = (... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/azure_cognitive_services/image_analysis.html |
3872b4afaaf5-3 | except ImportError:
pass
image_src_type = detect_file_src_type(image_path)
if image_src_type == "local":
vision_source = sdk.VisionSource(filename=image_path)
elif image_src_type == "remote":
vision_source = sdk.VisionSource(url=image_path)
else:
... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/azure_cognitive_services/image_analysis.html |
3872b4afaaf5-4 | 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_details = sdk.ImageAnalysisErrorDetails.from_result(result)
... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/azure_cognitive_services/image_analysis.html |
3872b4afaaf5-5 | ):
formatted_result.append(
"Objects: " + ", ".join(image_analysis_result["objects"])
)
if "tags" in image_analysis_result and len(image_analysis_result["tags"]) > 0:
formatted_result.append("Tags: " + ", ".join(image_analysis_result["tags"]))
if "text... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/azure_cognitive_services/image_analysis.html |
3872b4afaaf5-6 | 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"Error while running AzureCogsImageAnalysisTool: {e}")
async def _arun(
s... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/azure_cognitive_services/image_analysis.html |
26d318be4564-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 |
26d318be4564-1 | """
azure_cogs_key: str = "" #: :meta private:
azure_cogs_region: str = "" #: :meta private:
speech_language: str = "en-US" #: :meta private:
speech_config: Any #: :meta private:
name = "azure_cognitive_services_speech2text"
description = (
"A wrapper around Azure Cognitive Services ... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/azure_cognitive_services/speech2text.html |
26d318be4564-2 | )
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(
subscription=azure_cogs_key, region=azure_c... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/azure_cognitive_services/speech2text.html |
26d318be4564-3 | nonlocal done
done = True
def retrieve_cb(evt: Any) -> None:
"""callback that retrieves the intermediate recognition results"""
nonlocal text
text += evt.result.text
# retrieve text on recognized events
speech_recognizer.recognized.connect(retrieve... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/azure_cognitive_services/speech2text.html |
26d318be4564-4 | 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":
tmp_audio_path = download_audio_from_url(audio_path)
... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/azure_cognitive_services/speech2text.html |
26d318be4564-5 | try:
text = self._speech2text(query, self.speech_language)
return text
except Exception as e:
raise RuntimeError(f"Error while running AzureCogsSpeech2TextTool: {e}")
async def _arun(
self,
query: str,
run_manager: Optional[AsyncCallbackManagerForT... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/azure_cognitive_services/speech2text.html |
ba29c0648289-0 | Source code for langchain.tools.sql_database.tool
# flake8: noqa
"""Tools for interacting with a SQL database."""
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 (
AsyncC... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/sql_database/tool.html |
ba29c0648289-1 | # See https://github.com/pydantic/pydantic/issues/4173
class Config(BaseTool.Config):
"""Configuration for this pydantic object."""
arbitrary_types_allowed = True
extra = Extra.forbid
[docs]class QuerySQLDataBaseTool(BaseSQLDatabaseTool, BaseTool):
"""Tool for querying a SQL database."""... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/sql_database/tool.html |
ba29c0648289-2 | ) -> str:
"""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 ... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/sql_database/tool.html |
ba29c0648289-3 | table_names: str,
run_manager: Optional[CallbackManagerForToolRun] = None,
) -> str:
"""Get the schema for tables in a comma-separated list."""
return self.db.get_table_info_no_throw(table_names.split(", "))
async def _arun(
self,
table_name: str,
run_manager: Opt... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/sql_database/tool.html |
ba29c0648289-4 | 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_manager: Optional[AsyncCallbackM... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/sql_database/tool.html |
ba29c0648289-5 | llm: BaseLanguageModel
llm_chain: LLMChain = Field(init=False)
name = "sql_db_query_checker"
description = """
Use this tool to double check if your query is correct before executing it.
Always use this tool before executing a query with query_sql_db!
"""
@root_validator(pre=True)
def in... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/sql_database/tool.html |
ba29c0648289-6 | raise ValueError(
"LLM chain for QueryCheckerTool must have input variables ['query', 'dialect']"
)
return values
def _run(
self,
query: str,
run_manager: Optional[CallbackManagerForToolRun] = None,
) -> str:
"""Use the LLM to check the query."... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/sql_database/tool.html |
da4a3c2574cf-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 |
da4a3c2574cf-1 | input_func: Callable = Field(default_factory=lambda: input)
def _run(
self,
query: str,
run_manager: Optional[CallbackManagerForToolRun] = None,
) -> str:
"""Use the Human input tool."""
self.prompt_func(query)
return self.input_func()
async def _arun(
... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/human/tool.html |
104f26a0adc0-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 |
104f26a0adc0-1 | # See https://github.com/pydantic/pydantic/issues/4173
class Config(BaseTool.Config):
"""Configuration for this pydantic object."""
arbitrary_types_allowed = True
extra = Extra.forbid
[docs]class QuerySparkSQLTool(BaseSparkSQLTool, BaseTool):
"""Tool for querying a Spark SQL."""
name... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/spark_sql/tool.html |
104f26a0adc0-2 | ) -> str:
"""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 ... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/spark_sql/tool.html |
104f26a0adc0-3 | def _run(
self,
table_names: str,
run_manager: Optional[CallbackManagerForToolRun] = None,
) -> str:
"""Get the schema for tables in a comma-separated list."""
return self.db.get_table_info_no_throw(table_names.split(", "))
async def _arun(
self,
table_nam... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/spark_sql/tool.html |
104f26a0adc0-4 | 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 |
104f26a0adc0-5 | template: str = QUERY_CHECKER
llm: BaseLanguageModel
llm_chain: LLMChain = Field(init=False)
name = "query_checker_sql_db"
description = """
Use this tool to double check if your query is correct before executing it.
Always use this tool before executing a query with query_sql_db!
"""
@r... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/spark_sql/tool.html |
104f26a0adc0-6 | 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 |
4eeba15e2c5a-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 |
1460c7980afb-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 |
1460c7980afb-1 | self,
query: str,
run_manager: Optional[CallbackManagerForToolRun] = None,
) -> str:
"""Use the Wikipedia tool."""
return self.api_wrapper.run(query)
async def _arun(
self,
query: str,
run_manager: Optional[AsyncCallbackManagerForToolRun] = None,
) -> ... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/wikipedia/tool.html |
977174373901-0 | Source code for langchain.tools.zapier.tool
"""## Zapier Natural Language Actions API
\
Full docs here: https://nla.zapier.com/api/v1/docs
**Zapier Natural Language Actions** gives you access to the 5k+ apps, 20k+ actions
on Zapier's platform through a natural language API interface.
NLA supports apps like Gmail, Sales... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/zapier/tool.html |
977174373901-1 | 1. Server-side (API Key): for quickly getting started, testing, and production scenarios
where LangChain will only use actions exposed in the developer's Zapier account
(and will use the developer's connected accounts on Zapier.com)
2. User-facing (Oauth): for production scenarios where you are deploying an end... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/zapier/tool.html |
977174373901-2 | 3. Use NLA to send the draft reply (2) to someone in Slack via direct message
In code, below:
```python
import os
# get from https://platform.openai.com/
os.environ["OPENAI_API_KEY"] = os.environ.get("OPENAI_API_KEY", "")
# get from https://nla.zapier.com/demo/provider/debug
# (under User Information, after logging in)... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/zapier/tool.html |
977174373901-3 | # https://nla.zapier.com/demo/start
# -- for this example, can leave all fields "Have AI guess"
# in an oauth scenario, you'd get your own <provider> id (instead of 'demo')
# which you route your users through first
llm = OpenAI(temperature=0)
zapier = ZapierNLAWrapper()
## To leverage a nla_oauth_access_token yo... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/zapier/tool.html |
977174373901-4 | verbose=True
)
agent.run(("Summarize the last email I received regarding Silicon Valley Bank. "
"Send the summary to the #test-zapier channel in slack."))
```
"""
from typing import Any, Dict, Optional
from pydantic import Field, root_validator
from langchain.callbacks.manager import (
AsyncCallbackManagerForTo... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/zapier/tool.html |
977174373901-5 | (eg. "get the latest email from Mike Knoop" for "Gmail: find email" action)
params: a dict, optional. Any params provided will *override* AI guesses
from `instructions` (see "understanding the AI guessing flow" here:
https://nla.zapier.com/api/v1/docs)
"""
api_wrapper: ZapierNLAW... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/zapier/tool.html |
977174373901-6 | zapier_description = values["zapier_description"]
params_schema = values["params_schema"]
if "instructions" in params_schema:
del params_schema["instructions"]
# Ensure base prompt (if overrided) contains necessary input fields
necessary_fields = {"{zapier_description}", "{pa... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/zapier/tool.html |
977174373901-7 | return values
def _run(
self, instructions: str, run_manager: Optional[CallbackManagerForToolRun] = None
) -> str:
"""Use the Zapier NLA tool to return a list of all exposed user actions."""
return self.api_wrapper.run_as_str(self.action_id, instructions, self.params)
async def _arun... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/zapier/tool.html |
977174373901-8 | )
# other useful actions
[docs]class ZapierNLAListActions(BaseTool):
"""
Args:
None
"""
name = "ZapierNLA_list_actions"
description = BASE_ZAPIER_TOOL_PROMPT + (
"This tool returns a list of the user's exposed actions."
)
api_wrapper: ZapierNLAWrapper = Field(default_factory=... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/zapier/tool.html |
977174373901-9 | self,
_: str = "",
run_manager: Optional[AsyncCallbackManagerForToolRun] = None,
) -> str:
"""Use the Zapier NLA tool to return a list of all exposed user actions."""
raise NotImplementedError("ZapierNLAListActions does not support async")
ZapierNLAListActions.__doc__ = (
ZapierN... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/zapier/tool.html |
ef8ddcde88fd-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 |
ef8ddcde88fd-1 | file_path: str,
run_manager: Optional[CallbackManagerForToolRun] = None,
) -> str:
try:
read_path = self.get_relative_path(file_path)
except FileValidationError:
return INVALID_PATH_TEMPLATE.format(arg_name="file_path", value=file_path)
if not read_path.exists... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/file_management/read.html |
69742ca7c950-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 |
69742ca7c950-1 | description: str = "Move or rename a file from one location to another"
def _run(
self,
source_path: str,
destination_path: str,
run_manager: Optional[CallbackManagerForToolRun] = None,
) -> str:
try:
source_path_ = self.get_relative_path(source_path)
... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/file_management/move.html |
69742ca7c950-2 | 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,
source_path: str,
destination_path: str,
run_manager: ... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/file_management/move.html |
36fad131884d-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 |
36fad131884d-1 | name: str = "file_search"
args_schema: Type[BaseModel] = FileSearchInput
description: str = (
"Recursively search for files in a subdirectory that match the regex pattern"
)
def _run(
self,
pattern: str,
dir_path: str = ".",
run_manager: Optional[CallbackManagerFo... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/file_management/file_search.html |
36fad131884d-2 | relative_path = os.path.relpath(absolute_path, dir_path_)
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:
... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/file_management/file_search.html |
44d2f9b472bb-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 |
44d2f9b472bb-1 | description: str = "Create a copy of a file in a specified location"
def _run(
self,
source_path: str,
destination_path: str,
run_manager: Optional[CallbackManagerForToolRun] = None,
) -> str:
try:
source_path_ = self.get_relative_path(source_path)
exc... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/file_management/copy.html |
44d2f9b472bb-2 | 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 |
ea5ce2ab5b00-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 |
ea5ce2ab5b00-1 | name: str = "write_file"
args_schema: Type[BaseModel] = WriteFileInput
description: str = "Write file to disk"
def _run(
self,
file_path: str,
text: str,
append: bool = False,
run_manager: Optional[CallbackManagerForToolRun] = None,
) -> str:
try:
... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/file_management/write.html |
ea5ce2ab5b00-2 | 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 |
f190cb54ec90-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 |
f190cb54ec90-1 | file_path: str,
run_manager: Optional[CallbackManagerForToolRun] = None,
) -> str:
try:
file_path_ = self.get_relative_path(file_path)
except FileValidationError:
return INVALID_PATH_TEMPLATE.format(arg_name="file_path", value=file_path)
if not file_path_.exis... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/file_management/delete.html |
47b5aa9d1f9d-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 |
47b5aa9d1f9d-1 | def _run(
self,
dir_path: str = ".",
run_manager: Optional[CallbackManagerForToolRun] = None,
) -> str:
try:
dir_path_ = self.get_relative_path(dir_path)
except FileValidationError:
return INVALID_PATH_TEMPLATE.format(arg_name="dir_path", value=dir_pat... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/file_management/list_dir.html |
070ebe271468-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 |
070ebe271468-1 | Example Input: query {{ allUsers {{ id, name, email }} }}\
""" # noqa: E501
class Config:
"""Configuration for this pydantic object."""
arbitrary_types_allowed = True
def _run(
self,
tool_input: str,
run_manager: Optional[CallbackManagerForToolRun] = None,
) -> s... | https://api.python.langchain.com/en/latest/_modules/langchain/tools/graphql/tool.html |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.