Source code for langchain_community.tools.github.tool
"""This tool allows agents to interact with the pygithub libraryand operate on a GitHub repository.To use this tool, you must first set as environment variables: GITHUB_API_TOKEN GITHUB_REPOSITORY -> format: {owner}/{repo}"""fromtypingimportAny,Optional,Typefromlangchain_core.callbacksimportCallbackManagerForToolRunfromlangchain_core.toolsimportBaseToolfrompydanticimportBaseModel,Fieldfromlangchain_community.utilities.githubimportGitHubAPIWrapper
[docs]classGitHubAction(BaseTool):# type: ignore[override]"""Tool for interacting with the GitHub API."""api_wrapper:GitHubAPIWrapper=Field(default_factory=GitHubAPIWrapper)# type: ignore[arg-type]mode:strname:str=""description:str=""args_schema:Optional[Type[BaseModel]]=Nonedef_run(self,instructions:Optional[str]="",run_manager:Optional[CallbackManagerForToolRun]=None,**kwargs:Any,)->str:"""Use the GitHub API to run an operation."""ifnotinstructionsorinstructions=="{}":# Catch other forms of empty input that GPT-4 likes to send.instructions=""ifself.args_schemaisnotNone:field_names=list(self.args_schema.schema()["properties"].keys())iflen(field_names)>1:raiseAssertionError(f"Expected one argument in tool schema, got {field_names}.")iffield_names:field=field_names[0]else:field=""query=str(kwargs.get(field,""))else:query=instructionsreturnself.api_wrapper.run(self.mode,query)