pub struct UltrafastClientBuilder { /* private fields */ }Expand description
Builder for creating UltrafastClient instances with custom configuration.
The UltrafastClientBuilder provides a fluent API for configuring and creating
UltrafastClient instances. It supports both standalone and gateway modes.
§Examples
§Standalone Mode
use ultrafast_models_sdk::{UltrafastClient, RetryPolicy};
use std::time::Duration;
let retry_policy = RetryPolicy {
max_retries: 5,
initial_delay: Duration::from_millis(100),
max_delay: Duration::from_secs(10),
backoff_multiplier: 2.0,
jitter_factor: 0.1,
};
let client = UltrafastClientBuilder::default()
.with_retry_policy(retry_policy)
.standalone()
.with_openai("your-openai-key")
.with_anthropic("your-anthropic-key")
.build()?;§Gateway Mode
let client = UltrafastClientBuilder::default()
.gateway("http://localhost:3000".to_string())
.with_api_key("your-gateway-key")
.with_timeout(Duration::from_secs(60))
.build()?;§Builder Pattern
The builder follows the fluent builder pattern, allowing method chaining:
let client = UltrafastClientBuilder::default()
.with_retry_policy(custom_retry_policy)
.standalone()
.with_openai("key1")
.with_anthropic("key2")
.with_routing_strategy(RoutingStrategy::LoadBalance {
weights: vec![0.6, 0.4],
})
.with_cache_config(cache_config)
.build()?;§Configuration Options
§Retry Policy
Configure retry behavior for failed requests:
- Max Retries: Maximum number of retry attempts
- Initial Delay: Starting delay before first retry
- Max Delay: Maximum delay between retries
- Backoff Multiplier: Exponential backoff factor
- Jitter Factor: Randomization to prevent thundering herd
§Provider Configuration
Add and configure AI providers:
- OpenAI: GPT models with API key
- Anthropic: Claude models with API key
- Azure OpenAI: Azure-hosted OpenAI models
- Google Vertex AI: Google AI models
- Cohere: Command models
- Groq: Fast inference models
- Ollama: Local models
- Custom Providers: Extensible provider system
§Routing Strategy
Choose how requests are routed to providers:
- Single: Route all requests to one provider
- Load Balance: Distribute requests across providers
- Failover: Primary provider with automatic fallback
- Conditional: Route based on request characteristics
- A/B Testing: Route for testing different providers
§Caching
Configure response caching:
- Backend: In-memory or Redis cache
- TTL: Time-to-live for cached responses
- Max Size: Maximum number of cached items
- Key Strategy: Custom cache key generation
§Thread Safety
The builder is not thread-safe and should not be shared across threads. Build the client first, then share the client instance.
§Performance Considerations
- Connection Pooling: Configure appropriate pool sizes
- Timeout Settings: Set realistic timeouts for your use case
- Retry Policies: Balance retry attempts with user experience
- Cache Configuration: Enable caching for repeated requests
§Error Handling
The builder validates configuration and returns errors for:
- Invalid provider configurations
- Missing required fields
- Configuration conflicts
- Network connectivity issues
§See Also
UltrafastClient- The main client structStandaloneClientBuilder- For standalone mode configurationGatewayClientBuilder- For gateway mode configurationRetryPolicy- For retry configurationCacheConfig- For cache configuration
Implementations§
Source§impl UltrafastClientBuilder
impl UltrafastClientBuilder
pub fn with_retry_policy(self, retry_policy: RetryPolicy) -> Self
pub fn standalone(self) -> StandaloneClientBuilder
pub fn gateway(self, base_url: String) -> GatewayClientBuilder
Trait Implementations§
Source§impl Default for UltrafastClientBuilder
impl Default for UltrafastClientBuilder
Source§fn default() -> UltrafastClientBuilder
fn default() -> UltrafastClientBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for UltrafastClientBuilder
impl RefUnwindSafe for UltrafastClientBuilder
impl Send for UltrafastClientBuilder
impl Sync for UltrafastClientBuilder
impl Unpin for UltrafastClientBuilder
impl UnwindSafe for UltrafastClientBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more