GithubSearchTool
我们仍在努力改进工具,因此未来可能会出现意外行为或变更。
GithubSearchTool 是一款检索增强生成 (RAG) 工具,专为在 GitHub 代码仓库中进行语义搜索而设计。它利用先进的语义搜索功能,筛选代码、拉取请求、问题和仓库,使其成为开发人员、研究人员或任何需要从 GitHub 获取精确信息的人的必备工具。
要使用 GithubSearchTool,首先确保在您的 Python 环境中安装了 crewai_tools 包。
pip install 'crewai[tools]'
此命令会安装运行 GithubSearchTool 所需的包,以及 crewai_tools 包中包含的任何其他工具。 在 https://github.com/settings/tokens 获取 GitHub 个人访问令牌(开发者设置 → 细粒度令牌或经典令牌)。
以下是如何使用 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",
),
),
)
)