文档API 参考📓 教程🧑‍🍳 食谱🤝 集成💜 Discord🎨 Studio
文档

GitHubPRCreatorTool

一个允许代理和工具调用者从一个 fork 创建到原始存储库的拉取请求的工具。

必需的初始化变量"github_token": GitHub 个人访问令牌。可以设置为GITHUB_TOKEN 环境变量。
API 参考Tools (工具)
GitHub 链接https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/github

概述

GitHubPRCreatorTool 封装了 GitHubPRCreator 组件,为在代理工作流和基于工具的管道中使用提供了工具接口。

该工具接受一个 GitHub issue URL,并从您的 fork 创建一个拉取请求到原始存储库,自动将其链接到指定的 issue。它旨在与现有 fork 一起使用,并假设您已经在某个分支中进行了更改。

参数

  • name可选的,默认为“pr_creator”。指定工具的名称。
  • description可选的,并为 LLM 提供有关工具功能的上下文。
  • github_token必需的,必须是来自 fork 所有者的 GitHub 个人访问令牌。默认设置使用环境变量GITHUB_TOKEN.
  • raise_on_failure可选的,默认为True。如果为 False,则会返回错误而不是引发异常。

用法

安装 GitHub 集成即可使用GitHubPRCreatorTool:

pip install github-haystack

📘

仓库占位符

要运行以下代码片段,您需要将owner/repo 替换为您自己的 GitHub 仓库名称。

单独使用

创建拉取请求的基本用法

from haystack_integrations.tools.github import GitHubPRCreatorTool

tool = GitHubPRCreatorTool()
result = tool.invoke(
    issue_url="https://github.com/owner/repo/issues/123",
    title="Fix issue #123",
    body="This PR addresses issue #123 by implementing the requested changes.",
    branch="fix-123",  # Branch in your fork with the changes
    base="main"        # Branch in original repo to merge into
)

print(result)
{'result': 'Pull request #16 created successfully and linked to issue #4'}

与 Agent 一起使用

您可以使用GitHubPRCreatorToolAgent 组件一起使用。当需要创建拉取请求时,Agent 将自动调用该工具。

from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack.components.agents import Agent
from haystack_integrations.tools.github import GitHubPRCreatorTool

pr_tool = GitHubPRCreatorTool(name="github_pr_creator")

agent = Agent(
    chat_generator=OpenAIChatGenerator(),
    tools=[pr_tool],
    exit_conditions=["text"]
)

agent.warm_up()
response = agent.run(messages=[
    ChatMessage.from_user("Create a pull request for issue https://github.com/owner/repo/issues/4 with title 'Fix authentication bug' and empty body using my fix-4 branch and main as target branch")
])

print(response["last_message"].text)
The pull request titled "Fix authentication bug" has been created successfully and linked to issue [#123](https://github.com/owner/repo/issues/4).