pub struct FlexibleClient { /* private fields */ }
Expand description
Flexible client that wraps any LowLevelClient and provides factory functions
Implementations§
Source§impl FlexibleClient
impl FlexibleClient
Sourcepub fn new_lazy(client_type: ClientType) -> Self
pub fn new_lazy(client_type: ClientType) -> Self
Create a new FlexibleClient with lazy initialization
Sourcepub fn new(client: Box<dyn LowLevelClient>) -> Self
pub fn new(client: Box<dyn LowLevelClient>) -> Self
Create a new FlexibleClient wrapping the given client
Sourcepub fn with_interceptor(&self, interceptor: Arc<dyn Interceptor>) -> Self
pub fn with_interceptor(&self, interceptor: Arc<dyn Interceptor>) -> Self
Create a new FlexibleClient with an interceptor
Sourcepub fn with_file_interceptor(&self, path: PathBuf) -> Self
pub fn with_file_interceptor(&self, path: PathBuf) -> Self
Create a new FlexibleClient with an interceptor
Sourcepub fn claude(config: ClaudeConfig) -> Self
pub fn claude(config: ClaudeConfig) -> Self
Create a FlexibleClient with a Claude client
Examples found in repository?
examples/readme_demo.rs (line 34)
32async fn main() -> Result<(), Box<dyn std::error::Error>> {
33 // Create Claude client (reads ANTHROPIC_API_KEY from environment)
34 let client = FlexibleClient::claude(ClaudeConfig::default());
35 let resolver = QueryResolver::new(client, RetryConfig::default());
36
37 // Get 10 science quiz questions
38 let quiz: Quiz = resolver.query(
39 "Create 10 high school science quiz questions with A, B, C, D answers".to_string()
40 ).await?;
41
42 // Administer the quiz
43 administer_quiz(quiz.questions).await;
44 Ok(())
45}
Sourcepub fn deepseek(config: DeepSeekConfig) -> Self
pub fn deepseek(config: DeepSeekConfig) -> Self
Create a FlexibleClient with a DeepSeek client
Sourcepub fn mock() -> (Self, Arc<MockHandle>)
pub fn mock() -> (Self, Arc<MockHandle>)
Create a FlexibleClient with a mock and return the handle for configuration
Examples found in repository?
examples/flexible_client_demo.rs (line 20)
14async fn main() -> Result<(), Box<dyn std::error::Error>> {
15 println!("🧪 FlexibleClient Demo");
16 println!("=================");
17
18 // Create different client types easily
19 println!("\n1. Creating different client types:");
20 let (mock_client, _) = FlexibleClient::mock();
21
22 println!(" ✅ Mock client: {:?}", mock_client);
23 println!(" 📝 Claude/DeepSeek clients can be created with FlexibleClient::claude() / ::deepseek()");
24
25 // Clone clients easily
26 println!("\n2. Cloning clients:");
27 let cloned_mock = mock_client.clone();
28 println!(" ✅ Cloned mock client: {:?}", cloned_mock);
29
30 // Extract boxed clients for use with other systems
31 println!("\n3. Extract boxed clients:");
32 let _boxed_client = cloned_mock.clone_box();
33 println!(" ✅ Extracted boxed client from FlexibleClient");
34
35 // Use with QueryResolver
36 println!("\n4. Using with QueryResolver:");
37 let resolver = QueryResolver::new(mock_client, RetryConfig::default());
38
39 // Try a simple query (will return empty {} from mock)
40 match resolver.query::<SimpleResponse>("Hello world".to_string()).await {
41 Ok(response) => println!(" ✅ Query succeeded: {:?}", response),
42 Err(e) => println!(" ❌ Query failed (expected with mock): {}", e),
43 }
44
45 // Demonstrate factory functions
46 println!("\n5. Factory functions for dynamic client creation:");
47 let mock_client2 = FlexibleClient::mock();
48 println!(" ✅ Created mock client: {:?}", mock_client2);
49 println!(" 📝 Can also create claude/deepseek clients when API keys are available");
50
51 println!("\n🎉 FlexibleClient demo completed!");
52 println!(" - Easy construction with FlexibleClient::mock(), ::claude(), ::deepseek()");
53 println!(" - Seamless cloning with .clone()");
54 println!(" - Extract boxed clients with .clone_inner() or .into_inner()");
55 println!(" - Works directly with QueryResolver");
56
57 Ok(())
58}
Sourcepub fn new_mock_with_responses(
responses: Vec<MockResponse>,
) -> (Self, Arc<MockHandle>)
pub fn new_mock_with_responses( responses: Vec<MockResponse>, ) -> (Self, Arc<MockHandle>)
Create a FlexibleClient mock with predefined responses
Sourcepub fn into_inner(self) -> Result<Box<dyn LowLevelClient>, AIError>
pub fn into_inner(self) -> Result<Box<dyn LowLevelClient>, AIError>
Convert into the inner boxed client (initializes if needed)
Trait Implementations§
Source§impl Clone for FlexibleClient
impl Clone for FlexibleClient
Source§impl Debug for FlexibleClient
impl Debug for FlexibleClient
Source§impl LowLevelClient for FlexibleClient
impl LowLevelClient for FlexibleClient
Source§fn ask_raw<'life0, 'async_trait>(
&'life0 self,
prompt: String,
) -> Pin<Box<dyn Future<Output = Result<String, AIError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn ask_raw<'life0, 'async_trait>(
&'life0 self,
prompt: String,
) -> Pin<Box<dyn Future<Output = Result<String, AIError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
The only method that implementations must provide
Source§fn clone_box(&self) -> Box<dyn LowLevelClient>
fn clone_box(&self) -> Box<dyn LowLevelClient>
Clone this client into a boxed trait object
Auto Trait Implementations§
impl Freeze for FlexibleClient
impl !RefUnwindSafe for FlexibleClient
impl Send for FlexibleClient
impl Sync for FlexibleClient
impl Unpin for FlexibleClient
impl !UnwindSafe for FlexibleClient
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