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-generativeai", # or openai, ollama, ...
config=dict(
model_name="gemini-embedding-001",
task_type="RETRIEVAL_DOCUMENT",
# title="Embeddings",
),
),
)
)