You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -4,128 +4,163 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
4
4
5
5
## Project Overview
6
6
7
-
`rullm` is a Rust library and CLI for interacting with Large Language Models (LLMs). It consists of two main crates:
7
+
`rullm` is a Rust library and CLI for interacting with multiple LLM providers (OpenAI, Anthropic, Google AI, Groq, OpenRouter). The project uses a workspace structure with two main crates:
8
8
9
-
-**rullm-core**: The core library providing a high-performance LLM client with Tower middleware for enterprise features
10
-
-**rullm-cli**: A CLI tool built on top of rullm-core for interactive LLM usage
9
+
-**rullm-core**: Core library implementing provider integrations, middleware (Tower-based), and streaming support
10
+
-**rullm-cli**: Command-line interface built on top of rullm-core
11
11
12
12
## Architecture
13
13
14
-
### Core Library (rullm-core)
15
-
-**Providers**: Modular provider system supporting OpenAI, Groq, OpenRouter, Anthropic, and Google AI APIs
16
-
- OpenAI-compatible providers (OpenAI, Groq, OpenRouter) share implementation via `OpenAICompatibleProvider`
17
-
- Easily extensible to support any OpenAI-compatible API by adding a `ProviderIdentity`
18
-
-**Middleware**: Built on Tower for retry logic, rate limiting, circuit breakers, and timeouts
19
-
-**Dual APIs**: Simple string-based API and advanced API with full control over parameters
20
-
-**Streaming**: Real-time token-by-token streaming support via async streams
21
-
-**Types**: Comprehensive type system for chat messages, requests, responses, and configuration
14
+
### Provider System
22
15
23
-
### CLI Application (rullm-cli)
24
-
-**Commands**: Modular command structure for chat, models, aliases, keys, templates, etc.
25
-
-**Configuration**: TOML-based config management with user-defined aliases and templates
26
-
-**Interactive Chat**: Full-featured chat mode with history, slash commands, and editor integration
27
-
-**Templates**: TOML-based prompt templates with placeholder substitution
16
+
All LLM providers implement two core traits defined in `crates/rullm-core/src/types.rs`:
17
+
-`LlmProvider`: Base trait with provider metadata (name, aliases, env_key, default_base_url, available_models, health_check)
18
+
-`ChatCompletion`: Extends LlmProvider with chat completion methods (blocking and streaming)
28
19
29
-
## Development Commands
20
+
Provider implementations are in `crates/rullm-core/src/providers/`:
21
+
-`openai.rs`: OpenAI GPT models
22
+
-`anthropic.rs`: Anthropic Claude models
23
+
-`google.rs`: Google Gemini models
24
+
-`openai_compatible.rs`: Generic provider for OpenAI-compatible APIs
The `openai_compatible` provider is a generic implementation that other providers like Groq and OpenRouter extend. It uses a `ProviderIdentity` struct to define provider-specific metadata.
29
+
30
+
### Middleware Stack
31
+
32
+
The library uses Tower middleware for enterprise features (see `crates/rullm-core/src/middleware.rs`):
33
+
- Retry logic with exponential backoff
34
+
- Rate limiting
35
+
- Circuit breakers
36
+
- Timeouts
37
+
- Connection pooling
38
+
39
+
Configuration is done via `MiddlewareConfig` and `LlmServiceBuilder`.
40
+
41
+
### Simple API
42
+
43
+
`crates/rullm-core/src/simple.rs` provides a simplified string-based API (`SimpleLlmClient`, `SimpleLlmBuilder`) that wraps the advanced provider APIs for ease of use.
44
+
45
+
### CLI Architecture
46
+
47
+
The CLI entry point is `crates/rullm-cli/src/main.rs`, which:
48
+
1. Parses arguments using clap (see `args.rs`)
49
+
2. Loads configuration from `~/.config/rullm/` (see `config.rs`)
50
+
3. Dispatches to commands in `crates/rullm-cli/src/commands/`
51
+
52
+
Key CLI modules:
53
+
-`client.rs`: Creates provider clients from model strings (format: `provider:model`)
54
+
-`provider.rs`: Resolves provider names and aliases
cargo run -- chat --model groq/llama-3.3-70b-versatile
123
+
cargo run --example anthropic_simple
124
+
cargo run --example google_simple
125
+
cargo run --example openai_stream # Streaming example
126
+
cargo run --example test_all_providers # Test all providers at once
71
127
```
72
128
73
-
### Linting and Formatting
74
-
```bash
75
-
# Check code formatting
76
-
cargo fmt --check
129
+
### Adding a New Provider
77
130
78
-
# Format code
79
-
cargo fmt
131
+
When adding a new provider:
80
132
81
-
# Run clippy lints
82
-
cargo clippy
133
+
1.**OpenAI-compatible providers**: Use `OpenAICompatibleProvider` with a `ProviderIdentity` in `providers/openai_compatible.rs`. See `groq.rs` or `openrouter.rs` for examples.
83
134
84
-
# Run clippy with all targets
85
-
cargo clippy --all-targets --all-features
86
-
```
135
+
2.**Non-compatible providers**: Create a new file in `crates/rullm-core/src/providers/`:
136
+
- Implement `LlmProvider` and `ChatCompletion` traits
137
+
- Add provider config struct in `crates/rullm-core/src/config.rs`
138
+
- Export from `providers/mod.rs` and `lib.rs`
139
+
- Add client creation logic in `crates/rullm-cli/src/client.rs`
140
+
- Update `crates/rullm-cli/src/provider.rs` for CLI support
87
141
88
-
## Key Patterns and Conventions
142
+
3. Update `DEFAULT_MODELS` in `crates/rullm-core/src/simple.rs` if adding default model mappings
89
143
90
-
### Provider Implementation
91
-
- All providers implement the `ChatProvider` trait with `chat_completion` and `chat_completion_stream` methods
92
-
- Configuration structs follow the pattern `{Provider}Config` (e.g., `OpenAIConfig`, `AnthropicConfig`)
93
-
- OpenAI-compatible providers use `OpenAICompatibleConfig` with factory methods (`.groq()`, `.openrouter()`)
0 commit comments