跳到主要内容

GithubSearchTool

!!! note "实验性质" 我们仍在努力改进工具,因此未来可能会出现意外行为或更改。

描述

GithubSearchTool 是一个专门设计用于在 GitHub 仓库中进行语义搜索的读取、追加和生成(RAG)工具。利用先进的语义搜索功能,它可以筛选代码、拉取请求、问题和仓库,使其成为开发人员、研究人员或任何需要从 GitHub 获取精确信息的人的必备工具。

安装

要使用 GithubSearchTool,请首先确保在您的 Python 环境中安装了 crewai_tools 包:

pip install 'crewai[tools]'

此命令将安装运行 GithubSearchTool 所需的必要包,以及 crewai_tools 包中包含的任何其他工具。

示例

以下是您如何使用 GithubSearchTool 在 GitHub 仓库中执行语义搜索的示例:

from crewai_tools import GithubSearchTool

# 初始化用于在特定 GitHub 仓库中进行语义搜索的工具
tool = GithubSearchTool(
github_repo='https://github.com/example/repo',
content_types=['code', 'issue'] # 选项:code, repo, pr, issue
)

# 或者

# 初始化用于在特定 GitHub 仓库中进行语义搜索的工具,以便代理在执行期间了解任何仓库时都可以搜索
tool = GithubSearchTool(
content_types=['code', 'issue'] # 选项:code, repo, pr, issue
)

参数

  • github_repo:要进行搜索的 GitHub 仓库的 URL。这是一个必填字段,指定了搜索的目标仓库。
  • content_types:指定要包含在搜索中的内容类型。您必须从以下选项中提供内容类型列表:code 用于在代码中搜索,repo 用于在仓库的一般信息中搜索,pr 用于在拉取请求中搜索,issue 用于在问题中搜索。这是一个必填字段,允许将搜索定制为 GitHub 仓库中特定的内容类型。

自定义模型和嵌入

默认情况下,该工具使用 OpenAI 进行嵌入和摘要生成。要自定义模型,可以使用以下方式的配置字典:

tool = GithubSearchTool(
config=dict(
llm=dict(
provider="ollama", # 或 google, openai, anthropic, llama2, ...
config=dict(
model="llama2",
# temperature=0.5,
# top_p=1,
# stream=true,
),
),
embedder=dict(
provider="google", # 或 openai, ollama, ...
config=dict(
model="models/embedding-001",
task_type="retrieval_document",
# title="Embeddings",
),
),
)
)