pub struct ModelBuilder { /* private fields */ }Expand description
Builder for ModelRequest.
Implementations§
Source§impl ModelBuilder
impl ModelBuilder
Sourcepub fn credentials<VALUE: Into<Credentials>>(self, value: VALUE) -> Self
pub fn credentials<VALUE: Into<Credentials>>(self, value: VALUE) -> Self
Credentials for authentication (not serialized)
Examples found in repository?
examples/models.rs (line 26)
4async fn main() -> Result<(), Box<dyn std::error::Error>> {
5 // Load credentials from environment variables
6 let credentials = Credentials::from_env();
7
8 // List all available models
9 println!("Listing all available models:");
10 let models = ModelList::builder()
11 .credentials(credentials.clone())
12 // Add the limit to the request if desired
13 // .limit(5u32)
14 .create()
15 .await?;
16
17 println!("Available models:");
18 for model in &models.data {
19 println!("- {} ({})", model.display_name, model.id);
20 }
21
22 // Get details for a specific model
23 if let Some(first_model) = models.data.first() {
24 println!("\nGetting details for model: {}", first_model.id);
25 let model_details = Model::builder(&first_model.id)
26 .credentials(credentials)
27 .create()
28 .await?;
29
30 println!("Model details:");
31 println!(" ID: {}", model_details.id);
32 println!(" Name: {}", model_details.display_name);
33 println!(" Created at: {}", model_details.created_at);
34 println!(" Type: {}", model_details.model_type);
35 }
36
37 Ok(())
38}Sourcepub fn build(self) -> Result<ModelRequest, ModelBuilderError>
pub fn build(self) -> Result<ModelRequest, ModelBuilderError>
Source§impl ModelBuilder
impl ModelBuilder
Sourcepub async fn create(self) -> ApiResponseOrError<Model>
pub async fn create(self) -> ApiResponseOrError<Model>
Creates a new model request and returns the response.
This is a convenience method that builds the request from the builder and sends it to the Models API.
§Example
let credentials = Credentials::from_env();
let model = Model::builder("claude-3-7-sonnet-20250219")
.credentials(credentials)
.create()
.await?;Examples found in repository?
examples/models.rs (line 27)
4async fn main() -> Result<(), Box<dyn std::error::Error>> {
5 // Load credentials from environment variables
6 let credentials = Credentials::from_env();
7
8 // List all available models
9 println!("Listing all available models:");
10 let models = ModelList::builder()
11 .credentials(credentials.clone())
12 // Add the limit to the request if desired
13 // .limit(5u32)
14 .create()
15 .await?;
16
17 println!("Available models:");
18 for model in &models.data {
19 println!("- {} ({})", model.display_name, model.id);
20 }
21
22 // Get details for a specific model
23 if let Some(first_model) = models.data.first() {
24 println!("\nGetting details for model: {}", first_model.id);
25 let model_details = Model::builder(&first_model.id)
26 .credentials(credentials)
27 .create()
28 .await?;
29
30 println!("Model details:");
31 println!(" ID: {}", model_details.id);
32 println!(" Name: {}", model_details.display_name);
33 println!(" Created at: {}", model_details.created_at);
34 println!(" Type: {}", model_details.model_type);
35 }
36
37 Ok(())
38}Trait Implementations§
Source§impl Clone for ModelBuilder
impl Clone for ModelBuilder
Source§fn clone(&self) -> ModelBuilder
fn clone(&self) -> ModelBuilder
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 ModelBuilder
impl Debug for ModelBuilder
Source§impl Default for ModelBuilder
impl Default for ModelBuilder
Source§impl PartialEq for ModelBuilder
impl PartialEq for ModelBuilder
impl StructuralPartialEq for ModelBuilder
Auto Trait Implementations§
impl Freeze for ModelBuilder
impl RefUnwindSafe for ModelBuilder
impl Send for ModelBuilder
impl Sync for ModelBuilder
impl Unpin for ModelBuilder
impl UnwindSafe for ModelBuilder
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