|
| 1 | +# Multi-Provider Instance Support Implementation |
| 2 | + |
| 3 | +## Summary |
| 4 | + |
| 5 | +Implemented support for multiple instances of the same LLM provider type (e.g., multiple Ollama models) with different configurations. Users can now configure multiple providers of the same type by using unique names in their configuration. |
| 6 | + |
| 7 | +## Problem |
| 8 | + |
| 9 | +Previously, the system only supported one instance per provider type (openai, anthropic, ollama, vllm). Users couldn't configure multiple Ollama models or multiple OpenAI endpoints with different settings. The code tried to convert provider names directly to the `LLMProvider` enum, which failed for names like `ollama_qwen3`. |
| 10 | + |
| 11 | +## Solution |
| 12 | + |
| 13 | +### 1. Provider Type Extraction |
| 14 | + |
| 15 | +Added logic to extract the base provider type from provider names or configuration: |
| 16 | +- Provider names like `ollama_qwen3` are split to extract `ollama` as the type |
| 17 | +- The `provider` field in configuration explicitly specifies the type |
| 18 | +- New helper methods in `LLMProviderManager`: |
| 19 | + - `extract_provider_type()`: Extracts base provider type from name/config |
| 20 | + - `validate_provider_name()`: Validates provider names against configuration |
| 21 | + |
| 22 | +### 2. Provider Name Handling |
| 23 | + |
| 24 | +Updated all CLI commands to use provider names as strings instead of converting to enum: |
| 25 | +- `batch.py`: Validates provider names against config keys |
| 26 | +- `generate.py`: Uses provider names directly |
| 27 | +- `update.py`: Uses provider names directly |
| 28 | +- Better error messages showing available configured providers |
| 29 | + |
| 30 | +### 3. Model Updates |
| 31 | + |
| 32 | +Changed `GenerationRequest` and `BatchGenerationRequest` models: |
| 33 | +- `llm_provider` field changed from `LLMProvider` enum to `str` |
| 34 | +- Maintains backward compatibility with existing code |
| 35 | +- Generation engine already handled both string and enum values |
| 36 | + |
| 37 | +### 4. Validation Improvements |
| 38 | + |
| 39 | +Updated configuration validation: |
| 40 | +- Ollama and vLLM providers no longer require API keys |
| 41 | +- Validation checks provider existence in configuration |
| 42 | +- Clear error messages with list of available providers |
| 43 | + |
| 44 | +### 5. Documentation Updates |
| 45 | + |
| 46 | +Updated documentation to explain multi-provider support: |
| 47 | +- `README.md`: Added example with multiple Ollama instances |
| 48 | +- `saigen/docs/configuration-guide.md`: Added dedicated section on multi-provider instances |
| 49 | +- `saigen/docs/examples/saigen-config-sample.yaml`: Updated with multiple Ollama examples |
| 50 | +- CLI help text updated to reflect provider name usage |
| 51 | + |
| 52 | +## Configuration Example |
| 53 | + |
| 54 | +```yaml |
| 55 | +llm_providers: |
| 56 | + openai: |
| 57 | + provider: openai |
| 58 | + model: gpt-4o-mini |
| 59 | + enabled: true |
| 60 | + |
| 61 | + # Multiple Ollama instances with different models |
| 62 | + ollama_qwen3: |
| 63 | + provider: ollama |
| 64 | + api_base: http://localhost:11434 |
| 65 | + model: qwen3-coder:30b |
| 66 | + enabled: true |
| 67 | + |
| 68 | + ollama_deepseek: |
| 69 | + provider: ollama |
| 70 | + api_base: http://localhost:11434 |
| 71 | + model: deepseek-r1:8b |
| 72 | + enabled: true |
| 73 | + |
| 74 | + ollama_phi3: |
| 75 | + provider: ollama |
| 76 | + api_base: http://localhost:11434 |
| 77 | + model: phi3:latest |
| 78 | + enabled: true |
| 79 | +``` |
| 80 | +
|
| 81 | +## Usage |
| 82 | +
|
| 83 | +```bash |
| 84 | +# Use specific provider |
| 85 | +saigen generate nginx --llm-provider ollama_qwen3 |
| 86 | + |
| 87 | +# Use different provider |
| 88 | +saigen batch software-list.txt --llm-provider ollama_deepseek |
| 89 | + |
| 90 | +# Use default (first enabled provider) |
| 91 | +saigen generate nginx |
| 92 | +``` |
| 93 | + |
| 94 | +## Files Modified |
| 95 | + |
| 96 | +### Core Implementation |
| 97 | +- `saigen/llm/provider_manager.py`: Added provider type extraction logic |
| 98 | +- `saigen/models/generation.py`: Changed llm_provider field to string |
| 99 | +- `saigen/core/update_engine.py`: Updated method signature |
| 100 | + |
| 101 | +### CLI Commands |
| 102 | +- `saigen/cli/main.py`: Updated help text |
| 103 | +- `saigen/cli/commands/batch.py`: Provider name validation |
| 104 | +- `saigen/cli/commands/generate.py`: Provider name validation |
| 105 | +- `saigen/cli/commands/update.py`: Provider name validation |
| 106 | + |
| 107 | +### Configuration & Validation |
| 108 | +- `saigen/utils/config.py`: Skip API key validation for ollama/vllm |
| 109 | + |
| 110 | +### Documentation |
| 111 | +- `README.md`: Added multi-provider example |
| 112 | +- `saigen/docs/configuration-guide.md`: Added multi-provider section |
| 113 | +- `saigen/docs/examples/saigen-config-sample.yaml`: Updated examples |
| 114 | + |
| 115 | +## Testing |
| 116 | + |
| 117 | +All existing tests pass. The implementation: |
| 118 | +- Maintains backward compatibility with existing configurations |
| 119 | +- Handles both string and enum provider values in generation engine |
| 120 | +- Validates provider names against actual configuration |
| 121 | +- Provides clear error messages when invalid providers are specified |
| 122 | + |
| 123 | +## Benefits |
| 124 | + |
| 125 | +1. **Flexibility**: Users can configure multiple models of the same provider type |
| 126 | +2. **Model Comparison**: Easy to compare different models by switching providers |
| 127 | +3. **Resource Management**: Different models can use different endpoints/servers |
| 128 | +4. **Clear Naming**: Descriptive names like `ollama_qwen3` make it obvious which model is being used |
| 129 | +5. **Backward Compatible**: Existing single-provider configurations continue to work |
0 commit comments