use mod_interface::mod_interface;
mod private
{
use crate::
{
enhanced_client ::EnhancedClient,
environment ::{ OpenaiEnvironment, EnvironmentInterface },
connection_manager ::ConnectionConfig,
metrics_framework ::MetricsConfig,
error ::Result,
};
#[ cfg( feature = "circuit_breaker" ) ]
use crate::enhanced_circuit_breaker::EnhancedCircuitBreakerConfig;
#[ cfg( feature = "caching" ) ]
use crate::response_cache::CacheConfig;
use core::time::Duration;
#[ derive( Debug, Clone ) ]
#[ allow( dead_code ) ]
pub struct EnhancedClientBuilder
{
connection : ConnectionConfig,
#[ cfg( feature = "caching" ) ]
cache : Option< CacheConfig >,
#[ cfg( not( feature = "caching" ) ) ]
cache : Option< () >,
#[ cfg( feature = "circuit_breaker" ) ]
circuit_breaker : Option< EnhancedCircuitBreakerConfig >,
#[ cfg( not( feature = "circuit_breaker" ) ) ]
circuit_breaker : Option< () >,
metrics : Option< MetricsConfig >,
}
impl EnhancedClientBuilder
{
#[ must_use ]
#[ inline ]
pub fn new() -> Self
{
Self
{
connection : ConnectionConfig::default(),
cache : None,
circuit_breaker : None,
metrics : None,
}
}
#[ must_use ]
#[ inline ]
pub fn max_connections_per_host( mut self, max : usize ) -> Self
{
self.connection.max_connections_per_host = max;
self
}
#[ must_use ]
#[ inline ]
pub fn min_connections_per_host( mut self, min : usize ) -> Self
{
self.connection.min_connections_per_host = min;
self
}
#[ must_use ]
#[ inline ]
pub fn idle_timeout( mut self, timeout : Duration ) -> Self
{
self.connection.idle_timeout = timeout;
self
}
#[ must_use ]
#[ inline ]
pub fn adaptive_pooling( mut self, enabled : bool ) -> Self
{
self.connection.adaptive_pooling = enabled;
self
}
#[ must_use ]
#[ inline ]
pub fn connection_warming( mut self, enabled : bool ) -> Self
{
self.connection.enable_connection_warming = enabled;
self
}
#[ must_use ]
#[ inline ]
pub fn health_check_interval( mut self, interval : Duration ) -> Self
{
self.connection.health_check_interval = interval;
self
}
#[ cfg( feature = "caching" ) ]
#[ must_use ]
#[ inline ]
pub fn with_cache( mut self, cache_config : CacheConfig ) -> Self
{
self.cache = Some( cache_config );
self
}
#[ cfg( feature = "caching" ) ]
#[ must_use ]
#[ inline ]
pub fn with_default_cache( mut self ) -> Self
{
self.cache = Some( CacheConfig::default() );
self
}
#[ cfg( feature = "circuit_breaker" ) ]
#[ must_use ]
#[ inline ]
pub fn with_circuit_breaker( mut self, circuit_breaker_config : EnhancedCircuitBreakerConfig ) -> Self
{
self.circuit_breaker = Some( circuit_breaker_config );
self
}
#[ cfg( feature = "circuit_breaker" ) ]
#[ must_use ]
#[ inline ]
pub fn with_default_circuit_breaker( mut self ) -> Self
{
self.circuit_breaker = Some( EnhancedCircuitBreakerConfig::default() );
self
}
#[ must_use ]
#[ inline ]
pub fn with_metrics( mut self, metrics_config : MetricsConfig ) -> Self
{
self.metrics = Some( metrics_config );
self
}
#[ must_use ]
#[ inline ]
pub fn with_default_metrics( mut self ) -> Self
{
self.metrics = Some( MetricsConfig::default() );
self
}
#[ inline ]
pub fn build< E >( self, environment : E ) -> Result< EnhancedClient< E > >
where
E : OpenaiEnvironment + EnvironmentInterface + Send + Sync + 'static,
{
#[ cfg( all( feature = "caching", feature = "circuit_breaker" ) ) ]
{
EnhancedClient::build_with_full_config(
environment,
self.connection,
self.cache,
self.circuit_breaker,
self.metrics
)
}
#[ cfg( not( all( feature = "caching", feature = "circuit_breaker" ) ) ) ]
{
EnhancedClient::build_with_config( environment, self.connection )
}
}
}
impl Default for EnhancedClientBuilder
{
#[ inline ]
fn default() -> Self
{
Self::new()
}
}
}
mod_interface!
{
exposed use
{
EnhancedClientBuilder,
};
}