主题
Github 搜索
GithubSearchTool旨在搜索网站并将其转换为干净的 Markdown 或结构化数据。
GithubSearchTool
NOTE
我们仍在改进这些工具,因此未来可能会出现意外行为或变更。
描述
GithubSearchTool 是一种检索增强生成(RAG)工具,专门用于在 GitHub 仓库中执行语义搜索。它利用高级语义搜索能力,筛选代码、拉取请求、议题和仓库,使其成为开发者、研究人员或任何需要从 GitHub 获取精确信息的人的重要工具。
安装
要使用 GithubSearchTool,首先确保你的 Python 环境中已安装 crewai_tools 包:
shell
pip install 'crewai[tools]'此命令会安装运行 GithubSearchTool 所需的包,以及 crewai_tools 包中包含的任何其他工具。
在 https://github.com/settings/tokens 获取 GitHub 个人访问 token(开发者设置 → 细粒度 token 或经典 token)。
示例
以下是在 GitHub 仓库中使用 GithubSearchTool 执行语义搜索的方法:
python
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 个人访问 token(PAT)。你可以在 GitHub 账户设置的开发者设置 > 个人访问 token 中创建一个。content_types:指定要包含在搜索中的内容类型。你必须提供以下选项中的内容类型列表:code用于在代码中搜索,repo用于在仓库的常规信息中搜索,pr用于在拉取请求中搜索,issue用于在议题中搜索。 此字段为必填项,可让搜索针对 GitHub 仓库中的特定内容类型进行定制。
自定义模型和嵌入
默认情况下,该工具使用 OpenAI 进行嵌入和摘要。要自定义模型,你可以使用如下配置字典:
python
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",
),
),
)
)