GithubSearchTool

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

描述

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

安装

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

pip install 'crewai[tools]'

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

示例

以下是您可以使用GithubSearchTool在GitHub仓库内执行语义搜索的方法:

Code
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进行嵌入和摘要生成。要自定义模型,您可以使用如下配置字典:

Code
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",
            ),
        ),
    )
)

这个页面有帮助吗?