Vertex-CLI uses LangChain for unified LLM interactions with a clean, modular architecture following SOLID principles.
CLI Layer (prompt.py, llm.py)
|
v
Service Layer (LLMService, ConfigurationManager)
|
v
Provider Layer (ILLMProvider implementations)
|
v
LangChain Layer (ChatGoogleGenerativeAI, ChatOpenAI, ChatAnthropic)
ILLMProvider (vrtx/models/base.py)
- Abstract interface for all LLM providers
- Methods:
generate(),get_provider_name(),validate_config()
BaseLLMProvider (vrtx/models/base_provider.py)
- Base implementation with common functionality
- Implements DRY principle
- Provides: lazy initialization, validation, generation logic
All providers extend BaseLLMProvider and only implement:
_create_llm(): Provider-specific LLM instantiationget_provider_name(): Return provider name
Providers:
GeminiProvider: Google Gemini integrationOpenAIProvider: OpenAI GPT integrationAnthropicProvider: Anthropic Claude integration
LLMProviderFactory (vrtx/models/factory.py)
- Creates provider instances based on configuration
- Supports provider registration for extensibility
- Auto-detects provider from model name
ConfigurationManager (vrtx/config_manager.py)
- Manages model configurations
- Storage:
~/.config/ai_model_manager/models_config.json - Operations: CRUD for models, selection management
LLMService (vrtx/llm_service.py)
- Orchestrates LLM interactions
- Provider caching for performance
- Dependency injection pattern
Each class has one clear purpose:
ConfigurationManager: Configuration persistenceLLMService: LLM orchestration- Provider classes: Provider-specific logic
- Easy to add new providers without modifying existing code
- Factory pattern enables extension
- All providers implement
ILLMProvider - Providers are interchangeable
ILLMProviderdefines only essential operations- Clean, focused contracts
- High-level modules depend on abstractions
- Dependency injection throughout
{
"selected_model": "gpt-4",
"models": {
"gemini-flash-latest": {
"provider": "google",
"api_key": "your-api-key",
"temperature": 0.7,
"max_tokens": null
}
}
}- Create provider class extending
BaseLLMProvider - Implement
_create_llm()andget_provider_name() - Register in
LLMProviderFactory
Example:
from vrtx.models.base_provider import BaseLLMProvider
class YourProvider(BaseLLMProvider):
def _create_llm(self):
return ChatYourProvider(
model=self.config.name,
api_key=self.config.api_key,
temperature=self.config.temperature
)
def get_provider_name(self):
return "Your Provider"Comprehensive test suite: tests/test_vertex.py
Run tests:
python tests/test_vertex.py