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

GitHubIssueViewerTool

一个允许 Agents 和 ToolInvokers 获取和解析 GitHub issues 为文档的工具。

概述

GitHubIssueViewerTool 封装了 GitHubIssueViewer 组件,为在 agent 工作流和基于工具的管道中使用提供了工具接口。

该工具接受一个 GitHub issue URL 并返回一个文档列表,其中

  • 第一个文档包含主要 issue 内容,
  • 后续文档包含 issue 评论(如果有)。

每个文档都包含丰富的元数据,例如 issue 标题、编号、状态、创建日期、作者等。

参数

  • name可选的,默认为 "issue_viewer"。指定工具的名称。
  • description可选的,并为 LLM 提供有关工具功能的上下文。
  • github_token可选的,但建议用于私有存储库或避免速率限制。
  • raise_on_failure可选的,默认为True。如果为 False,错误将作为文档返回,而不是抛出异常。
  • retry_attempts可选的,默认为2。失败请求的重试次数。

用法

安装 GitHub 集成即可使用GitHubIssueViewerTool:

pip install github-haystack

📘

仓库占位符

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

单独使用

from haystack_integrations.tools.github import GitHubIssueViewerTool

tool = GitHubIssueViewerTool()
result = tool.invoke(url="https://github.com/deepset-ai/haystack/issues/123")

print(result)
{'documents': [Document(id=3989459bbd8c2a8420a9ba7f3cd3cf79bb41d78bd0738882e57d509e1293c67a, content: 'sentence-transformers = 0.2.6.1
haystack = latest
farm = 0.4.3 latest branch

In the call to Emb...', meta: {'type': 'issue', 'title': 'SentenceTransformer no longer accepts \'gpu" as argument', 'number': 123, 'state': 'closed', 'created_at': '2020-05-28T04:49:31Z', 'updated_at': '2020-05-28T07:11:43Z', 'author': 'predoctech', 'url': 'https://github.com/deepset-ai/haystack/issues/123'}), Document(id=a8a56b9ad119244678804d5873b13da0784587773d8f839e07f644c4d02c167a, content: 'Thanks for reporting!
Fixed with #124 ', meta: {'type': 'comment', 'issue_number': 123, 'created_at': '2020-05-28T07:11:42Z', 'updated_at': '2020-05-28T07:11:42Z', 'author': 'tholor', 'url': 'https://github.com/deepset-ai/haystack/issues/123#issuecomment-635153940'})]}

与 Agent 一起使用

您可以使用GitHubIssueViewerToolAgent 组件配合使用。当需要获取 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 GitHubIssueViewerTool

issue_tool = GitHubIssueViewerTool(name="github_issue_viewer")

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

agent.warm_up()
response = agent.run(messages=[
    ChatMessage.from_user("Please analyze this GitHub issue and summarize the main problem: https://github.com/deepset-ai/haystack/issues/123")
])

print(response["last_message"].text)
The GitHub issue titled "SentenceTransformer no longer accepts 'gpu' as argument" (issue \#123) discusses a problem encountered when using the `EmbeddingRetriever()` function. The user reports that passing the argument `gpu=True` now causes an error because the method that processes this argument does not accept "gpu" anymore; instead, it previously accepted "cuda" without issues.

The user indicates that this change is problematic since it prevents users from instantiating the embedding model with GPU support, forcing them to default to using only the CPU for model execution.

The issue was later closed with a comment indicating it was fixed in another pull request (#124).