使用 Ollama Web Search API 进行网络搜索和网页抓取。
export OLLAMA_API_KEY=your_key_herecurl: HTTP 请求工具 (macOS/Linux 自带)python3: JSON 解析和转义 (macOS/Linux 自带)bash
python3 --version # 检查 Python3
curl --version # 检查 curl
功能命令说明Web Searchsearch执行网络搜索,返回相关结果Web Fetchfetch获取单个网页内容
搜索:
bash
./ollama-web-search.sh search "AI 最新进展" 5
抓取网页:
bash
./ollama-web-search.sh fetch "https://ollama.com"
搜索:
text
/ollama-search "AI 最新进展" 5
抓取网页:
text
/ollama-fetch "https://ollama.com"
text
用 ollama-web-search-cli 搜索 "Ollama 新功能"
抓取 https://docs.ollama.com 页面内容
参数类型必需默认值说明querystring✅-搜索查询字符串max_resultsnumber❌5最大结果数 (1-10)
参数类型必需说明urlstring✅要抓取的网页 URL
json
{
"results": [
{
"title": "页面标题",
"url": "https://example.com",
"content": "相关内容摘要"
}
]
}
json
{
"title": "页面标题",
"content": "页面主要内容",
"links": ["链接 1", "链接 2", ...]
}
bash
# 基本搜索
./ollama-web-search.sh search "什么是 Ollama" 5
# 技术搜索
./ollama-web-search.sh search "LLM model scheduling" 10
# 新闻搜索
./ollama-web-search.sh search "AI news 2026" 5
# Slash 命令
/ollama-search "Ollama Web Search API" 5
bash
# 抓取 Ollama 首页
./ollama-web-search.sh fetch "https://ollama.com"
# 抓取文档
./ollama-web-search.sh fetch "https://docs.ollama.com"
# Slash 命令
/ollama-fetch "https://docs.openclaw.ai"
API端点方法Web Searchhttps://ollama.com/api/web_searchPOSTWeb Fetchhttps://ollama.com/api/web_fetchPOST
bash
# Web Search
curl -X POST "https://ollama.com/api/web_search" \
-H "Authorization: Bearer $OLLAMA_API_KEY" \
-H "Content-Type: application/json" \
-d '{"query":"what is ollama","max_results":5}'
# Web Fetch
curl -X POST "https://ollama.com/api/web_fetch" \
-H "Authorization: Bearer $OLLAMA_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url":"https://ollama.com"}'
OLLAMA_API_KEYtext
ollama-search-tool/
├── SKILL.md # 技能文档
├── README.md # 快速入门
├── _meta.json # 元数据
└── ollama-web-search.sh # 主脚本
slash-commands/
├── ollama-search # 搜索命令
└── ollama-fetch # 抓取命令