Struct FlexibleClient

Source
pub struct FlexibleClient { /* private fields */ }
Expand description

Flexible client that wraps any LowLevelClient and provides factory functions

Implementations§

Source§

impl FlexibleClient

Source

pub fn new_lazy(client_type: ClientType) -> Self

Create a new FlexibleClient with lazy initialization

Source

pub fn new(client: Box<dyn LowLevelClient>) -> Self

Create a new FlexibleClient wrapping the given client

Source

pub fn with_interceptor(&self, interceptor: Arc<dyn Interceptor>) -> Self

Create a new FlexibleClient with an interceptor

Source

pub fn with_file_interceptor(&self, path: PathBuf) -> Self

Create a new FlexibleClient with an interceptor

Source

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}
Source

pub fn deepseek(config: DeepSeekConfig) -> Self

Create a FlexibleClient with a DeepSeek client

Source

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}
Source

pub fn new_mock_with_responses( responses: Vec<MockResponse>, ) -> (Self, Arc<MockHandle>)

Create a FlexibleClient mock with predefined responses

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FlexibleClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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,

The only method that implementations must provide
Source§

fn clone_box(&self) -> Box<dyn LowLevelClient>

Clone this client into a boxed trait object
Source§

fn ask_json<'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,

Simple JSON extraction from a prompt response (default implementation)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,