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

GitHubRepoViewer

此组件通过 GitHub API 导航和获取 GitHub 存储库的内容。

pipeline 中的最常见位置在管道的开头,并在 ChatPromptBuilder 之前,该组件需要 GitHub 文件的内容作为输入
强制运行变量"path": 要查看的存储库路径

"repo": 格式为 owner/repo 的存储库
输出变量"documents": 包含存储库内容的文档列表
API 参考GitHub
GitHub 链接https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/github

概述

GitHubRepoViewer 的行为因路径类型而异

  • 对于目录:返回一个文档列表,每个文档代表一个条目(文件和子目录),
  • 对于文件:返回一个包含文件内容的单个文档。

每个文档都包含丰富的元数据,例如路径、类型、大小和 URL。

授权

该组件可以对公共存储库进行身份验证,但对于私有存储库或为了避免速率限制,您可以提供 GitHub 个人访问令牌。

您可以使用GITHUB_TOKEN 环境变量进行设置,或者在初始化时通过github_token 参数直接传递。

要创建个人访问令牌,请访问 GitHub 的令牌设置页面

安装

使用 pip 安装 GitHub 集成

pip install github-haystack

用法

📘

仓库占位符

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

单独使用

查看目录列表

from haystack_integrations.components.connectors.github import GitHubRepoViewer

viewer = GitHubRepoViewer()
result = viewer.run(
    repo="deepset-ai/haystack",
    path="haystack/components",
    branch="main"
)

print(result)
{'documents': [Document(id=..., content: 'agents', meta: {'path': 'haystack/components/agents', 'type': 'dir', 'size': 0, 'url': 'https://github.com/deepset-ai/haystack/tree/main/haystack/components/agents'}), ...]}

查看特定文件

from haystack_integrations.components.connectors.github import GitHubRepoViewer

viewer = GitHubRepoViewer(repo="deepset-ai/haystack", branch="main")
result = viewer.run(path="README.md")

print(result)
{'documents': [Document(id=..., content: '<div align="center">
  <a href="https://haystack.com.cn/"><img src="https://raw.githubuserconten...', meta: {'path': 'README.md', 'type': 'file_content', 'size': 11979, 'url': 'https://github.com/deepset-ai/haystack/blob/main/README.md'})]}