pub struct ClaudeClient { /* private fields */ }
Implementations§
Source§impl ClaudeClient
impl ClaudeClient
Sourcepub fn new(config: ClaudeConfig) -> Self
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
impl Clone for ClaudeClient
Source§fn clone(&self) -> ClaudeClient
fn clone(&self) -> ClaudeClient
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for ClaudeClient
impl Debug for ClaudeClient
Source§impl Default for ClaudeClient
impl Default for ClaudeClient
Source§impl LowLevelClient for ClaudeClient
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,
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 ClaudeClient
impl !RefUnwindSafe for ClaudeClient
impl Send for ClaudeClient
impl Sync for ClaudeClient
impl Unpin for ClaudeClient
impl !UnwindSafe for ClaudeClient
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