Struct ClaudeClient

Source
pub struct ClaudeClient { /* private fields */ }

Implementations§

Source§

impl ClaudeClient

Source

pub fn new(config: ClaudeConfig) -> Self

Examples found in repository?
examples/claude_providers_demo.rs (line 19)
4async fn main() -> Result<(), Box<dyn std::error::Error>> {
5    tracing_subscriber::fmt::init();
6    
7    println!("=== Claude Multi-Provider Demo ===\n");
8    println!("This demo shows how to use the same model (e.g., Opus 4) across different providers\n");
9    
10    // Example 1: Same model across different providers
11    println!("🚀 Using Claude 4 Opus across different providers:");
12    
13    // Anthropic API
14    println!("1. Anthropic API:");
15    let anthropic_config = ClaudeConfig::anthropic(
16        "your-anthropic-api-key".to_string(),
17        ClaudeModel::Opus4
18    );
19    let _anthropic_client = ClaudeClient::new(anthropic_config.clone());
20    println!("   Model: {} ({})", ClaudeModel::Opus4.display_name(), anthropic_config.get_model_for_provider());
21    println!("   Provider: Anthropic\n");
22    
23    // AWS Bedrock - Same model, different provider
24    println!("2. AWS Bedrock:");
25    let bedrock_config = ClaudeConfig::bedrock(
26        "us-east-1".to_string(),
27        ClaudeModel::Opus4  // Same model!
28    );
29    let _bedrock_client = ClaudeClient::new(bedrock_config.clone());
30    println!("   Model: {} ({})", ClaudeModel::Opus4.display_name(), bedrock_config.get_model_for_provider());
31    println!("   Provider: AWS Bedrock\n");
32    
33    // GCP Vertex AI - Same model, different provider
34    println!("3. GCP Vertex AI:");
35    let vertex_config = ClaudeConfig::vertex(
36        "my-project".to_string(),
37        "us-central1".to_string(),
38        ClaudeModel::Opus4  // Same model!
39    );
40    let _vertex_client = ClaudeClient::new(vertex_config.clone());
41    println!("   Model: {} ({})", ClaudeModel::Opus4.display_name(), vertex_config.get_model_for_provider());
42    println!("   Provider: GCP Vertex AI\n");
43    
44    // Example 2: Easy provider switching
45    println!("🔄 Easy provider switching with builder pattern:");
46    let base_config = ClaudeConfig::new(Provider::Anthropic, ClaudeModel::Sonnet4);
47    
48    // Switch to Bedrock
49    let bedrock_config = base_config.clone()
50        .with_provider(Provider::AwsBedrock)
51        .with_model(ClaudeModel::Sonnet4);  // Same model
52    println!("   Switched to Bedrock: {}", bedrock_config.get_model_for_provider());
53    
54    // Switch to Vertex
55    let vertex_config = base_config.clone()
56        .with_provider(Provider::GcpVertex)
57        .with_model(ClaudeModel::Sonnet4);  // Same model
58    println!("   Switched to Vertex: {}", vertex_config.get_model_for_provider());
59    
60    // Example 3: All available models
61    println!("\n📋 All available models:");
62    let models = [
63        ClaudeModel::Opus4,
64        ClaudeModel::Sonnet4,
65        ClaudeModel::Sonnet37,
66        ClaudeModel::Haiku35,
67        ClaudeModel::Sonnet35V2,
68        ClaudeModel::Sonnet35,
69        ClaudeModel::Opus3,
70        ClaudeModel::Sonnet3,
71        ClaudeModel::Haiku3,
72    ];
73    
74    for model in &models {
75        println!("   {} - Anthropic: {}, Bedrock: {}, Vertex: {}", 
76            model.display_name(),
77            model.anthropic_model_id(),
78            model.bedrock_model_id(),
79            model.vertex_model_id()
80        );
81    }
82    
83    // Example 4: Default configuration
84    println!("\n🎯 Using default client:");
85    let _default_client = ClaudeClient::default();
86    println!("   Default model: {} via Anthropic", ClaudeModel::default().display_name());
87    
88    println!("\n✅ Demo completed successfully!");
89    println!("Key benefits:");
90    println!("  • Abstract by model name, not platform-specific IDs");
91    println!("  • Easy provider switching with same model");
92    println!("  • Automatic model ID translation per provider");
93    println!("  • Builder pattern for configuration flexibility");
94    
95    Ok(())
96}

Trait Implementations§

Source§

impl Clone for ClaudeClient

Source§

fn clone(&self) -> ClaudeClient

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 ClaudeClient

Source§

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

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

impl Default for ClaudeClient

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl LowLevelClient for ClaudeClient

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,