GitHub工具包#

class langchain_community.agent_toolkits.github.toolkit.GitHubToolkit[source]#

基础类:BaseToolkit

GitHub 工具包。

Security Note: This toolkit contains tools that can read and modify

服务状态;例如,通过创建、删除或更新,读取底层数据。

例如,这个工具包可以用来在GitHub上创建问题、拉取请求和评论。

有关更多信息,请参见[安全](https://python.langchain.com/docs/security)。

Setup:

查看详细的安装说明: https://python.langchain.com/docs/integrations/tools/github/#installation

你需要安装 pygithub 并设置以下环境变量:

pip install -U pygithub
export GITHUB_APP_ID="your-app-id"
export GITHUB_APP_PRIVATE_KEY="path-to-private-key"
export GITHUB_REPOSITORY="your-github-repository"
Instantiate:
from langchain_community.agent_toolkits.github.toolkit import GitHubToolkit
from langchain_community.utilities.github import GitHubAPIWrapper

github = GitHubAPIWrapper()
toolkit = GitHubToolkit.from_github_api_wrapper(github)
Tools:
tools = toolkit.get_tools()
for tool in tools:
    print(tool.name)
Get Issues
Get Issue
Comment on Issue
List open pull requests (PRs)
Get Pull Request
Overview of files included in PR
Create Pull Request
List Pull Requests' Files
Create File
Read File
Update File
Delete File
Overview of existing files in Main branch
Overview of files in current working branch
List branches in this repository
Set active branch
Create a new branch
Get files from a directory
Search issues and pull requests
Search code
Create review request
Use within an agent:
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent

# Select example tool
tools = [tool for tool in toolkit.get_tools() if tool.name == "Get Issue"]
assert len(tools) == 1
tools[0].name = "get_issue"

llm = ChatOpenAI(model="gpt-4o-mini")
agent_executor = create_react_agent(llm, tools)

example_query = "What is the title of issue 24888?"

events = agent_executor.stream(
    {"messages": [("user", example_query)]},
    stream_mode="values",
)
for event in events:
    event["messages"][-1].pretty_print()
 ================================[1m Human Message [0m=================================

What is the title of issue 24888?
==================================[1m Ai Message [0m==================================
Tool Calls:
get_issue (call_iSYJVaM7uchfNHOMJoVPQsOi)
Call ID: call_iSYJVaM7uchfNHOMJoVPQsOi
Args:
    issue_number: 24888
=================================[1m Tool Message [0m=================================
Name: get_issue

{"number": 24888, "title": "Standardize KV-Store Docs", "body": "..."
==================================[1m Ai Message [0m==================================

The title of issue 24888 is "Standardize KV-Store Docs".
Parameters:

工具 – List[BaseTool]。工具包中的工具。默认为空列表。

通过解析和验证来自关键字参数的输入数据来创建一个新模型。

如果输入数据无法验证以形成有效模型,则引发 [ValidationError][pydantic_core.ValidationError]。

self 被显式地设为仅位置参数,以允许 self 作为字段名称。

param tools: List[BaseTool] = []#
classmethod from_github_api_wrapper(github_api_wrapper: GitHubAPIWrapper) GitHubToolkit[来源]#

从GitHubAPIWrapper创建一个GitHubToolkit。

Parameters:

github_api_wrapper (GitHubAPIWrapper) – GitHubAPIWrapper。GitHub API 封装器。

Returns:

GitHubToolkit。GitHub工具包。

Return type:

GitHubToolkit

get_tools() List[BaseTool][source]#

获取工具包中的工具。

Return type:

列表[BaseTool]

使用 GitHubToolkit 的示例