llm-test-bench 0.1.0

A production-grade CLI for testing and benchmarking LLM applications with support for GPT-5, Claude Opus 4, Gemini 2.5, and 65+ models
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
# LLM Test Bench CLI

A production-grade CLI for testing and benchmarking Large Language Model (LLM) applications.

## Phase 1 Implementation Status

This is the **Phase 1 (Milestone 1.3)** implementation of the CLI scaffolding, focusing on command structure and configuration management.

### Completed Features

- Complete Clap-based CLI command structure with derive API
- `config init` command with interactive setup wizard
- Command stubs for `test`, `bench`, and `eval` (full implementation in later phases)
- Shell completion generation for bash, zsh, fish, PowerShell, and elvish
- Comprehensive integration tests with assert_cmd (30 tests, all passing)
- Error handling with anyhow
- Global flags for verbose output and color control

## Installation

### Building from Source

```bash
# Clone the repository
git clone https://github.com/llm-test-bench/llm-test-bench.git
cd llm-test-bench

# Build the CLI
cargo build --release --package llm-test-bench

# The binary will be at: target/release/llm-test-bench
```

### Development Build

```bash
cargo build --package llm-test-bench
```

## Usage

### Basic Commands

```bash
# Show help
llm-test-bench --help

# Show version
llm-test-bench --version

# Enable verbose output (global flag)
llm-test-bench --verbose <COMMAND>

# Disable colored output
llm-test-bench --no-color <COMMAND>
```

### Configuration Management

#### Initialize Configuration

```bash
# Interactive setup wizard
llm-test-bench config init

# Non-interactive mode (uses defaults)
llm-test-bench config init --non-interactive

# Initialize specific provider only
llm-test-bench config init --provider openai
```

The `config init` command will:
1. Guide you through an interactive setup
2. Create a configuration file at `~/.config/llm-test-bench/config.toml`
3. Prompt for API key preferences (environment variable recommended)
4. Configure default models and parameters

#### Show Configuration

```bash
# Display current configuration
llm-test-bench config show

# Show with full TOML content
llm-test-bench config show --verbose
```

#### Validate Configuration

```bash
# Validate default config file
llm-test-bench config validate

# Validate specific config file
llm-test-bench config validate --config /path/to/config.toml
```

### Test Command (Phase 2)

```bash
# Run a single test (stub - coming in Phase 2)
llm-test-bench test openai --prompt "Hello, world!" --model gpt-4

# With additional parameters
llm-test-bench test anthropic \
  --prompt "Explain quantum computing" \
  --model claude-sonnet-4 \
  --temperature 0.7 \
  --max-tokens 1000

# With expected output for validation
llm-test-bench test openai \
  --prompt "What is 2+2?" \
  --expect "4"

# Save results to file
llm-test-bench test openai \
  --prompt "Test prompt" \
  --save ./results.json
```

### Benchmark Command (Phase 3)

```bash
# Run benchmark (stub - coming in Phase 3)
llm-test-bench bench \
  --dataset ./prompts.json \
  --providers openai,anthropic

# With concurrency and iterations
llm-test-bench bench \
  --dataset ./prompts.json \
  --providers openai,anthropic \
  --concurrency 4 \
  --iterations 10

# With caching and output format
llm-test-bench bench \
  --dataset ./dataset.json \
  --providers openai \
  --cache \
  --format html \
  --output ./benchmark-results
```

### Evaluation Command (Phase 4)

```bash
# Evaluate results (stub - coming in Phase 4)
llm-test-bench eval \
  --results ./results.json \
  --metrics accuracy,latency,cost

# With baseline comparison
llm-test-bench eval \
  --results ./results.json \
  --baseline ./baseline.json \
  --metrics all

# With visualizations
llm-test-bench eval \
  --results ./results.json \
  --visualize \
  --format html \
  --output ./evaluation-report
```

### Shell Completions

Generate shell completions for your shell:

```bash
# Bash
llm-test-bench completions bash > ~/.local/share/bash-completion/completions/llm-test-bench

# Zsh
llm-test-bench completions zsh > ~/.zfunc/_llm-test-bench

# Fish
llm-test-bench completions fish > ~/.config/fish/completions/llm-test-bench.fish

# PowerShell
llm-test-bench completions powershell > llm-test-bench.ps1

# Elvish
llm-test-bench completions elvish > ~/.elvish/lib/completions/llm-test-bench.elv
```

## Command Aliases

All major commands have short aliases:

- `test``t`
- `bench``b`
- `eval``e`

```bash
# These are equivalent:
llm-test-bench test openai --prompt "test"
llm-test-bench t openai --prompt "test"
```

## Configuration File Format

The configuration file uses TOML format and is stored at `~/.config/llm-test-bench/config.toml`:

```toml
version = "1.0"

[providers.openai]
type = "openai"
api_key_env = "OPENAI_API_KEY"  # Recommended: use environment variable
base_url = "https://api.openai.com/v1"

[providers.openai.defaults]
model = "gpt-4"
temperature = 0.7
max_tokens = 4096

[providers.anthropic]
type = "anthropic"
api_key_env = "ANTHROPIC_API_KEY"

[providers.anthropic.defaults]
model = "claude-sonnet-4-20250514"
temperature = 0.7

[defaults]
output_dir = "./test-results"
cache_enabled = true
```

## Testing

### Running Tests

```bash
# Run all CLI tests
cargo test --package llm-test-bench

# Run only unit tests
cargo test --package llm-test-bench --lib

# Run only integration tests
cargo test --package llm-test-bench --test integration

# Run with output
cargo test --package llm-test-bench -- --nocapture

# Run specific test
cargo test --package llm-test-bench test_help_command
```

### Test Coverage

Current test suite (Phase 1):
- **6 unit tests**: Argument parsing and configuration serialization
- **24 integration tests**: End-to-end CLI behavior testing

All 30 tests passing.

## Architecture

### CLI Structure

```
cli/
├── src/
│   ├── main.rs                      # Entry point, command routing
│   ├── commands/
│   │   ├── mod.rs                   # Command module declarations
│   │   ├── config.rs                # Config init/show/validate (COMPLETE)
│   │   ├── test.rs                  # Test command stub (Phase 2)
│   │   ├── bench.rs                 # Benchmark command stub (Phase 3)
│   │   └── eval.rs                  # Evaluation command stub (Phase 4)
│   └── lib.rs                       # (Future: shared utilities)
├── tests/
│   └── integration/
│       ├── main.rs                  # Test module entry
│       └── cli_tests.rs             # Integration tests
└── Cargo.toml
```

### Command Flow

```
User Input → Clap Parser → Command Router (main.rs) → Command Handler → Output
            Argument Validation
            Environment Setup
```

### Error Handling

The CLI uses `anyhow` for application-level error handling:

```rust
pub async fn execute(args: Args, verbose: bool) -> Result<()> {
    // Command implementation
    Ok(())
}
```

Errors are caught in `main.rs` and displayed with:
- Error message
- Chain of causes (in verbose mode)
- Appropriate exit code

## Development Guide

### Adding a New Command

1. Create a new file in `cli/src/commands/`:

```rust
// cli/src/commands/mynewcommand.rs
use anyhow::Result;
use clap::Args;

#[derive(Args, Debug)]
pub struct MyNewCommandArgs {
    /// Description of argument
    #[arg(short, long)]
    pub my_arg: String,
}

pub async fn execute(args: MyNewCommandArgs, verbose: bool) -> Result<()> {
    println!("Executing my new command");
    // Implementation here
    Ok(())
}
```

2. Add to `cli/src/commands/mod.rs`:

```rust
pub mod mynewcommand;
```

3. Add to command enum in `cli/src/main.rs`:

```rust
#[derive(Subcommand)]
enum Commands {
    // ... existing commands ...

    /// Description of my new command
    MyNewCommand(mynewcommand::MyNewCommandArgs),
}
```

4. Add to command router:

```rust
let result = match cli.command {
    // ... existing matches ...
    Commands::MyNewCommand(args) => mynewcommand::execute(args, cli.verbose).await,
};
```

5. Write integration tests in `cli/tests/integration/cli_tests.rs`.

### Adding Integration Tests

Use the `assert_cmd` crate for testing:

```rust
#[test]
fn test_my_new_command() {
    cli()
        .arg("mynewcommand")
        .arg("--my-arg")
        .arg("value")
        .assert()
        .success()
        .stdout(predicate::str::contains("expected output"));
}
```

## Phase 2+ Roadmap

### Phase 2: Test Command (Weeks 2-3)
- Implement provider integration (OpenAI, Anthropic)
- Add response generation and streaming
- Implement assertion validation
- Add result formatting and export

### Phase 3: Bench Command (Weeks 4-5)
- Implement multi-provider parallel execution
- Add dataset loading (JSON, YAML, CSV)
- Collect performance metrics
- Generate comparison reports

### Phase 4: Eval Command (Weeks 6-7)
- Implement metrics calculation
- Add baseline comparison
- Generate visualizations
- Create HTML/Markdown reports

## Contributing

When contributing to the CLI:

1. Follow Rust conventions and use `cargo fmt`
2. Add tests for all new features
3. Update this README for new commands
4. Ensure all tests pass: `cargo test --package llm-test-bench`
5. Test the CLI manually with various inputs

## License

MIT License - See LICENSE file

## Related Documentation

- [Main README]../README.md
- [Architecture Documentation]../docs/ARCHITECTURE.md
- [Implementation Roadmap]../docs/IMPLEMENTATION_ROADMAP.md
- [Quick Reference]../docs/QUICK_REFERENCE.md