1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
//! API handle for tuned model operations.
use crate::error::Error;
use super::super::Client;
/// API handle for tuned model operations.
///
/// Provides access to model tuning and fine-tuning capabilities including
/// creating, listing, and managing custom tuned models.
#[ derive( Debug ) ]
pub struct TunedModelsApi< 'a >
{
pub( crate ) client : &'a Client,
}
impl TunedModelsApi< '_ >
{
/// Create a new tuned model.
///
/// This method initiates the creation of a tuned model based on a base model
/// with custom training data and parameters.
///
/// # Arguments
///
/// * `request` - The create tuned model request containing model configuration and training data
///
/// # Returns
///
/// Returns a [`TunedModel`] with the created model information and training status.
///
/// # Errors
///
/// This method returns an error in the following cases:
/// - [`Error::NetworkError`] - Network connectivity issues or request timeout
/// - [`Error::AuthenticationError`] - Invalid or missing API key
/// - [`Error::ServerError`] - Gemini API server-side errors (5xx status codes)
/// - [`Error::DeserializationError`] - Failed to parse the API response
/// - [`Error::ApiError`] - Other API-related errors
///
/// # Examples
///
/// ```rust,no_run
/// # use api_gemini::client::Client;
/// # use api_gemini::models::*;
/// # #[ tokio::main ]
/// # async fn main() -> Result< (), Box< dyn std::error::Error > > {
/// let client = Client::new()?;
/// let tuned_models_api = client.tuned_models();
///
/// let tuned_model = TunedModel {
/// name : "projects/my-project/locations/us-central1/models/my-tuned-model".to_string(),
/// display_name : Some("My Custom Model".to_string()),
/// description : Some("A model tuned for specific tasks".to_string()),
/// base_model : "models/gemini-1.5-pro-002".to_string(),
/// state : None,
/// create_time : None,
/// update_time : None,
/// tuning_task : None,
/// tuned_model_source : None,
/// temperature : Some(0.7),
/// top_p : Some(0.9),
/// top_k : Some(40),
/// };
///
/// let request = CreateTunedModelRequest {
/// tuned_model,
/// tuned_model_id : Some("my-tuned-model".to_string()),
/// };
///
/// let response = tuned_models_api.create(&request).await?;
/// println!("Created tuned model : {}", response.name);
/// # Ok( () )
/// # }
/// ```
#[ inline ]
pub async fn create(
&self,
request : &crate::models::CreateTunedModelRequest
) -> Result< crate::models::TunedModel, Error >
{
let url = format!( "{}/v1beta/tunedModels", self.client.base_url );
crate ::internal::http::execute_legacy::< crate::models::CreateTunedModelRequest, crate::models::TunedModel >
(
&self.client.http,
reqwest ::Method::POST,
&url,
&self.client.api_key,
Some( request ),
)
.await
}
/// List all tuned models.
///
/// This method retrieves a list of tuned models accessible to the current user,
/// with optional pagination and filtering capabilities.
///
/// # Arguments
///
/// * `request` - The list tuned models request with pagination and filter options
///
/// # Returns
///
/// Returns a [`ListTunedModelsResponse`] containing:
/// - `tuned_models`: Vector of [`TunedModel`] objects
/// - `next_page_token`: Optional token for retrieving the next page of results
///
/// # Errors
///
/// This method returns an error in the following cases:
/// - [`Error::NetworkError`] - Network connectivity issues or request timeout
/// - [`Error::AuthenticationError`] - Invalid or missing API key
/// - [`Error::ServerError`] - Gemini API server-side errors (5xx status codes)
/// - [`Error::DeserializationError`] - Failed to parse the API response
/// - [`Error::ApiError`] - Other API-related errors
///
/// # Examples
///
/// ```rust,no_run
/// # use api_gemini::client::Client;
/// # use api_gemini::models::*;
/// # #[ tokio::main ]
/// # async fn main() -> Result< (), Box< dyn std::error::Error > > {
/// let client = Client::new()?;
/// let tuned_models_api = client.tuned_models();
///
/// let request = ListTunedModelsRequest {
/// page_size : Some(10),
/// page_token : None,
/// filter : None,
/// };
///
/// let response = tuned_models_api.list(&request).await?;
///
/// for model in response.tuned_models {
/// println!("Tuned model : {} - {}", model.name, model.display_name.unwrap_or_default());
/// }
/// # Ok( () )
/// # }
/// ```
#[ inline ]
pub async fn list(
&self,
request : &crate::models::ListTunedModelsRequest
) -> Result< crate::models::ListTunedModelsResponse, Error >
{
let mut url = format!( "{}/v1beta/tunedModels", self.client.base_url );
let mut params = Vec::new();
if let Some( page_size ) = request.page_size
{
params.push( format!( "pageSize={page_size}" ) );
}
if let Some( page_token ) = &request.page_token
{
params.push( format!( "pageToken={page_token}" ) );
}
if let Some( filter ) = &request.filter
{
params.push( format!( "filter={}", urlencoding::encode( filter ) ) );
}
if !params.is_empty()
{
url.push( '?' );
url.push_str( ¶ms.join( "&" ) );
}
crate ::internal::http::execute_legacy::< (), crate::models::ListTunedModelsResponse >
(
&self.client.http,
reqwest ::Method::GET,
&url,
&self.client.api_key,
None,
)
.await
}
/// Get information about a specific tuned model.
///
/// This method retrieves detailed information about a specific tuned model
/// including its configuration, training status, and performance metrics.
///
/// # Arguments
///
/// * `name` - The full name of the tuned model to retrieve
///
/// # Returns
///
/// Returns a [`TunedModel`] with complete model information.
///
/// # Errors
///
/// This method returns an error in the following cases:
/// - [`Error::NetworkError`] - Network connectivity issues or request timeout
/// - [`Error::AuthenticationError`] - Invalid or missing API key
/// - [`Error::ServerError`] - Gemini API server-side errors (5xx status codes)
/// - [`Error::DeserializationError`] - Failed to parse the API response
/// - [`Error::ApiError`] - Other API-related errors
///
/// # Examples
///
/// ```rust,no_run
/// # use api_gemini::client::Client;
/// # #[ tokio::main ]
/// # async fn main() -> Result< (), Box< dyn std::error::Error > > {
/// let client = Client::new()?;
/// let tuned_models_api = client.tuned_models();
///
/// let model = tuned_models_api.get("tunedModels/my-model-id").await?;
/// println!("Model : {} - Status : {}", model.name, model.state.unwrap_or_default());
/// # Ok( () )
/// # }
/// ```
#[ inline ]
pub async fn get( &self, name : &str ) -> Result< crate::models::TunedModel, Error >
{
let url = format!( "{}/v1beta/{}", self.client.base_url, name );
crate ::internal::http::execute_legacy::< (), crate::models::TunedModel >
(
&self.client.http,
reqwest ::Method::GET,
&url,
&self.client.api_key,
None,
)
.await
}
/// Delete a tuned model.
///
/// This method permanently deletes a tuned model and all associated data.
/// This action cannot be undone.
///
/// # Arguments
///
/// * `name` - The full name of the tuned model to delete
///
/// # Returns
///
/// Returns `Ok(())` if the deletion was successful.
///
/// # Errors
///
/// This method returns an error in the following cases:
/// - [`Error::NetworkError`] - Network connectivity issues or request timeout
/// - [`Error::AuthenticationError`] - Invalid or missing API key
/// - [`Error::ServerError`] - Gemini API server-side errors (5xx status codes)
/// - [`Error::ApiError`] - Other API-related errors
///
/// # Examples
///
/// ```rust,no_run
/// # use api_gemini::client::Client;
/// # #[ tokio::main ]
/// # async fn main() -> Result< (), Box< dyn std::error::Error > > {
/// let client = Client::new()?;
/// let tuned_models_api = client.tuned_models();
///
/// tuned_models_api.delete("tunedModels/my-model-id").await?;
/// println!("Tuned model deleted successfully");
/// # Ok( () )
/// # }
/// ```
#[ inline ]
pub async fn delete( &self, name : &str ) -> Result< (), Error >
{
let url = format!( "{}/v1beta/{}", self.client.base_url, name );
let response = crate::internal::http::execute_raw
(
&self.client.http,
reqwest ::Method::DELETE,
&url,
&self.client.api_key,
None::< &()>,
)
.await?;
if response.status().is_success()
{
Ok( () )
}
else
{
let error_text = response.text().await.unwrap_or_else( |_| "Failed to read error response".to_string() );
Err( Error::ApiError( format!( "Failed to delete tuned model : {error_text}" ) ) )
}
}
}