@elizaos/plugin-web-search 0.1.7 → 0.1.8
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 +225 -0
- package/package.json +3 -3
package/README.MD
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# @elizaos/plugin-web-search
|
|
2
|
+
|
|
3
|
+
A plugin for powerful web search capabilities, providing efficient search query handling and result processing through a customizable API interface.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This plugin provides functionality to:
|
|
8
|
+
|
|
9
|
+
- Execute web search queries with customizable parameters
|
|
10
|
+
- Process and format search results
|
|
11
|
+
- Handle search API authentication
|
|
12
|
+
- Manage token limits and response sizes
|
|
13
|
+
- Optimize query performance
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm install @elizaos/plugin-web-search
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Configuration
|
|
22
|
+
|
|
23
|
+
The plugin requires the following environment variables:
|
|
24
|
+
|
|
25
|
+
```env
|
|
26
|
+
TAVILY_API_KEY=your_api_key # Required: API key for search service
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
Import and register the plugin in your Eliza configuration:
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { webSearchPlugin } from "@elizaos/plugin-web-search";
|
|
35
|
+
|
|
36
|
+
export default {
|
|
37
|
+
plugins: [webSearchPlugin],
|
|
38
|
+
// ... other configuration
|
|
39
|
+
};
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Features
|
|
43
|
+
|
|
44
|
+
### Web Search
|
|
45
|
+
|
|
46
|
+
The plugin provides comprehensive web search capabilities:
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { webSearch } from "@elizaos/plugin-web-search";
|
|
50
|
+
|
|
51
|
+
// Execute a search query
|
|
52
|
+
const result = await webSearch.handler(
|
|
53
|
+
runtime,
|
|
54
|
+
{
|
|
55
|
+
content: { text: "What is the latest news about AI?" },
|
|
56
|
+
},
|
|
57
|
+
state,
|
|
58
|
+
{},
|
|
59
|
+
callback
|
|
60
|
+
);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Token Management
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
// The plugin automatically handles token limits
|
|
67
|
+
const DEFAULT_MAX_WEB_SEARCH_TOKENS = 4000;
|
|
68
|
+
|
|
69
|
+
// Example of token-limited response
|
|
70
|
+
const response = MaxTokens(searchResult, DEFAULT_MAX_WEB_SEARCH_TOKENS);
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Development
|
|
74
|
+
|
|
75
|
+
### Building
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pnpm run build
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Testing
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pnpm run test
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Development Mode
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
pnpm run dev
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Dependencies
|
|
94
|
+
|
|
95
|
+
- `@elizaos/core`: Core Eliza functionality
|
|
96
|
+
- `js-tiktoken`: Token counting and management
|
|
97
|
+
- `tsup`: Build tool
|
|
98
|
+
- Other standard dependencies listed in package.json
|
|
99
|
+
|
|
100
|
+
## API Reference
|
|
101
|
+
|
|
102
|
+
### Core Interfaces
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
interface Action {
|
|
106
|
+
name: "WEB_SEARCH";
|
|
107
|
+
similes: string[];
|
|
108
|
+
description: string;
|
|
109
|
+
validate: (runtime: IAgentRuntime, message: Memory) => Promise<boolean>;
|
|
110
|
+
handler: (
|
|
111
|
+
runtime: IAgentRuntime,
|
|
112
|
+
message: Memory,
|
|
113
|
+
state: State,
|
|
114
|
+
options: any,
|
|
115
|
+
callback: HandlerCallback
|
|
116
|
+
) => Promise<void>;
|
|
117
|
+
examples: Array<Array<any>>;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
interface SearchResult {
|
|
121
|
+
title: string;
|
|
122
|
+
url: string;
|
|
123
|
+
answer?: string;
|
|
124
|
+
results?: Array<{
|
|
125
|
+
title: string;
|
|
126
|
+
url: string;
|
|
127
|
+
}>;
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Plugin Methods
|
|
132
|
+
|
|
133
|
+
- `webSearch.handler`: Main method for executing searches
|
|
134
|
+
- `generateWebSearch`: Core search generation function
|
|
135
|
+
- `MaxTokens`: Token limit management function
|
|
136
|
+
- `getTotalTokensFromString`: Token counting utility
|
|
137
|
+
|
|
138
|
+
## Common Issues/Troubleshooting
|
|
139
|
+
|
|
140
|
+
### Issue: API Authentication Failures
|
|
141
|
+
|
|
142
|
+
- **Cause**: Invalid or missing Tavily API key
|
|
143
|
+
- **Solution**: Verify TAVILY_API_KEY environment variable
|
|
144
|
+
|
|
145
|
+
### Issue: Token Limit Exceeded
|
|
146
|
+
|
|
147
|
+
- **Cause**: Search results exceeding maximum token limit
|
|
148
|
+
- **Solution**: Results are automatically truncated to fit within limits
|
|
149
|
+
|
|
150
|
+
### Issue: Search Rate Limiting
|
|
151
|
+
|
|
152
|
+
- **Cause**: Too many requests in short time
|
|
153
|
+
- **Solution**: Implement proper request throttling
|
|
154
|
+
|
|
155
|
+
## Security Best Practices
|
|
156
|
+
|
|
157
|
+
- Store API keys securely using environment variables
|
|
158
|
+
- Validate all search inputs
|
|
159
|
+
- Implement proper error handling
|
|
160
|
+
- Keep dependencies updated
|
|
161
|
+
- Monitor API usage and rate limits
|
|
162
|
+
- Use HTTPS for API communication
|
|
163
|
+
|
|
164
|
+
## Example Usage
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
// Basic search
|
|
168
|
+
const searchQuery = "Latest developments in quantum computing";
|
|
169
|
+
const results = await generateWebSearch(searchQuery, runtime);
|
|
170
|
+
|
|
171
|
+
// With formatted response
|
|
172
|
+
if (results && results.results.length) {
|
|
173
|
+
const formattedResponse = `${results.answer}\n\nFor more details, check out:\n${results.results
|
|
174
|
+
.map(
|
|
175
|
+
(result, index) => `${index + 1}. [${result.title}](${result.url})`
|
|
176
|
+
)
|
|
177
|
+
.join("\n")}`;
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Configuration Options
|
|
182
|
+
|
|
183
|
+
### Token Management
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
const DEFAULT_MODEL_ENCODING = "gpt-3.5-turbo";
|
|
187
|
+
const DEFAULT_MAX_WEB_SEARCH_TOKENS = 4000;
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Search Actions
|
|
191
|
+
|
|
192
|
+
The plugin includes multiple search action similes:
|
|
193
|
+
|
|
194
|
+
- SEARCH_WEB
|
|
195
|
+
- INTERNET_SEARCH
|
|
196
|
+
- LOOKUP
|
|
197
|
+
- QUERY_WEB
|
|
198
|
+
- FIND_ONLINE
|
|
199
|
+
- And more...
|
|
200
|
+
|
|
201
|
+
## Contributing
|
|
202
|
+
|
|
203
|
+
Contributions are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) file for more information.
|
|
204
|
+
|
|
205
|
+
## Credits
|
|
206
|
+
|
|
207
|
+
This plugin integrates with and builds upon several key technologies:
|
|
208
|
+
|
|
209
|
+
- [Tavily API](https://tavily.com/): Advanced search and content analysis API
|
|
210
|
+
- [js-tiktoken](https://github.com/dqbd/tiktoken): Token counting for API responses
|
|
211
|
+
- [Zod](https://github.com/colinhacks/zod): TypeScript-first schema validation
|
|
212
|
+
|
|
213
|
+
Special thanks to:
|
|
214
|
+
|
|
215
|
+
- The Eliza community for their contributions and feedback
|
|
216
|
+
|
|
217
|
+
For more information about the search capabilities and tools:
|
|
218
|
+
|
|
219
|
+
- [Tavily API Documentation](https://docs.tavily.com/)
|
|
220
|
+
- [Token Management Guide](https://github.com/dqbd/tiktoken#readme)
|
|
221
|
+
- [Search API Best Practices](https://docs.tavily.com/docs/guides/best-practices)
|
|
222
|
+
|
|
223
|
+
## License
|
|
224
|
+
|
|
225
|
+
This plugin is part of the Eliza project. See the main project repository for license information.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elizaos/plugin-web-search",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8+build.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"dist"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@elizaos/core": "0.1.
|
|
22
|
+
"@elizaos/core": "0.1.8+build.1",
|
|
23
23
|
"tsup": "8.3.5"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"whatwg-url": "7.1.0"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "d55c86c961960b4b34528c358eb34b2ff4b34d87"
|
|
33
33
|
}
|