GithubSearchTool¶
实验性
我们仍在改进工具,因此未来可能会出现意外行为或更改。
描述¶
GithubSearchTool 是一个专门为在 GitHub 仓库中进行语义搜索而设计的检索增强生成(RAG)工具。利用先进的语义搜索能力,它能够筛选代码、拉取请求、问题和仓库,使其成为开发者、研究人员或任何需要从 GitHub 获取精确信息的人的必备工具。
安装¶
要使用 GithubSearchTool,首先确保在您的 Python 环境中安装了 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",
),
),
)
)