GitHub 搜索
GithubSearchTool
Section titled “GithubSearchTool”GithubSearchTool 是一个检索增强生成(RAG)工具,专为在 GitHub 仓库中进行语义搜索而设计。它利用高级语义搜索能力,筛选代码、拉取请求、问题和仓库内容,因此对于开发者、研究人员或任何需要从 GitHub 获取精确信息的人来说都非常有用。
要使用 GithubSearchTool,请先确保你的 Python 环境中已安装 crewai_tools 包:
pip install 'crewai[tools]'此命令会安装运行 GithubSearchTool 所需的必要包,以及 crewai_tools 包中的其他工具。
请在 https://github.com/settings/tokens 获取 GitHub Personal Access Token(开发者设置 → 精细化令牌或经典令牌)。
以下演示如何使用 GithubSearchTool 在 GitHub 仓库中执行语义搜索:
from crewai_tools import GithubSearchTool
# 初始化工具,用于在特定 GitHub 仓库中进行语义搜索tool = GithubSearchTool( github_repo='https://github.com/example/repo', gh_token='your_github_personal_access_token', content_types=['code', 'issue'] # 选项:code、repo、pr、issue)
# 或者
# 初始化工具,用于在特定 GitHub 仓库中进行语义搜索,# 这样智能体在执行过程中了解到仓库后也可以搜索任意仓库tool = GithubSearchTool( gh_token='your_github_personal_access_token', content_types=['code', 'issue'] # 选项:code、repo、pr、issue)github_repo:进行搜索的 GitHub 仓库 URL。这是必填字段,用于指定搜索目标仓库。gh_token:用于认证的 GitHub Personal Access Token (PAT)。你可以在 GitHub 账户设置的 Developer Settings > Personal Access Tokens 中创建。content_types:指定搜索中包含的内容类型。你必须提供以下内容类型列表:code表示搜索代码,repo表示搜索仓库的一般信息,pr表示搜索拉取请求,issue表示搜索问题。
此字段为必需项,可让你根据 GitHub 仓库中的特定内容类型定制搜索。
自定义模型与嵌入
Section titled “自定义模型与嵌入”默认情况下,该工具使用 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-generativeai", # 或 openai、ollama 等 config=dict( model_name="gemini-embedding-001", task_type="RETRIEVAL_DOCUMENT", # title="Embeddings", ), ), ))