lc-cli 0.1.3

LLM Client - A fast Rust-based LLM CLI tool with provider management and chat sessions
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
---
sidebar_position: 17
---

# Search Commands

The `search` command allows you to integrate web search capabilities into your LLM prompts, providing real-time information and context from 6 different search providers.

## Overview

```bash
lc search [SUBCOMMAND]
```

The search functionality supports **6 search providers** with automatic type detection and can be used both as a standalone search tool and integrated into your LLM prompts.

## Supported Search Providers

| Provider | URL Pattern | API Key Required | Special Features |
|----------|-------------|------------------|------------------|
| **Brave** | `api.search.brave.com` | ✅ Yes | Fast, independent search |
| **Exa** | `api.exa.ai` | ✅ Yes | AI-powered neural search |
| **Serper** | `google.serper.dev` | ✅ Yes | Google search results |
| **SerpApi** | `serpapi.com` | ✅ Yes | Rich metadata, comprehensive results |
| **DuckDuckGo** | `api.duckduckgo.com` |**Free** | No API key needed |
| **Jina AI** | `s.jina.ai` | ✅ Yes | AI search + full content reading |

## Subcommands

### Provider Management

#### Add a Search Provider

```bash
lc search provider add <NAME> <URL>
# or
lc search p a <NAME> <URL>
```

Add a new search provider with **automatic type detection** from the URL pattern.

**Examples:**

```bash
# Add Brave Search (auto-detected as 'brave')
lc search provider add brave https://api.search.brave.com/res/v1/web/search

# Add Exa Search (auto-detected as 'exa')
lc search provider add exa https://api.exa.ai/search

# Add Serper (auto-detected as 'serper')
lc search provider add serper https://google.serper.dev/search

# Add SerpApi (auto-detected as 'serpapi')
lc search provider add serpapi https://serpapi.com/search

# Add DuckDuckGo (auto-detected as 'duckduckgo')
lc search provider add ddg https://api.duckduckgo.com/

# Add Jina AI (auto-detected as 'jina')
lc search provider add jina https://s.jina.ai/
```

#### List Search Providers

```bash
lc search provider list
# or
lc search p l
```

Display all configured search providers and their status.

#### Delete a Search Provider

```bash
lc search provider delete <NAME>
# or
lc search p d <NAME>
```

Remove a search provider from your configuration.

#### Set Provider Headers

```bash
lc search provider set <PROVIDER> <HEADER_NAME> <HEADER_VALUE>
# or
lc search p s <PROVIDER> <HEADER_NAME> <HEADER_VALUE>
```

Configure authentication headers and options for a search provider.

### Direct Search

```bash
lc search query <PROVIDER> <QUERY> [OPTIONS]
```

Perform a direct search using the specified provider.

**Options:**

- `-f, --format <FORMAT>`: Output format (`json` or `md`/`markdown`, default: `md`)
- `-n, --count <COUNT>`: Number of results to return (default: 5)

**Examples:**

```bash
# Markdown output (default)
lc search query brave "rust programming language"

# JSON output
lc search query jina "quantum computing" -f json

# Get 10 results
lc search query ddg "AI research papers" -n 10
```

## Integration with LLM Prompts

### Using --use-search Flag

The `--use-search` flag allows you to automatically include search results as context in your LLM prompts:

```bash
lc --use-search <PROVIDER> "Your prompt here"
```

**Examples:**

```bash
# Use default search query (your prompt)
lc --use-search brave "What are the latest developments in quantum computing?"

# Specify custom search query
lc --use-search "jina:quantum computing 2024" "Summarize the recent breakthroughs"
```

### Search Query Formats

When using `--use-search`, you can specify the search in two ways:

1. **Provider only**: Uses your prompt as the search query

   ```bash
   lc --use-search brave "What is happening with AI regulation?"
   ```

2. **Provider:query**: Uses a specific search query

   ```bash
   lc --use-search "brave:AI regulation EU 2024" "Analyze the implications"
   ```

## Configuration

### Set Default Search Provider

```bash
lc config set search <PROVIDER>
```

Set a default search provider for use with `--use-search`:

```bash
lc config set search brave
```

### Get Default Search Provider

```bash
lc config get search
```

### Delete Default Search Provider

```bash
lc config delete search
```

## Complete Setup Examples

### Brave Search Setup

```bash
# 1. Add Brave as a search provider (auto-detected)
lc search provider add brave https://api.search.brave.com/res/v1/web/search

# 2. Set your API key
lc search provider set brave X-Subscription-Token YOUR_BRAVE_API_KEY

# 3. Set as default provider (optional)
lc config set search brave

# 4. Test direct search
lc search query brave "OpenAI GPT-4" -f json

# 5. Use in LLM prompts
lc --use-search brave "What are the latest AI safety developments?"
```

### Exa Setup

```bash
# 1. Add Exa as a search provider (auto-detected)
lc search provider add exa https://api.exa.ai/search

# 2. Set your API key
lc search provider set exa x-api-key YOUR_EXA_API_KEY

# 3. Test direct search
lc search query exa "machine learning best practices" -f json

# 4. Use in LLM prompts
lc --use-search exa "What are the latest developments in neural networks?"
```

### Serper Setup

```bash
# 1. Add Serper as a search provider (auto-detected)
lc search provider add serper https://google.serper.dev/search

# 2. Set your API key
lc search provider set serper X-API-KEY YOUR_SERPER_API_KEY

# 3. Test direct search
lc search query serper "latest AI developments" -f json

# 4. Use in LLM prompts
lc --use-search serper "What are the current trends in artificial intelligence?"
```

### SerpApi Setup

```bash
# 1. Add SerpApi as a search provider (auto-detected)
lc search provider add serpapi https://serpapi.com/search

# 2. Set your API key
lc search provider set serpapi api_key YOUR_SERPAPI_KEY

# 3. Test direct search
lc search query serpapi "machine learning research 2024" -f json

# 4. Use in LLM prompts
lc --use-search serpapi "Summarize recent ML breakthroughs"
```

### DuckDuckGo Setup (Free!)

```bash
# 1. Add DuckDuckGo as a search provider (auto-detected)
lc search provider add ddg https://api.duckduckgo.com/

# 2. No API key required! ✅

# 3. Test direct search
lc search query ddg "rust programming tutorials" -f json

# 4. Use in LLM prompts
lc --use-search ddg "What are good resources for learning Rust?"
```

### Jina AI Setup (Advanced Features)

```bash
# 1. Add Jina AI as a search provider (auto-detected)
lc search provider add jina https://s.jina.ai/

# 2. Set your API key
lc search provider set jina Authorization YOUR_JINA_API_KEY

# 3. Test basic search
lc search query jina "rust async programming" -f json

# 4. Enable full content reading (X-Engine: direct)
lc search provider set jina X-Engine direct

# 5. Test with full content (much richer results!)
lc search query jina "rust async programming" -f json

# 6. Enable JSON format for structured responses
lc search provider set jina Accept application/json

# 7. Use in LLM prompts with rich content
lc --use-search jina "Explain Rust async programming concepts"
```

## Provider-Specific Features

### Jina AI Advanced Features

Jina AI offers unique capabilities beyond standard search:

#### Full Content Reading

Enable `X-Engine: direct` to get complete page content instead of just snippets:

```bash
# Enable full content reading
lc search provider set jina X-Engine direct

# Now searches return full page content (much richer!)
lc search query jina "topic" -f json
```

**Benefits:**
- ✅ Complete article content (thousands of characters)
- ✅ No need to visit individual URLs
- ✅ Perfect for research and AI analysis
- ⚠️ Slower response times
- ⚠️ Higher API costs

#### Response Formats

```bash
# Text format (default)
lc search query jina "topic"

# JSON format
lc search provider set jina Accept application/json
lc search query jina "topic" -f json
```

### DuckDuckGo (Free Option)

DuckDuckGo is the only provider that requires **no API key**:

```bash
# Just add and use - no authentication needed!
lc search provider add ddg https://api.duckduckgo.com/
lc search query ddg "your search query"
```

Perfect for:
- ✅ Testing search functionality
- ✅ Users without API budgets
- ✅ Privacy-focused searches
- ⚠️ Limited to basic instant answers

## Provider Comparison

| Feature | Brave | Exa | Serper | SerpApi | DuckDuckGo | Jina AI |
|---------|-------|-----|--------|---------|------------|---------|
| **Cost** | Paid | Paid | Paid | Paid | **Free** | Paid |
| **Search Quality** | High | AI-Enhanced | Google Results | Google Results | Basic | AI-Enhanced |
| **Speed** | Fast | Fast | Fast | Fast | Fast | Fast/Slow* |
| **Rich Snippets** ||||| Limited ||
| **Full Content** |||||| ✅* |
| **Metadata** ||||| Limited ||

*With X-Engine: direct enabled

## Authentication Headers

Each provider uses different authentication methods:

| Provider | Header Name | Format | Example |
|----------|-------------|--------|---------|
| **Brave** | `X-Subscription-Token` | Direct | `YOUR_API_KEY` |
| **Exa** | `x-api-key` | Direct | `YOUR_API_KEY` |
| **Serper** | `X-API-KEY` | Direct | `YOUR_API_KEY` |
| **SerpApi** | `api_key` | Query Param | `YOUR_API_KEY` |
| **DuckDuckGo** | None | N/A | No auth required |
| **Jina AI** | `Authorization` | Bearer | `Bearer YOUR_API_KEY` |

## Tips and Best Practices

1. **Start with DuckDuckGo**: Test search functionality for free before getting API keys
2. **API Keys**: Store your API keys securely and never commit them to version control
3. **Result Count**: For general queries, 3-5 results are sufficient. For research, consider 10+
4. **Query Optimization**: Be specific with your search queries for better results
5. **Provider Selection**: 
   - Use **DuckDuckGo** for free basic searches
   - Use **Brave/Serper** for general web search
   - Use **Exa** for AI-enhanced content discovery
   - Use **Jina AI** for research requiring full content
6. **Rate Limits**: Be aware of your search provider's rate limits and pricing
7. **Jina Full Content**: Only enable `X-Engine: direct` when you need comprehensive content

## Troubleshooting

### Common Issues

1. **401 Unauthorized**: Check your API key and header format

   ```bash
   # Check current providers
   lc search provider list
   
   # Set correct API key for each provider
   lc search provider set brave X-Subscription-Token YOUR_KEY
   lc search provider set jina Authorization YOUR_KEY
   ```

2. **Auto-detection failed**: Ensure you're using the correct URL pattern

   ```bash
   # These URLs will auto-detect correctly:
   lc search provider add brave https://api.search.brave.com/res/v1/web/search
   lc search provider add jina https://s.jina.ai/
   lc search provider add ddg https://api.duckduckgo.com/
   ```

3. **No results found**: Try a different provider or check your query

   ```bash
   # Test with free DuckDuckGo first
   lc search query ddg "test query"
   ```

4. **Jina parsing errors**: Check if you need both headers for JSON + full content

   ```bash
   lc search provider set jina Accept application/json
   lc search provider set jina X-Engine direct
   ```

## Examples

### Research Assistant with Full Content

```bash
# Use Jina with full content reading for comprehensive research
lc search provider set jina X-Engine direct
lc --use-search "jina:latest machine learning papers arxiv 2024" \
  "Summarize the most important recent developments in machine learning"
```

### Free News Analysis

```bash
# Use free DuckDuckGo for basic news queries
lc --use-search ddg "What happened in tech news today?"
```

### Fact Checking with Google Results

```bash
# Use Serper for Google-quality fact checking
lc --use-search "serper:climate change statistics 2024" \
  "Verify and explain the latest climate data"
```

### AI-Enhanced Content Discovery

```bash
# Use Exa for AI-powered content discovery
lc --use-search "exa:best practices machine learning 2024" \
  "What are the current ML best practices?"
```

### Competitive Analysis

```bash
# Use SerpApi for comprehensive competitive research
lc --use-search "serpapi:OpenAI competitors 2024" \
  "Analyze the current competitive landscape in AI"
```

## Getting API Keys

### Free Option
- **DuckDuckGo**: No API key required! ✅

### Paid Options
- **Brave Search**: [Get API Key]https://brave.com/search/api/
- **Exa**: [Get API Key]https://exa.ai/
- **Serper**: [Get API Key]https://serper.dev/
- **SerpApi**: [Get API Key]https://serpapi.com/
- **Jina AI**: [Get API Key]https://jina.ai/

Start with DuckDuckGo to test the functionality, then choose paid providers based on your specific needs!