Source Code:
src/gaia/llm/__init__.py- Package exportssrc/gaia/llm/base_client.py- Abstract interfacesrc/gaia/llm/factory.py- Client factorysrc/gaia/llm/providers/- Provider implementations
Primary API:
create_client() factory function
Module: gaia.llm
Imports:from gaia.llm import create_client(preferred)from gaia.llm import LLMClient, NotSupportedError
Overview
The LLM client package provides a unified interface for generating text from multiple LLM backends using a provider pattern. Each provider implements the abstractLLMClient interface, with optional methods raising NotSupportedError when unavailable.
Key Features:
- Factory-based client creation with
create_client() - Three providers: Lemonade (local AMD-optimized), OpenAI, Claude
- Abstract base class for type safety and extensibility
- Graceful handling of unsupported features via
NotSupportedError - Streaming and non-streaming generation
- Backward-compatible
use_claude/use_openaiflags
Methods marked with ✗ raise
NotSupportedError when called on that provider.Requirements
Functional Requirements
-
Factory Pattern
create_client()factory function for client creation- Explicit provider selection via
providerparameter (“lemonade”, “openai”, “claude”) - Backward-compatible
use_claude/use_openaiflags - Auto-detection of provider from flags when
providernot specified - Default to Lemonade provider when no flags set
-
Abstract Interface
LLMClientABC defines unified interfaceprovider_nameproperty returns provider name- Required methods (all providers must implement):
generate()- Text completionchat()- Chat completion with message history
- Optional methods (raise
NotSupportedErrorif not implemented):embed()- Generate embeddingsvision()- Vision/image understandingget_performance_stats()- Performance statisticsload_model()- Load a modelunload_model()- Unload current model
-
Provider Implementations
- LemonadeProvider: Full support for all methods, connects to local Lemonade server
- OpenAIProvider:
generate,chat,embedonly - ClaudeProvider:
generate,chat,visiononly - All providers support streaming and non-streaming modes
-
Error Handling
NotSupportedErrorraised for unsupported methods- Clear error messages indicating provider and unsupported method
- Connection errors handled by underlying provider implementations
Non-Functional Requirements
-
Performance
- Lazy provider loading via
importlib(load only when needed) - Minimal overhead from abstraction layer
- Streaming support across all providers
- Default temperature of 0.1 for deterministic responses
- Lazy provider loading via
-
Reliability
- Type safety through ABC pattern
- Graceful handling of unsupported features
- Clear error messages for provider capabilities
- Provider-specific connection management
-
Usability
- Simple factory function interface
- Backward compatibility with existing code
- Consistent API across all providers
- Clear documentation with examples
API Specification
Package Structure
Package Exports (__init__.py)
VLMClient is also re-exported from gaia.llm — see
vlm-client for its API.
Factory Function (factory.py)
Abstract Base Class (base_client.py)
NotSupportedError (exceptions.py)
Provider Implementations
LemonadeProvider (providers/lemonade.py)
Full feature support - implements all methods.
OpenAIProvider (providers/openai_provider.py)
Partial support - generate, chat, embed only.
ClaudeProvider (providers/claude.py)
Partial support - generate, chat, vision only.
Implementation Details
Provider Selection Logic
The factory function auto-detects the provider based on parameters:Lazy Provider Loading
Providers are loaded dynamically usingimportlib to avoid importing unnecessary dependencies:
NotSupportedError Pattern
Optional methods raiseNotSupportedError by default in the ABC:
Temperature Defaults
All providers default totemperature=0.1 for deterministic responses:
Provider-Specific Implementation
LemonadeProvider wraps the low-levelLemonadeClient:
Testing Requirements
Unit Tests
File:tests/unit/test_llm_client_factory.py
Integration Tests
File:tests/integration/test_llm_providers.py
Dependencies
Required Packages
Import Dependencies
Factory (factory.py):
base_client.py):
providers/lemonade.py):
providers/openai_provider.py):
providers/claude.py):
Usage Examples
Example 1: Basic Usage with Factory
Example 2: Explicit Provider Selection
Example 3: Handling Unsupported Features
Example 4: Chat with Message History
Example 5: Streaming Responses
Example 6: Embeddings (Lemonade and OpenAI only)
Example 7: Vision (Lemonade and Claude only)
Example 8: Model Management (Lemonade only)
Example 9: Remote Lemonade Server
Example 10: System Prompts
Third-Party LLM Integration
GAIA supports third-party LLM service providers through its OpenAI-compatible API interface. Any service implementing the OpenAI API specification can be used with GAIA.
Required API Endpoints
Your LLM service must implement at least one of these OpenAI-compatible endpoints:Completions Endpoint
Default:
POST /v1/completionsUsed for pre-formatted promptsChat Completions Endpoint
POST /v1/chat/completionsUsed for structured conversations with message historyCompletions Endpoint
- Request
- Response
- Streaming
Chat Completions Endpoint
- Request
- Response
- Streaming
Configuration
- Environment Variable
- Direct Initialization
Linux
Windows (PowerShell)
Windows (CMD)
URL Normalization: LemonadeClient automatically appends
/api/v1 if not present:http://localhost:8080→http://localhost:8080/api/v1- If your service uses
/v1instead, provide the full path:http://localhost:8080/v1
Example Integration
Compatibility Checklist
Required Features
Required Features
- ✅ OpenAI-compatible endpoints (
/v1/completionsor/v1/chat/completions) - ✅ JSON request/response format matching OpenAI specification
- ✅ HTTP POST method for generation requests
- ✅ Non-streaming responses (complete response as JSON)
Optional Features
Optional Features
- ⚠️ Streaming responses (Server-Sent Events format)
- ⚠️ Error handling (proper HTTP status codes: 200, 400, 404, 500)
- ⚠️ Model listing (
GET /v1/modelsendpoint) - ⚠️ Token counting (usage statistics in responses)
GAIA-Specific Features
GAIA-Specific Features
The following features are specific to Lemonade provider and raise
NotSupportedError with third-party services:get_performance_stats()- Performance statisticsload_model()- Model loadingunload_model()- Model unloading
Troubleshooting
Connection Errors
Connection Errors
Problem:
ConnectionError: LLM Server Connection ErrorSolutions:- Verify service is running:
- Check firewall settings
- Ensure correct base URL format
- Test with explicit base URL:
404 Endpoint Errors
404 Endpoint Errors
Problem:
404 endpoint not foundSolutions:- Check if service uses
/v1/completions(OpenAI standard) - Verify API path structure:
/v1vs/api/v1 - Consult service documentation for correct endpoint paths
- Use chat method explicitly if needed:
Model Not Found
Model Not Found
Problem: Model errors or “model not loaded”Solutions:
- Specify model explicitly:
- List available models (if service supports):
- Ensure model is loaded in your service before connecting
Streaming Issues
Streaming Issues
Problem: Streaming responses not workingSolutions:
- Verify service supports Server-Sent Events (SSE)
- Check Content-Type headers:
text/event-stream - Test non-streaming first:
- Enable debug logging:
Documentation Updates Required
docs/sdk/sdks/llm.mdx
Add to LLM Section:LLMClient Technical Specification