Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

langchain_community: Added Missing Schema for Community Tools #16229

Closed
wants to merge 11 commits into from
9 changes: 8 additions & 1 deletion libs/community/langchain_community/tools/bing_search/tool.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
"""Tool for the Bing search API."""

from typing import Optional
from typing import Optional, Type

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

from langchain_community.utilities.bing_search import BingSearchAPIWrapper


class BingSearchInput(BaseModel):
query: str = Field(description="should be a search query")


class BingSearchRun(BaseTool):
"""Tool that queries the Bing search API."""

Expand All @@ -18,6 +23,7 @@ class BingSearchRun(BaseTool):
"Input should be a search query."
)
api_wrapper: BingSearchAPIWrapper
args_schema: Type[BingSearchInput] = BingSearchInput

def _run(
self,
Expand All @@ -39,6 +45,7 @@ class BingSearchResults(BaseTool):
)
num_results: int = 4
api_wrapper: BingSearchAPIWrapper
args_schema: Type[BaseModel] = BingSearchInput

def _run(
self,
Expand Down
12 changes: 9 additions & 3 deletions libs/community/langchain_community/tools/brave_search/tool.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
from __future__ import annotations

from typing import Any, Optional
from typing import Any, Optional, Type

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

from langchain_community.utilities.brave_search import BraveSearchWrapper


class BraveSearchInput(BaseModel):
query: str = Field(description="should be a search query")


class BraveSearch(BaseTool):
"""Tool that queries the BraveSearch."""

name: str = "brave_search"
description: str = (
"a search engine. "
"a search engine."
"useful for when you need to answer questions about current events."
" input should be a search query."
"input should be a search query."
)
search_wrapper: BraveSearchWrapper
args_schema: Type[BraveSearchInput] = BraveSearchInput

@classmethod
def from_api_key(
Expand Down
15 changes: 10 additions & 5 deletions libs/community/langchain_community/tools/clickup/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,27 @@
toolkit = ClickupToolkit.from_clickup_api_wrapper(clickup)
```
"""
from typing import Optional
from typing import Optional, Type

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

from langchain_community.utilities.clickup import ClickupAPIWrapper


class ClickupActionInput(BaseModel):
instructions: str = Field(description="Instructions for the Click Up Action")


class ClickupAction(BaseTool):
"""Tool that queries the Clickup API."""
"""Tool that queries the Clickup API."""

api_wrapper: ClickupAPIWrapper = Field(default_factory=ClickupAPIWrapper)
mode: str
name: str = ""
description: str = ""
name: str = "clickup_action"
description: str = "Tool to execute action on ClickUp"
args_schema: Type[ClickupActionInput] = ClickupActionInput

def _run(
self,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
"""Tool for the DataForSeo SERP API."""

from typing import Optional
from typing import Optional, Type

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

from langchain_community.utilities.dataforseo_api_search import DataForSeoAPIWrapper


class DataForSeoAPISearchInput(BaseModel):
query: str = Field(description="should be a search query")


class DataForSeoAPISearchRun(BaseTool):
"""Tool that queries the DataForSeo Google search API."""

Expand All @@ -22,6 +26,7 @@ class DataForSeoAPISearchRun(BaseTool):
"or current events."
)
api_wrapper: DataForSeoAPIWrapper
args_schema: Type[DataForSeoAPISearchInput] = DataForSeoAPISearchInput

def _run(
self,
Expand Down Expand Up @@ -53,6 +58,7 @@ class DataForSeoAPISearchResults(BaseTool):
"of the query results."
)
api_wrapper: DataForSeoAPIWrapper = Field(default_factory=DataForSeoAPIWrapper)
args_schema: Type[BaseModel] = DataForSeoAPISearchInput

def _run(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DuckDuckGoSearchRun(BaseTool):
api_wrapper: DuckDuckGoSearchAPIWrapper = Field(
default_factory=DuckDuckGoSearchAPIWrapper
)
args_schema: Type[BaseModel] = DDGInput
args_schema: Type[DDGInput] = DDGInput

def _run(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class E2BDataAnalysisTool(BaseTool):
"""Tool for running python code in a sandboxed environment for data analysis."""

name = "e2b_data_analysis"
args_schema: Type[BaseModel] = E2BDataAnalysisToolArguments
args_schema: Type[E2BDataAnalysisToolArguments] = E2BDataAnalysisToolArguments
session: Any
description: str
_uploaded_files: List[UploadedFile] = PrivateAttr(default_factory=list)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@

import logging
from abc import abstractmethod
from typing import Any, Dict, List, Optional
from typing import Any, Dict, List, Optional, Type

import requests
from langchain_core.callbacks import CallbackManagerForToolRun
from langchain_core.pydantic_v1 import root_validator
from langchain_core.pydantic_v1 import BaseModel, Field, root_validator
from langchain_core.tools import BaseTool
from langchain_core.utils import get_from_dict_or_env


class EdenAiInput(BaseModel):
query: str = Field(description="should be a search query")


logger = logging.getLogger(__name__)


Expand All @@ -29,6 +34,7 @@ class EdenaiTool(BaseTool):

providers: List[str]
"""provider to use for the API call."""
args_schema: Type[EdenAiInput] = EdenAiInput

@root_validator(allow_reuse=True)
def validate_environment(cls, values: Dict) -> Dict:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import tempfile
from enum import Enum
from typing import Any, Dict, Optional, Union
from typing import Any, Dict, Optional, Type, Union

from langchain_core.callbacks import CallbackManagerForToolRun
from langchain_core.pydantic_v1 import root_validator
from langchain_core.pydantic_v1 import BaseModel, Field, root_validator
from langchain_core.tools import BaseTool
from langchain_core.utils import get_from_dict_or_env

Expand All @@ -18,6 +18,10 @@ def _import_elevenlabs() -> Any:
return elevenlabs


class ElevenLabsText2SpeechToolInput(BaseModel):
query: str = Field(description="Text that needs to be converted to speech")


class ElevenLabsModel(str, Enum):
"""Models available for Eleven Labs Text2Speech."""

Expand All @@ -41,6 +45,7 @@ class ElevenLabsText2SpeechTool(BaseTool):
"It supports multiple languages, including English, German, Polish, "
"Spanish, Italian, French, Portuguese, and Hindi. "
)
args_schema: Type[ElevenLabsText2SpeechToolInput] = ElevenLabsText2SpeechToolInput

@root_validator(pre=True)
def validate_environment(cls, values: Dict) -> Dict:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CopyFileTool(BaseFileToolMixin, BaseTool):
"""Tool that copies a file."""

name: str = "copy_file"
args_schema: Type[BaseModel] = FileCopyInput
args_schema: Type[FileCopyInput] = FileCopyInput
description: str = "Create a copy of a file in a specified location"

def _run(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DeleteFileTool(BaseFileToolMixin, BaseTool):
"""Tool that deletes a file."""

name: str = "file_delete"
args_schema: Type[BaseModel] = FileDeleteInput
args_schema: Type[FileDeleteInput] = FileDeleteInput
description: str = "Delete a file"

def _run(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class FileSearchTool(BaseFileToolMixin, BaseTool):
"""Tool that searches for files in a subdirectory that match a regex pattern."""

name: str = "file_search"
args_schema: Type[BaseModel] = FileSearchInput
args_schema: Type[FileSearchInput] = FileSearchInput
description: str = (
"Recursively search for files in a subdirectory that match the regex pattern"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ListDirectoryTool(BaseFileToolMixin, BaseTool):
"""Tool that lists files and directories in a specified folder."""

name: str = "list_directory"
args_schema: Type[BaseModel] = DirectoryListingInput
args_schema: Type[DirectoryListingInput] = DirectoryListingInput
description: str = "List files and directories in a specified folder"

def _run(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MoveFileTool(BaseFileToolMixin, BaseTool):
"""Tool that moves a file."""

name: str = "move_file"
args_schema: Type[BaseModel] = FileMoveInput
args_schema: Type[FileMoveInput] = FileMoveInput
description: str = "Move or rename a file from one location to another"

def _run(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ReadFileTool(BaseFileToolMixin, BaseTool):
"""Tool that reads a file."""

name: str = "read_file"
args_schema: Type[BaseModel] = ReadFileInput
args_schema: Type[ReadFileInput] = ReadFileInput
description: str = "Read file from disk"

def _run(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class WriteFileTool(BaseFileToolMixin, BaseTool):
"""Tool that writes a file to disk."""

name: str = "write_file"
args_schema: Type[BaseModel] = WriteFileInput
args_schema: Type[WriteFileInput] = WriteFileInput
description: str = "Write file to disk"

def _run(
Expand Down
8 changes: 7 additions & 1 deletion libs/community/langchain_community/tools/github/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@
from langchain_community.utilities.github import GitHubAPIWrapper


class GitHubActionToolInput(BaseModel):
instructions: str = Field(
description="Instruction associated with a action on GitHub"
)


class GitHubAction(BaseTool):
"""Tool for interacting with the GitHub API."""

api_wrapper: GitHubAPIWrapper = Field(default_factory=GitHubAPIWrapper)
mode: str
name: str = ""
description: str = ""
args_schema: Optional[Type[BaseModel]] = None
args_schema: Type[GitHubActionToolInput] = GitHubActionToolInput

def _run(
self,
Expand Down
11 changes: 9 additions & 2 deletions libs/community/langchain_community/tools/gitlab/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,29 @@
GITLAB_REPOSITORY -> format: {owner}/{repo}

"""
from typing import Optional
from typing import Optional, Type

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

from langchain_community.utilities.gitlab import GitLabAPIWrapper


class GitLabActionToolInput(BaseModel):
instructions: str = Field(
description="Instruction associated with a action on GitLab"
)


class GitLabAction(BaseTool):
"""Tool for interacting with the GitLab API."""

api_wrapper: GitLabAPIWrapper = Field(default_factory=GitLabAPIWrapper)
mode: str
name: str = ""
description: str = ""
args_schema: Type[GitLabActionToolInput] = GitLabActionToolInput

def _run(
self,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
"""Tool for the Golden API."""

from typing import Optional
from typing import Optional, Type

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

from langchain_community.utilities.golden_query import GoldenQueryAPIWrapper


class GoldenQueryRunToolInput(BaseModel):
query: str = Field(description="search query to look up")


class GoldenQueryRun(BaseTool):
"""Tool that adds the capability to query using the Golden API and get back JSON."""

Expand All @@ -24,6 +29,7 @@ class GoldenQueryRun(BaseTool):
" in JSON format."
)
api_wrapper: GoldenQueryAPIWrapper
args_schema: Type[GoldenQueryRunToolInput] = GoldenQueryRunToolInput

def _run(
self,
Expand Down
Loading
Loading