GitHubIssueCommenterTool
一个允许 Agent 和 ToolInvoker 向 GitHub 问题发布评论的工具。
| 必需的初始化变量 | "github_token": GitHub 个人访问令牌。可以设置为GITHUB_TOKEN 环境变量。 |
| API 参考 | Tools (工具) |
| GitHub 链接 | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/github |
概述
GitHubIssueCommenterTool 包装了 GitHubIssueCommenter 组件,提供了一个工具接口,用于在 agent 工作流和基于工具的管道中使用。
该工具接收 GitHub issue URL 和评论文本,然后使用 GitHub API 将评论发布到指定的 issue。这需要身份验证,因为发布评论是一个需要身份验证的操作。
参数
name是可选的,默认为“issue_commenter”。指定工具的名称。description是可选的,并为 LLM 提供有关工具功能的上下文。github_token是必需的,必须是用于 API 身份验证的 GitHub 个人访问令牌。默认设置使用环境变量GITHUB_TOKEN.raise_on_failure是可选的,默认为True。如果为 False,则会返回错误而不是引发异常。retry_attempts是可选的,默认为2。失败请求的重试次数。
用法
安装 GitHub 集成即可使用GitHubIssueCommenterTool:
pip install github-haystack
仓库占位符
要运行以下代码片段,您需要将
owner/repo替换为您自己的 GitHub 仓库名称。
单独使用
评论 issue 的基本用法
from haystack_integrations.tools.github import GitHubIssueCommenterTool
tool = GitHubIssueCommenterTool()
result = tool.invoke(
url="https://github.com/owner/repo/issues/123",
comment="Thanks for reporting this issue! We'll look into it."
)
print(result)
{'success': True}
与 Agent 一起使用
您可以使用与 Agent 组件一起使用 GitHubIssueCommenterTool。当需要发布 GitHub issue 评论时,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 GitHubIssueCommenterTool
comment_tool = GitHubIssueCommenterTool(name="github_issue_commenter")
agent = Agent(
chat_generator=OpenAIChatGenerator(),
tools=[comment_tool],
exit_conditions=["text"]
)
agent.warm_up()
response = agent.run(messages=[
ChatMessage.from_user("Please post a helpful comment on this GitHub issue: https://github.com/owner/repo/issues/123 acknowledging the bug report and mentioning that we're investigating")
])
print(response["last_message"].text)
I have posted the comment on the GitHub issue, acknowledging the bug report and mentioning that the team is investigating the problem. If you need anything else, feel free to ask!
更新于 4 个月前
