Skip to content

Commit 401e0ab

Browse files
committed
fix: update ai302-search skill
1 parent eae91c9 commit 401e0ab

3 files changed

Lines changed: 254 additions & 320 deletions

File tree

skills/302ai-search.zip

-1.52 KB
Binary file not shown.

skills/302ai-search/SKILL.md

Lines changed: 85 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ metadata:
77

88
# 302 Search
99

10-
使用 302.AI 通用搜索 API 进行网络搜索,支持多种搜索引擎供应商。
10+
使用 302.AI 通用搜索 API 进行网络搜索,支持多种搜索引擎供应商。**当指定供应商失败时,会自动切换到备用供应商**
1111

1212
## 前置要求
1313

@@ -17,47 +17,28 @@ metadata:
1717

1818
## 安装依赖
1919

20-
Skill 需要 `requests` Python 包。安装方式:
21-
2220
```bash
2321
pip3 install requests
2422
```
2523

26-
或者使用虚拟环境(推荐):
27-
28-
```bash
29-
python3 -m venv ~/skills/302ai-search/venv
30-
source ~/skills/302ai-search/venv/bin/activate # Linux/macOS
31-
#
32-
~/skills/302ai-search/venv/Scripts/activate # Windows
33-
34-
pip install requests
35-
```
36-
3724
## 配置 API Key
3825

39-
### 工作原理
40-
41-
本 skill 声明了 `primaryEnv: AI302_API_KEY`。OpenClaw 会自动将你配置的 `apiKey` 值注入到 `AI302_API_KEY` 环境变量中供脚本读取。
42-
43-
### 配置方式(推荐)
44-
4526
编辑 `~/.openclaw/openclaw.json`,添加:
4627

4728
```json
4829
{
49-
"skills": {
50-
"entries": {
51-
"302ai-search": {
52-
"enabled": true,
53-
"apiKey": "sk-你的APIKey"
54-
}
55-
}
56-
}
30+
"skills": {
31+
"entries": {
32+
"302ai-search": {
33+
"enabled": true,
34+
"apiKey": "sk-你的APIKey"
35+
}
36+
}
37+
}
5738
}
5839
```
5940

60-
### 使配置生效
41+
使配置生效
6142

6243
```bash
6344
openclaw gateway restart
@@ -69,7 +50,7 @@ openclaw gateway restart
6950

7051
配置完成后,可以直接问 Agent:
7152

72-
> "用 302ai-search 搜一下今天的新闻,供应商用 search1_news"
53+
> "用 302ai-search 搜一下今天的新闻"
7354
> "帮我用 metaso 搜索学术论文,只看第一页"
7455
7556
### 直接调用脚本
@@ -81,147 +62,94 @@ python3 ~/skills/302ai-search/scripts/302ai-search.py "搜索关键词"
8162
# 指定结果数量和搜索引擎
8263
python3 ~/skills/302ai-search/scripts/302ai-search.py "AI trends" --count 10 --provider tavily
8364

84-
# 指定特定的分类搜索 (如寻找指定分类的公司)
85-
python3 ~/skills/302ai-search/scripts/302ai-search.py "AI公司" --provider exa --category company
8665

87-
# 域名过滤
66+
# 其他用法
67+
python3 ~/skills/302ai-search/scripts/302ai-search.py "AI公司" --provider exa --category company
8868
python3 ~/skills/302ai-search/scripts/302ai-search.py "技术文章" --include-domains example.com,techblog.com
89-
90-
# 学术搜索并分页
91-
python3 ~/skills/302ai-search/scripts/302ai-search.py "大模型进展" --provider metaso --category scholar --page 1
92-
93-
# 指定时间范围
94-
python3 ~/skills/302ai-search/scripts/302ai-search.py "今日新闻" --time-range day
95-
96-
# 排除图片
97-
python3 ~/skills/302ai-search/scripts/302ai-search.py "搜索词" --no-images
98-
99-
# 输出原始JSON响应
100-
python3 ~/skills/302ai-search/scripts/302ai-search.py "搜索词" --json
69+
python3 ~/skills/302ai-search/scripts/302ai-search.py "学术论文" --provider metaso --category scholar --page 1
10170
```
10271

10372
### 命令行参数
10473

105-
| 参数 | 简写 | 说明 | 默认值 |
106-
| ------------------------- | ---- | ------------------------------------------------------------ | ------ |
107-
| `query` | - | 搜索关键词(必需) | - |
108-
| `--count` | `-c` | 返回结果数量 | 5 |
109-
| `--provider` | `-p` | 搜索供应商 | tavily |
110-
| `--time-range` | `-t` | 时间范围 (time_range),如 day, week, month, year | - |
111-
| `--category` | - | 搜索分类,具体值因供应商而异 (如 general, news, company 等) | - |
112-
| `--no-images` | - | 排除图片结果 | false |
113-
| `--include-domains` | - | 域名白名单,逗号分隔 (如: `example.com,techblog.com`) | - |
114-
| `--exclude-domains` | - | 域名黑名单,逗号分隔 (如: `spam.com,ads.com`) | - |
115-
| `--start-crawl-date` | - | `exa` 专用: 爬取起始时间 (ISO8601 格式) | - |
116-
| `--end-crawl-date` | - | `exa` 专用: 爬取结束时间 (ISO8601 格式) | - |
117-
| `--start-published-date` | - | `exa` 专用: 发布起始时间 (ISO8601 格式) | - |
118-
| `--end-published-date` | - | `exa` 专用: 发布结束时间 (ISO8601 格式) | - |
119-
| `--crawl-results` | - | `search1_*` 专用: 爬取完整网页内容的数量 | - |
120-
| `--include-row-content` | - | `metaso` 专用: 返回页面完整文本内容 (可能产生额外费用) | - |
121-
| `--page` | - | 分页页码 (`metaso`/`unifuncs` 专用,metaso 1 page = 10 条) | - |
122-
| `--max-tokens-per-page` | - | `perplexity` 专用: 每页返回的最大 Token 数量 | - |
123-
| `--country` | - | `perplexity` 专用: 按国家/地区过滤结果 | - |
124-
| `--json` | `-j` | 输出原始JSON响应 | false |
74+
| 参数 | 简写 | 说明 | 默认值 |
75+
|------|------|------|--------|
76+
| `query` | - | 搜索关键词(必需) | - |
77+
| `--count` | `-c` | 返回结果数量 | 5 |
78+
| `--provider` | `-p` | 搜索供应商 | tavily |
79+
| `--time-range` | `-t` | 时间范围 (day, week, month, year) | - |
80+
| `--category` | - | 搜索分类 | - |
81+
| `--no-images` | - | 排除图片结果 | false |
82+
| `--include-domains` | - | 域名白名单,逗号分隔 | - |
83+
| `--exclude-domains` | - | 域名黑名单,逗号分隔 | - |
84+
| `--no-fallback` | - | 禁用供应商自动切换 | false |
85+
| `--json` | `-j` | 输出原始JSON响应 | false |
86+
87+
## 供应商自动切换
88+
89+
当指定供应商请求失败时,脚本会自动尝试其他供应商(按优先级顺序)。
90+
91+
**供应商优先级:**
92+
1. `tavily` (默认)
93+
2. `search1_search`
94+
3. `metaso`
95+
4. `exa`
96+
5. `bocha`
97+
6. `firecrawl`
98+
7. `perplexity`
99+
8. `unifuncs`
100+
9. `search1_news`
101+
102+
**使用示例:**
125103

126-
## 输出格式
127-
128-
### 标准输出格式
129-
130-
脚本返回 JSON 格式:
104+
```bash
105+
# 如果 tavily 失败,会自动尝试其他供应商
106+
python3 ~/skills/302ai-search/scripts/302ai-search.py "今日新闻"
131107

132-
```json
133-
{
134-
"query": "搜索关键词",
135-
"count": 5,
136-
"provider": "tavily",
137-
"results": [
138-
{
139-
"title": "标题",
140-
"url": "https://...",
141-
"snippet": "摘要内容",
142-
"content": "完整网页内容",
143-
"published_at": "2024-01-01",
144-
"summary": "摘要",
145-
"score": 0.85,
146-
"images": []
147-
}
148-
],
149-
"images": ["https://..."],
150-
"response_time": 0.95,
151-
"request_id": "xxx-xxx-xxx"
152-
}
108+
# 禁用自动切换,失败直接报错
109+
python3 ~/skills/302ai-search/scripts/302ai-search.py "今日新闻" --no-fallback
153110
```
154111

155-
- `query`:原始搜索词
156-
- `count`:返回结果数量
157-
- `provider`:使用的搜索引擎
158-
- `results`:搜索结果列表
159-
- `title`:网页标题
160-
- `url`:网页链接
161-
- `snippet`:内容摘要
162-
- `content`:完整网页内容(如有)
163-
- `published_at`:发布日期(如有)
164-
- `summary`:AI 生成的摘要(如有)
165-
- `score`:相关性分数(如有)
166-
- `images`:相关图片(如有)
167-
- `images`:搜索结果中的图片列表
168-
- `response_time`:API 响应时间(秒)
169-
- `request_id`:请求 ID
170-
171-
### 原始 JSON 输出(--json)
172-
173-
使用 `--json` 参数可获取 302 API 的原始响应,包含所有字段:
112+
当发生切换时,输出结果会包含 `_fallback_notice` 字段提示用户。
113+
114+
## 输出格式
174115

175116
```json
176117
{
177-
"search_results": [...],
178-
"data": {
179-
"query": "搜索词",
180-
"images": [...],
181-
"results": [...],
118+
"query": "搜索关键词",
119+
"count": 5,
120+
"provider": "tavily",
121+
"results": [
122+
{
123+
"title": "标题",
124+
"url": "https://...",
125+
"snippet": "摘要内容",
126+
"content": "完整网页内容",
127+
"published_at": "2024-01-01",
128+
"summary": "摘要",
129+
"score": 0.85,
130+
"images": []
131+
}
132+
],
133+
"images": ["https://..."],
182134
"response_time": 0.95,
183-
"request_id": "xxx-xxx-xxx"
184-
},
185-
"images": [...]
135+
"request_id": "xxx-xxx-xxx",
136+
"_fallback_notice": "原供应商 'tavily' 失败,已自动切换至 'search1_search'"
186137
}
187138
```
188139

189-
## 支持的供应商及其特定参数
190-
191-
| 供应商 | provider 值 | 分类 (category) | 时间范围 (time_range) | 特殊参数说明 |
192-
| -------------- | ---------------- | ---------------- | -------------------- | ------------- |
193-
| Tavily | `tavily` | `general`, `news` | `day`, `week`, `month`, `year` | 默认供应商,高质量综合搜索 |
194-
| Search1 | `search1_search` | `google`, `bing`| `day`, `month`, `year` | 支持 `crawl_results` 爬取全网页 |
195-
| Search1 News | `search1_news` | 同上 | 同上 | 专注于新闻 |
196-
| Bocha | `bocha` | - | `oneDay`, `oneWeek`| 中文搜索优化 |
197-
| Exa | `exa` | `company`, `news`, `pdf`| - | 不支持 time_range,使用专用的四个 Date 参数替代 |
198-
| Metaso | `metaso` | `webpage`, `scholar`, `video`| - | 不支持 time_range。支持 `page`, `include_row_content` |
199-
| Firecrawl | `firecrawl` | - | `day`, `hour`, `week`| - |
200-
| Perplexity | `perplexity` | - | - | 不支持 time_range。限制: `max_results` ≤ 20. 支持 `country`, `max_tokens_per_page` |
201-
| Unifuncs | `unifuncs` | - | `Day`, `Week`, `Month`, `Year` | 支持 `page` 分页 |
202-
203-
*- 其他 Search1 分类: `duckduckgo`, `yahoo`, `youtube`, `x`, `reddit`, `github`, `arxiv`, `wechat`, `bilibili`, `imdb`, `wikipedia`.*
204-
205-
**注意**:为避免触发 API 报错,脚本内部会自动检查你传递的 `time_range` 是否被该 `provider` 真正支持;如果传递给不支持它的引擎(如 `metaso``exa`),将会在这边直接抛出异常拦截。
206-
207-
## API 参考
140+
## 支持的供应商
208141

209-
- **端点**`POST https://api.302.ai/302/general/search`
210-
- **认证**`Authorization: Bearer {{API_KEY}}`
211-
- **Content-Type**`application/json`
212-
213-
### 请求参数示例 (API 层面)
214-
215-
```json
216-
{
217-
"query": "人工智能最新进展",
218-
"provider": "tavily",
219-
"max_results": 10,
220-
"time_range": "week",
221-
"category": "news",
222-
"include_images": true
223-
}
224-
```
142+
| 供应商 | provider 值 | 分类 (category) | 时间范围 |
143+
|--------|-------------|-----------------|----------|
144+
| Tavily | `tavily` | `general`, `news` | `day`, `week`, `month`, `year` |
145+
| Search1 | `search1_search` | `google`, `bing`| `day`, `month`, `year` |
146+
| Search1 News | `search1_news` | 同上 | 同上 |
147+
| Bocha | `bocha` | - | `oneDay`, `oneWeek`|
148+
| Exa | `exa` | `company`, `news`, `pdf`| - |
149+
| Metaso | `metaso` | `webpage`, `scholar`, `video`| - |
150+
| Firecrawl | `firecrawl` | - | `day`, `hour`, `week`|
151+
| Perplexity | `perplexity` | - | - |
152+
| Unifuncs | `unifuncs` | - | `Day`, `Week`, `Month`, `Year` |
225153

226154
## 最佳实践
227155

@@ -235,19 +163,8 @@ python3 ~/skills/302ai-search/scripts/302ai-search.py "搜索词" --json
235163
- 找微信公众号文章:`--provider search1_search --category wechat`
236164
3. **域名过滤**:找技术资料时限定具体网站,如 `--include-domains github.com,stackoverflow.com`
237165

238-
### 节省 API 费用/提高速度
239-
240-
1. **限制结果数量**`--count 5` 而不是默认的 10 (Perplexity 供应商受限为最多 20)。
241-
2. **谨慎使用抓取参数**:如非必需,避免在 `metaso` 开启 `--include-row-content`(因内容大可能产生额外计费),或者在 `search1_*` 设置过大的 `--crawl-results`
242-
3. **排除图片**`--no-images` 减少数据传输。
243-
244-
### 错误处理
245-
246-
脚本会自动处理常见错误:
247-
- API 余额不足
248-
- 尝试为 provider 传递了不支持的 time_range 或 category 报错
249-
- 无效的 provider
250-
- 网络超时
251-
- 参数验证失败
166+
### 节省 API 费用
252167

253-
错误信息会通过标准错误输出(stderr)显示。
168+
1. **限制结果数量**`--count 5` 而不是默认的 10
169+
2. **谨慎使用抓取参数**:避免在 `metaso` 开启 `--include-row-content`(可能产生额外计费)
170+
3. **排除图片**`--no-images` 减少数据传输

0 commit comments

Comments
 (0)