Commit 28f26d1
committed
feat: Add cloud LLM provider support with Anthropic, OpenAI, and OpenAI-compatible APIs
This major update integrates cloud-based LLM providers alongside existing local
options, providing flexibility in deployment and usage.
## New Features
### LLM Provider Infrastructure
- Created unified `LLMProvider` trait for consistent provider interface
- Implemented `LLMProviderFactory` for dynamic provider instantiation
- Added comprehensive provider characteristics and configuration types
### Cloud Provider Implementations
- **Anthropic Claude**: Full support for Claude 3.5 (Opus, Sonnet, Haiku)
- 200K token context window
- Automatic retry with exponential backoff
- Feature-gated with `anthropic` flag
- **OpenAI**: Complete GPT-4o and GPT-4 Turbo support
- 128K token context window
- Organization ID support
- Feature-gated with `openai-llm` flag
- **OpenAI-Compatible**: Generic support for any OpenAI-compatible endpoint
- Works with LM Studio, vLLM, Ollama v1 API, etc.
- Optional API key authentication
- Feature-gated with `openai-compatible` flag
### Updated Existing Providers
- Refactored `QwenClient` to implement `LLMProvider` trait
- Maintained backward compatibility with existing code
- Enhanced with consistent error handling and metrics
### Interactive Setup Wizard
- Created `codegraph-setup` binary for guided configuration
- Interactive prompts for all provider types
- Supports both embedding and LLM provider selection
- Automatic configuration file generation at ~/.codegraph/config.toml
### Configuration Enhancements
- Extended `LLMConfig` with cloud provider fields:
- `anthropic_api_key`, `openai_api_key`
- `openai_compatible_url` for custom endpoints
- `max_tokens`, `timeout_secs` for fine-tuning
- Updated `.codegraph.toml.example` with comprehensive examples
- Added environment variable support (ANTHROPIC_API_KEY, OPENAI_API_KEY)
### Documentation
- Created comprehensive `docs/CLOUD_PROVIDERS.md` guide
- Provider comparison matrix
- Setup instructions for each provider
- Usage examples and code snippets
- Troubleshooting guide
- Security best practices
- Updated README.md with cloud provider quickstart
- Added provider-specific configuration examples
## Technical Details
### Architecture
- All cloud providers follow the same `LLMProvider` trait
- Async-first design with proper error propagation
- Configurable retry logic with exponential backoff
- Token usage tracking and metrics
- Streaming support (prepared for future implementation)
### Code Quality
- Feature flags for optional dependencies
- Comprehensive test coverage for factory and providers
- Type-safe configuration with serde
- Clear error messages for missing API keys
### Dependencies Added
- dialoguer: Interactive CLI prompts
- dirs: Cross-platform config directory detection
- Feature flags for optional cloud providers
## Migration Guide
Existing configurations continue to work without changes. To use cloud providers:
1. Enable desired features during build:
```bash
cargo build --features anthropic,openai-llm,openai-compatible
```
2. Run setup wizard or manually configure in .codegraph.toml:
```toml
[llm]
enabled = true
provider = "anthropic" # or "openai", "openai-compatible"
model = "claude-3-5-sonnet-20241022"
anthropic_api_key = "sk-ant-..."
```
## Files Changed
- Core implementation: 5 new provider files in codegraph-ai
- Factory: New llm_factory.rs for provider instantiation
- Configuration: Updated config_manager.rs with cloud fields
- Setup wizard: New codegraph-setup binary
- Documentation: New CLOUD_PROVIDERS.md guide
- Examples: Updated .codegraph.toml.example
## Breaking Changes
None. All changes are backward compatible with existing configurations.
## Future Enhancements
- Streaming response support
- Function calling for supported providers
- Response caching layer
- Cost tracking and optimization
- Multi-provider fallback strategies1 parent 4eb8f58 commit 28f26d1
File tree
14 files changed
+2518
-14
lines changed- crates
- codegraph-ai
- src
- codegraph-api
- src/bin
- codegraph-core/src
- docs
14 files changed
+2518
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
47 | 51 | | |
48 | 52 | | |
49 | 53 | | |
50 | | - | |
| 54 | + | |
51 | 55 | | |
52 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
53 | 60 | | |
54 | 61 | | |
55 | | - | |
| 62 | + | |
56 | 63 | | |
57 | 64 | | |
58 | | - | |
| 65 | + | |
59 | 66 | | |
60 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
61 | 80 | | |
62 | 81 | | |
| 82 | + | |
| 83 | + | |
63 | 84 | | |
64 | 85 | | |
65 | | - | |
| 86 | + | |
66 | 87 | | |
67 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
68 | 95 | | |
69 | 96 | | |
70 | 97 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 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 | + | |
51 | 96 | | |
52 | 97 | | |
53 | 98 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
0 commit comments