mirror of
https://github.com/hwchase17/langchain.git
synced 2026-02-21 22:56:05 +00:00
Compare commits
3 Commits
langchain-
...
vwp/add-gi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
18e31de2c4 | ||
|
|
036510f7e4 | ||
|
|
7a504b3b3a |
@@ -27,6 +27,13 @@ from langchain.tools.playwright import (
|
|||||||
from langchain.tools.plugin import AIPluginTool
|
from langchain.tools.plugin import AIPluginTool
|
||||||
from langchain.tools.scenexplain.tool import SceneXplainTool
|
from langchain.tools.scenexplain.tool import SceneXplainTool
|
||||||
from langchain.tools.shell.tool import ShellTool
|
from langchain.tools.shell.tool import ShellTool
|
||||||
|
from langchain.tools.vectorstore.tool import (
|
||||||
|
VectorStoreQATool,
|
||||||
|
VectorStoreQAWithSourcesTool,
|
||||||
|
)
|
||||||
|
from langchain.tools.wikipedia.tool import WikipediaQueryRun
|
||||||
|
from langchain.tools.wolfram_alpha.tool import WolframAlphaQueryRun
|
||||||
|
from langchain.tools.zapier.tool import ZapierNLAListActions, ZapierNLARunAction
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"AIPluginTool",
|
"AIPluginTool",
|
||||||
@@ -60,4 +67,10 @@ __all__ = [
|
|||||||
"WriteFileTool",
|
"WriteFileTool",
|
||||||
"BaseTool",
|
"BaseTool",
|
||||||
"SceneXplainTool",
|
"SceneXplainTool",
|
||||||
|
"VectorStoreQAWithSourcesTool",
|
||||||
|
"VectorStoreQATool",
|
||||||
|
"WikipediaQueryRun",
|
||||||
|
"WolframAlphaQueryRun",
|
||||||
|
"ZapierNLARunAction",
|
||||||
|
"ZapierNLAListActions",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1 +1,5 @@
|
|||||||
"""Bing Search API toolkit."""
|
"""Bing Search API toolkit."""
|
||||||
|
|
||||||
|
from langchain.tools.bing_search.tool import BingSearchResults, BingSearchRun
|
||||||
|
|
||||||
|
__all__ = ["BingSearchRun", "BingSearchResults"]
|
||||||
|
|||||||
1
langchain/tools/github/__init__.py
Normal file
1
langchain/tools/github/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
""" GitHub API wrapper toolkit. """
|
||||||
29
langchain/tools/github/tool.py
Normal file
29
langchain/tools/github/tool.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
"""Tool for the GitHub API."""
|
||||||
|
|
||||||
|
from langchain.tools.base import BaseTool
|
||||||
|
from langchain.utilities import GitHubAPIWrapper
|
||||||
|
|
||||||
|
|
||||||
|
class GitHubRepoQueryRun(BaseTool):
|
||||||
|
"""Tool that adds the capability to query using the GitHub API."""
|
||||||
|
|
||||||
|
api_wrapper: GitHubAPIWrapper
|
||||||
|
|
||||||
|
name = "GitHub"
|
||||||
|
description = (
|
||||||
|
"A wrapper around GitHub API. "
|
||||||
|
"Useful for fetching repository information for a specified user. "
|
||||||
|
"Input should be a GitHub username (e.g. 'octocat')."
|
||||||
|
)
|
||||||
|
|
||||||
|
def __init__(self) -> None:
|
||||||
|
self.api_wrapper = GitHubAPIWrapper()
|
||||||
|
return
|
||||||
|
|
||||||
|
def _run(self, user: str) -> str:
|
||||||
|
"""Use the GitHub tool."""
|
||||||
|
return self.api_wrapper.run(user)
|
||||||
|
|
||||||
|
async def _arun(self, user: str) -> str:
|
||||||
|
"""Use the GitHub tool asynchronously."""
|
||||||
|
raise NotImplementedError("GitHubRepoQueryRun does not support async")
|
||||||
@@ -1 +1,5 @@
|
|||||||
"""Google Places API Toolkit."""
|
"""Google Places API Toolkit."""
|
||||||
|
|
||||||
|
from langchain.tools.google_places.tool import GooglePlacesTool
|
||||||
|
|
||||||
|
__all__ = ["GooglePlacesTool"]
|
||||||
|
|||||||
@@ -1 +1,5 @@
|
|||||||
"""Google Search API Toolkit."""
|
"""Google Search API Toolkit."""
|
||||||
|
|
||||||
|
from langchain.tools.google_search.tool import GoogleSearchResults, GoogleSearchRun
|
||||||
|
|
||||||
|
__all__ = ["GoogleSearchRun", "GoogleSearchResults"]
|
||||||
|
|||||||
@@ -1 +1,5 @@
|
|||||||
"""Tool for asking for human input."""
|
"""Tool for asking for human input."""
|
||||||
|
|
||||||
|
from langchain.tools.human.tool import HumanInputRun
|
||||||
|
|
||||||
|
__all__ = ["HumanInputRun"]
|
||||||
|
|||||||
@@ -1,32 +1,17 @@
|
|||||||
"""Tools for interacting with the user."""
|
"""Tools for interacting with the user."""
|
||||||
|
|
||||||
|
|
||||||
from typing import Optional
|
import warnings
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from langchain.callbacks.manager import (
|
from langchain.tools.human.tool import HumanInputRun
|
||||||
AsyncCallbackManagerForToolRun,
|
|
||||||
RunManager,
|
|
||||||
)
|
|
||||||
from langchain.tools.base import BaseTool
|
|
||||||
|
|
||||||
|
|
||||||
class StdInInquireTool(BaseTool):
|
def StdInInquireTool(*args: Any, **kwargs: Any) -> HumanInputRun:
|
||||||
"""Tool for asking the user for input."""
|
"""Tool for asking the user for input."""
|
||||||
|
warnings.warn(
|
||||||
name: str = "Inquire"
|
"StdInInquireTool will be deprecated in the future. "
|
||||||
description: str = (
|
"Please use HumanInputRun instead.",
|
||||||
"useful if you do not have enough information to"
|
DeprecationWarning,
|
||||||
" effectively use other tools. Input is best as a clarifying"
|
|
||||||
" question (to disambiguate) or a request for more context."
|
|
||||||
)
|
)
|
||||||
|
return HumanInputRun(*args, **kwargs)
|
||||||
def _run(self, prompt: str, run_manager: Optional[RunManager] = None) -> str:
|
|
||||||
"""Prompt the user for more input."""
|
|
||||||
return input(f"\n{prompt}")
|
|
||||||
|
|
||||||
async def _arun(
|
|
||||||
self,
|
|
||||||
query: str,
|
|
||||||
run_manager: Optional[AsyncCallbackManagerForToolRun] = None,
|
|
||||||
) -> str:
|
|
||||||
raise NotImplementedError(f"{self.__class__.__name__} does not support async")
|
|
||||||
|
|||||||
@@ -1 +1,8 @@
|
|||||||
"""Wolfram Alpha API toolkit."""
|
"""Wolfram Alpha API toolkit."""
|
||||||
|
|
||||||
|
|
||||||
|
from langchain.tools.wolfram_alpha.tool import WolframAlphaQueryRun
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"WolframAlphaQueryRun",
|
||||||
|
]
|
||||||
|
|||||||
@@ -1 +1,8 @@
|
|||||||
"""Zapier Tool."""
|
"""Zapier Tool."""
|
||||||
|
|
||||||
|
from langchain.tools.zapier.tool import ZapierNLAListActions, ZapierNLARunAction
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"ZapierNLARunAction",
|
||||||
|
"ZapierNLAListActions",
|
||||||
|
]
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ from langchain.utilities.searx_search import SearxSearchWrapper
|
|||||||
from langchain.utilities.serpapi import SerpAPIWrapper
|
from langchain.utilities.serpapi import SerpAPIWrapper
|
||||||
from langchain.utilities.wikipedia import WikipediaAPIWrapper
|
from langchain.utilities.wikipedia import WikipediaAPIWrapper
|
||||||
from langchain.utilities.wolfram_alpha import WolframAlphaAPIWrapper
|
from langchain.utilities.wolfram_alpha import WolframAlphaAPIWrapper
|
||||||
|
from langchain.utilities.github import GitHubAPIWrapper
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"ApifyWrapper",
|
"ApifyWrapper",
|
||||||
@@ -33,4 +34,5 @@ __all__ = [
|
|||||||
"PythonREPL",
|
"PythonREPL",
|
||||||
"LambdaWrapper",
|
"LambdaWrapper",
|
||||||
"PowerBIDataset",
|
"PowerBIDataset",
|
||||||
|
"GitHubAPIWrapper",
|
||||||
]
|
]
|
||||||
|
|||||||
86
langchain/utilities/github.py
Normal file
86
langchain/utilities/github.py
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
"""Util that calls GitHub API using requests."""
|
||||||
|
from typing import Any, Dict, Optional
|
||||||
|
|
||||||
|
import requests
|
||||||
|
from pydantic import Extra, root_validator
|
||||||
|
|
||||||
|
from langchain.tools.base import BaseModel
|
||||||
|
from langchain.utils import get_from_dict_or_env
|
||||||
|
|
||||||
|
"""
|
||||||
|
Example usage
|
||||||
|
|
||||||
|
from langchain.utilities import GitHubAPIWrapper
|
||||||
|
|
||||||
|
#set env variable GITHUB_API_KEY
|
||||||
|
import os
|
||||||
|
|
||||||
|
os.environ['GITHUB_API_KEY'] = ''
|
||||||
|
|
||||||
|
github_api = GitHubAPIWrapper()
|
||||||
|
|
||||||
|
print(github_api.run('SamPink'))
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class GitHubAPIWrapper(BaseModel):
|
||||||
|
"""Wrapper for GitHub API using requests.
|
||||||
|
|
||||||
|
Docs for using:
|
||||||
|
|
||||||
|
1. Go to GitHub and sign up for an API key
|
||||||
|
2. Save your API KEY into GITHUB_API_KEY env variable
|
||||||
|
3. pip install requests
|
||||||
|
"""
|
||||||
|
|
||||||
|
github_api_key: Optional[str] = None
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
"""Configuration for this pydantic object."""
|
||||||
|
|
||||||
|
extra = Extra.forbid
|
||||||
|
|
||||||
|
@root_validator(pre=True)
|
||||||
|
def validate_environment(cls, values: Dict) -> Dict:
|
||||||
|
"""Validate that api key exists in environment."""
|
||||||
|
github_api_key = get_from_dict_or_env(
|
||||||
|
values, "github_api_key", "GITHUB_API_KEY"
|
||||||
|
)
|
||||||
|
values["github_api_key"] = github_api_key
|
||||||
|
|
||||||
|
try:
|
||||||
|
import requests
|
||||||
|
|
||||||
|
except ImportError:
|
||||||
|
raise ImportError(
|
||||||
|
"requests is not installed. "
|
||||||
|
"Please install it with `pip install requests`"
|
||||||
|
)
|
||||||
|
|
||||||
|
return values
|
||||||
|
|
||||||
|
def _format_repo_info(self, repo: Dict) -> str:
|
||||||
|
return (
|
||||||
|
f"Repo name: {repo['name']}\n"
|
||||||
|
f"Description: {repo['description']}\n"
|
||||||
|
f"URL: {repo['html_url']}\n"
|
||||||
|
f"Stars: {repo['stargazers_count']}\n"
|
||||||
|
f"Forks: {repo['forks_count']}\n"
|
||||||
|
f"Language: {repo['language']}\n"
|
||||||
|
f"Open issues: {repo['open_issues_count']}\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
def run(self, user: str) -> str:
|
||||||
|
"""Get the repository information for a specified user."""
|
||||||
|
headers = {"Authorization": f"token {self.github_api_key}"}
|
||||||
|
response = requests.get(
|
||||||
|
f"https://api.github.com/users/{user}/repos", headers=headers
|
||||||
|
)
|
||||||
|
|
||||||
|
if response.status_code != 200:
|
||||||
|
raise ValueError(f"Error: {response.status_code}, {response.text}")
|
||||||
|
|
||||||
|
repos = response.json()
|
||||||
|
repo_info = "\n\n".join(self._format_repo_info(repo) for repo in repos)
|
||||||
|
|
||||||
|
return f"Repositories for {user}:\n\n{repo_info}"
|
||||||
@@ -21,7 +21,8 @@ def get_non_abstract_subclasses(cls: Type[BaseTool]) -> List[Type[BaseTool]]:
|
|||||||
and subclass not in to_skip
|
and subclass not in to_skip
|
||||||
):
|
):
|
||||||
subclasses.append(subclass)
|
subclasses.append(subclass)
|
||||||
subclasses.extend(get_non_abstract_subclasses(subclass))
|
sc = get_non_abstract_subclasses(subclass)
|
||||||
|
subclasses.extend(sc)
|
||||||
return subclasses
|
return subclasses
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user