ai-web-search 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -121
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,80 +1,68 @@
|
|
|
1
1
|
# AI Web Search
|
|
2
2
|
|
|
3
|
-
🔍 为AI助手提供联网搜索能力的轻量级工具
|
|
3
|
+
🔍 为AI助手提供联网搜索能力的轻量级工具 / A lightweight tool that enables AI assistants to search the internet
|
|
4
4
|
|
|
5
|
-
## 功能特点
|
|
5
|
+
## 功能特点 / Features
|
|
6
6
|
|
|
7
|
-
- **开箱即用**:从
|
|
7
|
+
- **开箱即用**:从npm安装后即可使用,无需复杂配置
|
|
8
|
+
**Ready to use**: Install from npm and start using immediately, no complex configuration needed
|
|
8
9
|
- **免费搜索**:使用 DuckDuckGo 搜索引擎,无需API密钥
|
|
10
|
+
**Free search**: Uses DuckDuckGo search engine, no API key required
|
|
9
11
|
- **智能回退**:DuckDuckGo不可用时自动切换到百度搜索,确保可用性
|
|
12
|
+
**Smart fallback**: Automatically switches to Baidu search when DuckDuckGo is unavailable, ensuring availability
|
|
10
13
|
- **兼容性强**:提供标准HTTP API,可与任何AI软件集成
|
|
14
|
+
**High compatibility**: Provides standard HTTP API, can be integrated with any AI software
|
|
11
15
|
- **轻量快速**:启动速度快,资源占用少
|
|
16
|
+
**Lightweight and fast**: Fast startup speed, low resource usage
|
|
12
17
|
- **隐私保护**:不记录搜索历史,保护用户隐私
|
|
18
|
+
**Privacy protection**: Does not record search history, protecting user privacy
|
|
13
19
|
|
|
14
|
-
## 安装
|
|
20
|
+
## 安装 / Installation
|
|
15
21
|
|
|
16
|
-
### 方式1
|
|
22
|
+
### 方式1:通过npm安装(推荐)/ Method 1: Install via npm (Recommended)
|
|
17
23
|
|
|
18
24
|
```bash
|
|
19
|
-
#
|
|
20
|
-
|
|
25
|
+
# 全局安装
|
|
26
|
+
npm install -g ai-web-search
|
|
21
27
|
|
|
22
|
-
#
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
# 安装依赖
|
|
26
|
-
npm install
|
|
27
|
-
|
|
28
|
-
# 创建全局命令(可选)
|
|
29
|
-
npm link
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
### 方式2:直接从GitHub安装
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
# 直接从GitHub安装
|
|
36
|
-
npm install git+https://github.com/your-username/ai-web-search.git
|
|
37
|
-
|
|
38
|
-
# 或者指定分支
|
|
39
|
-
npm install git+https://github.com/your-username/ai-web-search.git#main
|
|
28
|
+
# 或者本地安装
|
|
29
|
+
npm install ai-web-search
|
|
40
30
|
```
|
|
41
31
|
|
|
42
|
-
### 方式3:下载ZIP文件
|
|
43
32
|
|
|
44
|
-
1. 从GitHub下载ZIP文件
|
|
45
|
-
2. 解压到本地目录
|
|
46
|
-
3. 进入目录运行 `npm install`
|
|
47
33
|
|
|
48
|
-
## 快速开始
|
|
34
|
+
## 快速开始 / Quick Start
|
|
49
35
|
|
|
50
|
-
### 1. 启动服务器
|
|
36
|
+
### 1. 启动服务器 / Start the server
|
|
51
37
|
|
|
52
38
|
```bash
|
|
53
|
-
# 如果已创建全局命令
|
|
39
|
+
# 如果已创建全局命令 / If global command is created
|
|
54
40
|
ai-web-search
|
|
55
41
|
|
|
56
|
-
# 或者直接运行
|
|
42
|
+
# 或者直接运行 / Or run directly
|
|
57
43
|
node src/index.js
|
|
58
44
|
|
|
59
|
-
# 或者使用npm脚本
|
|
45
|
+
# 或者使用npm脚本 / Or use npm script
|
|
60
46
|
npm start
|
|
61
47
|
```
|
|
62
48
|
|
|
63
49
|
服务器默认运行在 `http://localhost:3000`
|
|
50
|
+
Server runs by default at `http://localhost:3000`
|
|
64
51
|
|
|
65
|
-
### 2. 测试搜索
|
|
52
|
+
### 2. 测试搜索 / Test search
|
|
66
53
|
|
|
67
54
|
```bash
|
|
68
|
-
# 使用curl测试
|
|
55
|
+
# 使用curl测试 / Test with curl
|
|
69
56
|
curl "http://localhost:3000/search?query=人工智能最新发展"
|
|
70
57
|
|
|
71
|
-
# 或者在浏览器中访问
|
|
58
|
+
# 或者在浏览器中访问 / Or visit in browser
|
|
72
59
|
http://localhost:3000/search?query=人工智能最新发展
|
|
73
60
|
```
|
|
74
61
|
|
|
75
|
-
### 3. 集成到AI软件
|
|
62
|
+
### 3. 集成到AI软件 / Integrate into AI software
|
|
76
63
|
|
|
77
64
|
在你的AI软件中添加以下工具配置:
|
|
65
|
+
Add the following tool configuration to your AI software:
|
|
78
66
|
|
|
79
67
|
```json
|
|
80
68
|
{
|
|
@@ -89,25 +77,25 @@ http://localhost:3000/search?query=人工智能最新发展
|
|
|
89
77
|
}
|
|
90
78
|
```
|
|
91
79
|
|
|
92
|
-
## 配置选项
|
|
80
|
+
## 配置选项 / Configuration Options
|
|
93
81
|
|
|
94
|
-
### 命令行参数
|
|
82
|
+
### 命令行参数 / Command Line Arguments
|
|
95
83
|
|
|
96
84
|
```bash
|
|
97
|
-
ai-web-search [
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
-p, --port
|
|
101
|
-
-H, --host
|
|
102
|
-
-d, --dev
|
|
103
|
-
-s, --search-function
|
|
104
|
-
-h, --help
|
|
105
|
-
-v, --version
|
|
85
|
+
ai-web-search [options]
|
|
86
|
+
|
|
87
|
+
Options:
|
|
88
|
+
-p, --port <port> Server port (default: 3000)
|
|
89
|
+
-H, --host <host> Server host (default: localhost)
|
|
90
|
+
-d, --dev Run in development mode
|
|
91
|
+
-s, --search-function <path> Path to custom search function module
|
|
92
|
+
-h, --help Show help information
|
|
93
|
+
-v, --version Show version number
|
|
106
94
|
```
|
|
107
95
|
|
|
108
|
-
### 环境变量
|
|
96
|
+
### 环境变量 / Environment Variables
|
|
109
97
|
|
|
110
|
-
创建 `.env`
|
|
98
|
+
创建 `.env` 文件:/ Create `.env` file:
|
|
111
99
|
|
|
112
100
|
```env
|
|
113
101
|
PORT=3000
|
|
@@ -116,9 +104,10 @@ RATE_LIMIT_MAX=100
|
|
|
116
104
|
SEARCH_FUNCTION_PATH=./examples/custom-search.js
|
|
117
105
|
```
|
|
118
106
|
|
|
119
|
-
### 自定义搜索引擎
|
|
107
|
+
### 自定义搜索引擎 / Custom Search Engine
|
|
120
108
|
|
|
121
109
|
如果默认的DuckDuckGo搜索引擎无法使用(如网络限制),你可以提供自定义搜索引擎实现。
|
|
110
|
+
If the default DuckDuckGo search engine is unavailable (e.g., network restrictions), you can provide a custom search engine implementation.
|
|
122
111
|
|
|
123
112
|
#### 创建自定义搜索引擎模块
|
|
124
113
|
|
|
@@ -161,23 +150,23 @@ SEARCH_FUNCTION_PATH=./custom-search.js
|
|
|
161
150
|
|
|
162
151
|
详细的自定义搜索引擎示例请参考 `examples/custom-search.js` 文件。
|
|
163
152
|
|
|
164
|
-
## API 文档
|
|
153
|
+
## API 文档 / API Documentation
|
|
165
154
|
|
|
166
|
-
### 搜索接口
|
|
155
|
+
### 搜索接口 / Search Endpoint
|
|
167
156
|
|
|
168
157
|
```
|
|
169
158
|
GET /search
|
|
170
159
|
```
|
|
171
160
|
|
|
172
|
-
**参数:**
|
|
161
|
+
**参数:** / **Parameters:**
|
|
173
162
|
|
|
174
|
-
| 参数 | 类型 | 必需 | 默认值 | 描述 |
|
|
163
|
+
| 参数 / Parameter | 类型 / Type | 必需 / Required | 默认值 / Default | 描述 / Description |
|
|
175
164
|
|------|------|------|--------|------|
|
|
176
|
-
| query | string | 是 | - | 搜索查询关键词 |
|
|
177
|
-
| limit | integer | 否 | 5 | 返回结果数量(1-20) |
|
|
178
|
-
| type | string | 否 | web | 搜索类型:web(网页)或 news(新闻) |
|
|
165
|
+
| query | string | 是 / Yes | - | 搜索查询关键词 / Search query keyword |
|
|
166
|
+
| limit | integer | 否 / No | 5 | 返回结果数量(1-20) / Number of results to return (1-20) |
|
|
167
|
+
| type | string | 否 / No | web | 搜索类型:web(网页)或 news(新闻) / Search type: web (webpage) or news (news articles) |
|
|
179
168
|
|
|
180
|
-
**响应示例:**
|
|
169
|
+
**响应示例:** / **Response Example:**
|
|
181
170
|
|
|
182
171
|
```json
|
|
183
172
|
{
|
|
@@ -195,13 +184,14 @@ GET /search
|
|
|
195
184
|
}
|
|
196
185
|
```
|
|
197
186
|
|
|
198
|
-
### 工具定义接口
|
|
187
|
+
### 工具定义接口 / Tool Definition Endpoint
|
|
199
188
|
|
|
200
189
|
```
|
|
201
190
|
GET /tool-definition
|
|
202
191
|
```
|
|
203
192
|
|
|
204
193
|
返回兼容 OpenAI 工具格式的 JSON 定义:
|
|
194
|
+
Returns JSON definition compatible with OpenAI tool format:
|
|
205
195
|
|
|
206
196
|
```json
|
|
207
197
|
{
|
|
@@ -234,21 +224,21 @@ GET /tool-definition
|
|
|
234
224
|
}
|
|
235
225
|
```
|
|
236
226
|
|
|
237
|
-
### 搜索建议接口
|
|
227
|
+
### 搜索建议接口 / Search Suggestions Endpoint
|
|
238
228
|
|
|
239
229
|
```
|
|
240
230
|
GET /suggest?query=部分关键词
|
|
241
231
|
```
|
|
242
232
|
|
|
243
|
-
### 健康检查接口
|
|
233
|
+
### 健康检查接口 / Health Check Endpoint
|
|
244
234
|
|
|
245
235
|
```
|
|
246
236
|
GET /health
|
|
247
237
|
```
|
|
248
238
|
|
|
249
|
-
## 使用示例
|
|
239
|
+
## 使用示例 / Usage Examples
|
|
250
240
|
|
|
251
|
-
### Python AI 助手集成
|
|
241
|
+
### Python AI 助手集成 / Python AI Assistant Integration
|
|
252
242
|
|
|
253
243
|
```python
|
|
254
244
|
import requests
|
|
@@ -260,12 +250,12 @@ def web_search(query, limit=5):
|
|
|
260
250
|
)
|
|
261
251
|
return response.json()
|
|
262
252
|
|
|
263
|
-
# 使用示例
|
|
253
|
+
# 使用示例 / Usage example
|
|
264
254
|
results = web_search("最新的AI技术")
|
|
265
255
|
print(results)
|
|
266
256
|
```
|
|
267
257
|
|
|
268
|
-
### JavaScript AI 助手集成
|
|
258
|
+
### JavaScript AI 助手集成 / JavaScript AI Assistant Integration
|
|
269
259
|
|
|
270
260
|
```javascript
|
|
271
261
|
async function webSearch(query, limit = 5) {
|
|
@@ -275,108 +265,92 @@ async function webSearch(query, limit = 5) {
|
|
|
275
265
|
return await response.json();
|
|
276
266
|
}
|
|
277
267
|
|
|
278
|
-
// 使用示例
|
|
268
|
+
// 使用示例 / Usage example
|
|
279
269
|
const results = await webSearch("机器学习最新进展");
|
|
280
270
|
console.log(results);
|
|
281
271
|
```
|
|
282
272
|
|
|
283
|
-
## 故障排除
|
|
273
|
+
## 故障排除 / Troubleshooting
|
|
284
274
|
|
|
285
|
-
### 1. 端口被占用
|
|
275
|
+
### 1. 端口被占用 / Port already in use
|
|
286
276
|
|
|
287
277
|
```bash
|
|
288
|
-
# 使用其他端口
|
|
278
|
+
# 使用其他端口 / Use a different port
|
|
289
279
|
ai-web-search -p 8080
|
|
290
280
|
```
|
|
291
281
|
|
|
292
|
-
### 2. 搜索无结果
|
|
282
|
+
### 2. 搜索无结果 / No search results
|
|
293
283
|
|
|
294
|
-
- 检查网络连接
|
|
295
|
-
- 尝试不同的搜索关键词
|
|
296
|
-
- 查看服务器日志
|
|
284
|
+
- 检查网络连接 / Check network connection
|
|
285
|
+
- 尝试不同的搜索关键词 / Try different search keywords
|
|
286
|
+
- 查看服务器日志 / Check server logs
|
|
297
287
|
|
|
298
|
-
### 3. 连接被拒绝
|
|
288
|
+
### 3. 连接被拒绝 / Connection refused
|
|
299
289
|
|
|
300
|
-
- 确认服务器正在运行
|
|
301
|
-
- 检查防火墙设置
|
|
302
|
-
- 验证端口是否正确
|
|
290
|
+
- 确认服务器正在运行 / Confirm server is running
|
|
291
|
+
- 检查防火墙设置 / Check firewall settings
|
|
292
|
+
- 验证端口是否正确 / Verify port is correct
|
|
303
293
|
|
|
304
|
-
### 4.
|
|
294
|
+
### 4. npm install失败 / npm install failed
|
|
305
295
|
|
|
306
296
|
```bash
|
|
307
|
-
#
|
|
308
|
-
git config --global http.proxy # 设置代理(如果需要)
|
|
309
|
-
|
|
310
|
-
# 或者使用SSH方式(需要配置SSH密钥)
|
|
311
|
-
git clone git@github.com:your-username/ai-web-search.git
|
|
312
|
-
|
|
313
|
-
# 如果证书问题,可以临时跳过SSL验证(不推荐)
|
|
314
|
-
git -c http.sslVerify=false clone https://github.com/your-username/ai-web-search.git
|
|
315
|
-
```
|
|
316
|
-
|
|
317
|
-
### 5. npm install失败
|
|
318
|
-
|
|
319
|
-
```bash
|
|
320
|
-
# 清除npm缓存
|
|
297
|
+
# 清除npm缓存 / Clear npm cache
|
|
321
298
|
npm cache clean --force
|
|
322
299
|
|
|
323
|
-
#
|
|
300
|
+
# 使用淘宝镜像(国内加速)/ Use Taobao mirror (China acceleration)
|
|
324
301
|
npm install --registry=https://registry.npmmirror.com
|
|
325
302
|
|
|
326
|
-
# 检查Node.js版本
|
|
327
|
-
node --version # 需要 >= 14.0.0
|
|
303
|
+
# 检查Node.js版本 / Check Node.js version
|
|
304
|
+
node --version # 需要 >= 14.0.0 / Requires >= 14.0.0
|
|
328
305
|
```
|
|
329
306
|
|
|
330
|
-
## 开发
|
|
307
|
+
## 开发 / Development
|
|
331
308
|
|
|
332
|
-
### 本地开发
|
|
309
|
+
### 本地开发 / Local Development
|
|
333
310
|
|
|
334
311
|
```bash
|
|
335
|
-
#
|
|
336
|
-
git clone https://github.com/your-username/ai-web-search.git
|
|
337
|
-
cd ai-web-search
|
|
338
|
-
|
|
339
|
-
# 安装依赖
|
|
312
|
+
# 安装依赖 / Install dependencies
|
|
340
313
|
npm install
|
|
341
314
|
|
|
342
|
-
# 开发模式运行
|
|
315
|
+
# 开发模式运行 / Run in development mode
|
|
343
316
|
npm run dev
|
|
344
317
|
|
|
345
|
-
# 运行测试
|
|
318
|
+
# 运行测试 / Run tests
|
|
346
319
|
npm test
|
|
347
320
|
```
|
|
348
321
|
|
|
349
|
-
### 项目结构
|
|
322
|
+
### 项目结构 / Project Structure
|
|
350
323
|
|
|
351
324
|
```
|
|
352
325
|
ai-web-search/
|
|
353
326
|
├── bin/
|
|
354
|
-
│ └── cli.js # 命令行入口
|
|
327
|
+
│ └── cli.js # 命令行入口 / Command line entry
|
|
355
328
|
├── src/
|
|
356
|
-
│ ├── index.js # 主入口
|
|
357
|
-
│ ├── server.js # HTTP服务器
|
|
358
|
-
│ └── search.js # 搜索引擎模块
|
|
329
|
+
│ ├── index.js # 主入口 / Main entry
|
|
330
|
+
│ ├── server.js # HTTP服务器 / HTTP server
|
|
331
|
+
│ └── search.js # 搜索引擎模块 / Search engine module
|
|
359
332
|
├── examples/
|
|
360
|
-
│ ├── custom-search.js # 自定义搜索引擎示例
|
|
361
|
-
│ └── baidu-search.js # 百度搜索引擎实现
|
|
333
|
+
│ ├── custom-search.js # 自定义搜索引擎示例 / Custom search engine example
|
|
334
|
+
│ └── baidu-search.js # 百度搜索引擎实现 / Baidu search engine implementation
|
|
362
335
|
├── test/
|
|
363
|
-
│ ├── test.js # 测试文件
|
|
364
|
-
│ └── test-custom.js # 自定义搜索测试
|
|
336
|
+
│ ├── test.js # 测试文件 / Test file
|
|
337
|
+
│ └── test-custom.js # 自定义搜索测试 / Custom search test
|
|
365
338
|
├── package.json
|
|
366
339
|
├── README.md
|
|
367
340
|
├── .gitignore
|
|
368
341
|
└── .env.example
|
|
369
342
|
```
|
|
370
343
|
|
|
371
|
-
## 许可证
|
|
344
|
+
## 许可证 / License
|
|
372
345
|
|
|
373
346
|
MIT License
|
|
374
347
|
|
|
375
|
-
## 贡献
|
|
348
|
+
## 贡献 / Contributing
|
|
376
349
|
|
|
377
|
-
|
|
350
|
+
欢迎提交问题和建议!
|
|
351
|
+
Issues and suggestions are welcome!
|
|
378
352
|
|
|
379
|
-
## 相关项目
|
|
353
|
+
## 相关项目 / Related Projects
|
|
380
354
|
|
|
381
|
-
- [duck-duck-scrape](https://github.com/Snazzah/duck-duck-scrape) - DuckDuckGo 搜索库
|
|
382
|
-
- [Express](https://expressjs.com/) - Web 框架
|
|
355
|
+
- [duck-duck-scrape](https://github.com/Snazzah/duck-duck-scrape) - DuckDuckGo 搜索库 / DuckDuckGo search library
|
|
356
|
+
- [Express](https://expressjs.com/) - Web 框架 / Web framework
|