2023-12-11 21:53:30 +00:00
|
|
|
"""
|
|
|
|
This tool allows agents to interact with the pygithub library
|
|
|
|
and operate on a GitHub repository.
|
|
|
|
|
|
|
|
To use this tool, you must first set as environment variables:
|
|
|
|
GITHUB_API_TOKEN
|
|
|
|
GITHUB_REPOSITORY -> format: {owner}/{repo}
|
|
|
|
|
|
|
|
"""
|
|
|
|
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.github import GitHubAPIWrapper
|
|
|
|
|
|
|
|
|
|
|
|
class GitHubAction(BaseTool):
|
|
|
|
"""Tool for interacting with the GitHub API."""
|
|
|
|
|
2024-05-13 18:55:07 +00:00
|
|
|
api_wrapper: GitHubAPIWrapper = Field(default_factory=GitHubAPIWrapper) # type: ignore[arg-type]
|
2023-12-11 21:53:30 +00:00
|
|
|
mode: str
|
|
|
|
name: str = ""
|
|
|
|
description: str = ""
|
|
|
|
args_schema: Optional[Type[BaseModel]] = None
|
|
|
|
|
|
|
|
def _run(
|
|
|
|
self,
|
|
|
|
instructions: Optional[str] = "",
|
|
|
|
run_manager: Optional[CallbackManagerForToolRun] = None,
|
|
|
|
) -> str:
|
|
|
|
"""Use the GitHub API to run an operation."""
|
|
|
|
if not instructions or instructions == "{}":
|
|
|
|
# Catch other forms of empty input that GPT-4 likes to send.
|
|
|
|
instructions = ""
|
|
|
|
return self.api_wrapper.run(self.mode, instructions)
|