GithubSearchTool

我们仍在努力改进工具,因此未来可能存在意外行为或变化。

描述

GithubSearchTool 是一款检索增强生成 (RAG) 工具,专为在 GitHub 仓库中执行语义搜索而设计。它利用先进的语义搜索能力,筛选代码、拉取请求、问题和仓库,使其成为开发者、研究人员或任何需要从 GitHub 获取精确信息的人的必备工具。

安装

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

pip install 'crewai[tools]'

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

示例

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

代码
from crewai_tools import GithubSearchTool

# Initialize the tool for semantic searches within a specific GitHub repository
tool = GithubSearchTool(
	github_repo='https://github.com/example/repo',
	gh_token='your_github_personal_access_token',
	content_types=['code', 'issue'] # Options: code, repo, pr, issue
)

# OR

# Initialize the tool for semantic searches within a specific GitHub repository, so the agent can search any repository if it learns about during its execution
tool = GithubSearchTool(
	gh_token='your_github_personal_access_token',
	content_types=['code', 'issue'] # Options: code, repo, pr, issue
)

参数

  • github_repo : 将进行搜索的 GitHub 仓库的 URL。这是一个强制字段,用于指定搜索的目标仓库。
  • gh_token : 进行身份验证所需的 GitHub 个人访问令牌 (PAT)。您可以在 GitHub 账户设置的 开发者设置 > 个人访问令牌 下创建一个。
  • content_types : 指定要包含在搜索中的内容类型。您必须提供一个包含以下选项的内容类型列表:code 用于搜索代码,repo 用于搜索仓库的常规信息,pr 用于搜索拉取请求,以及 issue 用于搜索问题。此字段为强制字段,允许将搜索范围限定在 GitHub 仓库内的特定内容类型。

自定义模型和嵌入

默认情况下,该工具使用 OpenAI 进行嵌入和摘要。要自定义模型,您可以使用如下配置字典

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