Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions libs/langchain/langchain/tools/github/tool.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
This tool allows agents to interact with the pygithub library
This tool allows agents to interact with the pygithub library and operate on a GitHub repository.\n\nTo use this tool, you must first set as environment variables:\n GITHUB_API_TOKEN\n GITHUB_REPOSITORY -> format: {owner}/{repo}
and operate on a GitHub repository.

To use this tool, you must first set as environment variables:
Expand All @@ -11,22 +11,30 @@

from langchain.callbacks.manager import CallbackManagerForToolRun
from langchain.pydantic_v1 import Field
from langchain.tools.base import BaseTool
from langchain.pydantic_v1 import Field
import logging
import traceback
from langchain.tools.base import BaseTool, ToolRunFailed
from langchain.utilities.github import GitHubAPIWrapper


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

api_wrapper: GitHubAPIWrapper = Field(default_factory=GitHubAPIWrapper)
mode: str
name: str = ""
description: str = ""
api_wrapper: GitHubAPIWrapper = Field()

name: str = "GitHubAction"
description: str = "Provides an interface for interacting with the GitHub API."

def _run(
self,
instructions: str,
run_manager: Optional[CallbackManagerForToolRun] = None,
) -> str:
"""Use the GitHub API to run an operation."""
return self.api_wrapper.run(self.mode, instructions)
try:
return self.api_wrapper.run(instructions)
except Exception as e:
logging.error(f'An error occurred while running the API: {e}')
logging.error(traceback.format_exc())
raise ToolRunFailed('Failed to run the API')