pub struct FineTuningJobBuilder { /* private fields */ }Expand description
Builder for creating fine-tuning jobs.
Fine-tuning jobs train models on your specific data to improve performance for your particular use case.
ImplementationsΒ§
SourceΒ§impl FineTuningJobBuilder
impl FineTuningJobBuilder
Sourcepub fn new(model: impl Into<String>, training_file: impl Into<String>) -> Self
pub fn new(model: impl Into<String>, training_file: impl Into<String>) -> Self
Create a new fine-tuning job builder.
Β§Examples
use openai_ergonomic::builders::fine_tuning::FineTuningJobBuilder;
let builder = FineTuningJobBuilder::new("gpt-3.5-turbo", "file-training-data");Examples found in repository?
examples/fine_tuning.rs (line 120)
89async fn main() -> Result<(), Box<dyn std::error::Error>> {
90 println!("π OpenAI Ergonomic - Comprehensive Fine-tuning Example\n");
91
92 // Initialize client from environment variables
93 println!("π Initializing OpenAI client...");
94 let client = match Client::from_env() {
95 Ok(c) => {
96 println!("β
Client initialized successfully\n");
97 c.build()
98 }
99 Err(e) => {
100 eprintln!("β Failed to initialize client: {}", e);
101 eprintln!("π‘ Make sure OPENAI_API_KEY is set");
102 return Ok(());
103 }
104 };
105
106 // Example 1: Create a fine-tuning job
107 println!("ββββββββββββββββββββββββββββββββββββββββ");
108 println!("π Example 1: Create Fine-tuning Job");
109 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
110
111 // Note: You need to upload a training file first
112 // For demonstration purposes, we'll use a placeholder file ID
113 let training_file_id = "file-training-data";
114
115 println!("Creating fine-tuning job...");
116 println!(" Base Model: gpt-3.5-turbo");
117 println!(" Training File: {}", training_file_id);
118 println!(" Suffix: my-custom-model");
119
120 let builder = FineTuningJobBuilder::new("gpt-3.5-turbo", training_file_id)
121 .suffix("my-custom-model")
122 .epochs(3);
123
124 println!("\nπ‘ Note: This would create a real fine-tuning job with your API key.");
125 println!(" Commented out to avoid accidental charges.\n");
126
127 // Uncomment to actually create the job:
128 // match client.fine_tuning().create_job(builder).await {
129 // Ok(job) => {
130 // println!("β
Fine-tuning job created successfully!");
131 // println!(" Job ID: {}", job.id);
132 // println!(" Status: {}", job.status);
133 // println!(" Model: {}", job.model);
134 // }
135 // Err(e) => {
136 // eprintln!("β Failed to create fine-tuning job: {}", e);
137 // }
138 // }
139
140 // Simulate job creation for demonstration
141 let demo_job = JobInfo::new(
142 "ftjob-demo123",
143 "gpt-3.5-turbo",
144 "validating",
145 training_file_id,
146 );
147 println!("π Demo Job Created:");
148 demo_job.display();
149
150 // Example 2: List fine-tuning jobs
151 println!("\nββββββββββββββββββββββββββββββββββββββββ");
152 println!("π Example 2: List Fine-tuning Jobs");
153 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
154
155 println!("Listing fine-tuning jobs (limit: 5)...\n");
156
157 // Uncomment to actually list jobs:
158 // match client.fine_tuning().list_jobs(None, Some(5)).await {
159 // Ok(response) => {
160 // println!("β
Found {} fine-tuning jobs", response.data.len());
161 // for (i, job) in response.data.iter().enumerate() {
162 // println!("\nπ Job {}:", i + 1);
163 // println!(" ID: {}", job.id);
164 // println!(" Model: {}", job.model);
165 // println!(" Status: {}", job.status);
166 // println!(" Created At: {}", job.created_at);
167 // }
168 // }
169 // Err(e) => {
170 // eprintln!("β Failed to list fine-tuning jobs: {}", e);
171 // }
172 // }
173
174 println!("π‘ Demo: Would list your fine-tuning jobs here");
175
176 // Example 3: Get specific fine-tuning job
177 println!("\nββββββββββββββββββββββββββββββββββββββββ");
178 println!("π Example 3: Get Fine-tuning Job Details");
179 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
180
181 let job_id = "ftjob-demo123";
182 println!("Retrieving job: {}\n", job_id);
183
184 // Uncomment to actually get job:
185 // match client.fine_tuning().get_job(job_id).await {
186 // Ok(job) => {
187 // println!("β
Job retrieved successfully!");
188 // println!(" ID: {}", job.id);
189 // println!(" Model: {}", job.model);
190 // println!(" Status: {}", job.status);
191 // println!(" Created At: {}", job.created_at);
192 // if let Some(finished_at) = job.finished_at {
193 // println!(" Finished At: {}", finished_at);
194 // }
195 // }
196 // Err(e) => {
197 // eprintln!("β Failed to get fine-tuning job: {}", e);
198 // }
199 // }
200
201 println!("π‘ Demo: Would show detailed job information");
202
203 // Example 4: List job events
204 println!("\nββββββββββββββββββββββββββββββββββββββββ");
205 println!("π Example 4: List Fine-tuning Job Events");
206 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
207
208 println!("Listing events for job: {}\n", job_id);
209
210 // Uncomment to actually list events:
211 // match client.fine_tuning().list_events(job_id, None, Some(10)).await {
212 // Ok(response) => {
213 // println!("β
Found {} events", response.data.len());
214 // for (i, event) in response.data.iter().enumerate() {
215 // println!("\nπ Event {}:", i + 1);
216 // println!(" Message: {}", event.message);
217 // println!(" Created At: {}", event.created_at);
218 // if let Some(level) = &event.level {
219 // println!(" Level: {}", level);
220 // }
221 // }
222 // }
223 // Err(e) => {
224 // eprintln!("β Failed to list events: {}", e);
225 // }
226 // }
227
228 println!("π‘ Demo: Would show training events like:");
229 println!(" - Job started");
230 println!(" - Training step 1/100 complete");
231 println!(" - Validation loss: 0.452");
232 println!(" - Training complete");
233
234 // Example 5: List job checkpoints
235 println!("\nββββββββββββββββββββββββββββββββββββββββ");
236 println!("π Example 5: List Fine-tuning Job Checkpoints");
237 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
238
239 println!("Listing checkpoints for job: {}\n", job_id);
240
241 // Uncomment to actually list checkpoints:
242 // match client.fine_tuning().list_checkpoints(job_id, None, Some(5)).await {
243 // Ok(response) => {
244 // println!("β
Found {} checkpoints", response.data.len());
245 // for (i, checkpoint) in response.data.iter().enumerate() {
246 // println!("\nπΎ Checkpoint {}:", i + 1);
247 // println!(" ID: {}", checkpoint.id);
248 // println!(" Created At: {}", checkpoint.created_at);
249 // println!(" Step Number: {}", checkpoint.step_number);
250 // }
251 // }
252 // Err(e) => {
253 // eprintln!("β Failed to list checkpoints: {}", e);
254 // }
255 // }
256
257 println!("π‘ Demo: Would show model checkpoints from training");
258
259 // Example 6: Cancel fine-tuning job
260 println!("\nββββββββββββββββββββββββββββββββββββββββ");
261 println!("π Example 6: Cancel Fine-tuning Job");
262 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
263
264 println!("Cancelling job: {}\n", job_id);
265
266 // Uncomment to actually cancel job:
267 // match client.fine_tuning().cancel_job(job_id).await {
268 // Ok(job) => {
269 // println!("β
Job cancelled successfully!");
270 // println!(" Job ID: {}", job.id);
271 // println!(" Status: {}", job.status);
272 // }
273 // Err(e) => {
274 // eprintln!("β Failed to cancel job: {}", e);
275 // }
276 // }
277
278 println!("π‘ Demo: Would cancel the running fine-tuning job");
279
280 // Example 7: Create job with validation file
281 println!("\nββββββββββββββββββββββββββββββββββββββββ");
282 println!("π Example 7: Create Job with Validation File");
283 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
284
285 let validation_file_id = "file-validation-data";
286
287 println!("Creating fine-tuning job with validation...");
288 println!(" Base Model: gpt-3.5-turbo");
289 println!(" Training File: {}", training_file_id);
290 println!(" Validation File: {}", validation_file_id);
291 println!(" Epochs: 5");
292 println!(" Learning Rate Multiplier: 0.1");
293
294 let builder_with_validation = FineTuningJobBuilder::new("gpt-3.5-turbo", training_file_id)
295 .validation_file(validation_file_id)
296 .epochs(5)
297 .learning_rate_multiplier(0.1);
298
299 println!("\nπ‘ Note: Validation files help monitor overfitting during training");
300
301 // Example 8: Create job with Weights & Biases integration
302 println!("\nββββββββββββββββββββββββββββββββββββββββ");
303 println!("π Example 8: Create Job with W&B Integration");
304 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
305
306 println!("Creating fine-tuning job with W&B...");
307 println!(" Base Model: gpt-3.5-turbo");
308 println!(" Training File: {}", training_file_id);
309 println!(" W&B Project: my-finetuning-project");
310
311 let builder_with_wandb = FineTuningJobBuilder::new("gpt-3.5-turbo", training_file_id)
312 .with_wandb("my-finetuning-project");
313
314 println!("\nπ‘ Note: W&B integration provides detailed training metrics visualization");
315
316 // Summary
317 println!("\nββββββββββββββββββββββββββββββββββββββββ");
318 println!("π Summary");
319 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
320
321 println!("β
Fine-tuning API examples completed!");
322 println!("\nπ Key Takeaways:");
323 println!(" β’ Fine-tuning allows customizing models for specific tasks");
324 println!(" β’ Jobs can be created with various hyperparameters");
325 println!(" β’ Progress can be monitored through events and checkpoints");
326 println!(" β’ Validation files help prevent overfitting");
327 println!(" β’ Integrations like W&B provide detailed metrics");
328 println!(" β’ Jobs can be cancelled if needed");
329
330 println!("\nπ‘ Next Steps:");
331 println!(" 1. Prepare your training data in JSONL format");
332 println!(" 2. Upload training data using the Files API");
333 println!(" 3. Create a fine-tuning job with appropriate parameters");
334 println!(" 4. Monitor progress through events");
335 println!(" 5. Use the fine-tuned model in your applications");
336
337 println!("\nπ Example completed successfully!");
338
339 Ok(())
340}Sourcepub fn validation_file(self, file_id: impl Into<String>) -> Self
pub fn validation_file(self, file_id: impl Into<String>) -> Self
Set the validation file for the fine-tuning job.
Examples found in repository?
examples/fine_tuning.rs (line 295)
89async fn main() -> Result<(), Box<dyn std::error::Error>> {
90 println!("π OpenAI Ergonomic - Comprehensive Fine-tuning Example\n");
91
92 // Initialize client from environment variables
93 println!("π Initializing OpenAI client...");
94 let client = match Client::from_env() {
95 Ok(c) => {
96 println!("β
Client initialized successfully\n");
97 c.build()
98 }
99 Err(e) => {
100 eprintln!("β Failed to initialize client: {}", e);
101 eprintln!("π‘ Make sure OPENAI_API_KEY is set");
102 return Ok(());
103 }
104 };
105
106 // Example 1: Create a fine-tuning job
107 println!("ββββββββββββββββββββββββββββββββββββββββ");
108 println!("π Example 1: Create Fine-tuning Job");
109 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
110
111 // Note: You need to upload a training file first
112 // For demonstration purposes, we'll use a placeholder file ID
113 let training_file_id = "file-training-data";
114
115 println!("Creating fine-tuning job...");
116 println!(" Base Model: gpt-3.5-turbo");
117 println!(" Training File: {}", training_file_id);
118 println!(" Suffix: my-custom-model");
119
120 let builder = FineTuningJobBuilder::new("gpt-3.5-turbo", training_file_id)
121 .suffix("my-custom-model")
122 .epochs(3);
123
124 println!("\nπ‘ Note: This would create a real fine-tuning job with your API key.");
125 println!(" Commented out to avoid accidental charges.\n");
126
127 // Uncomment to actually create the job:
128 // match client.fine_tuning().create_job(builder).await {
129 // Ok(job) => {
130 // println!("β
Fine-tuning job created successfully!");
131 // println!(" Job ID: {}", job.id);
132 // println!(" Status: {}", job.status);
133 // println!(" Model: {}", job.model);
134 // }
135 // Err(e) => {
136 // eprintln!("β Failed to create fine-tuning job: {}", e);
137 // }
138 // }
139
140 // Simulate job creation for demonstration
141 let demo_job = JobInfo::new(
142 "ftjob-demo123",
143 "gpt-3.5-turbo",
144 "validating",
145 training_file_id,
146 );
147 println!("π Demo Job Created:");
148 demo_job.display();
149
150 // Example 2: List fine-tuning jobs
151 println!("\nββββββββββββββββββββββββββββββββββββββββ");
152 println!("π Example 2: List Fine-tuning Jobs");
153 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
154
155 println!("Listing fine-tuning jobs (limit: 5)...\n");
156
157 // Uncomment to actually list jobs:
158 // match client.fine_tuning().list_jobs(None, Some(5)).await {
159 // Ok(response) => {
160 // println!("β
Found {} fine-tuning jobs", response.data.len());
161 // for (i, job) in response.data.iter().enumerate() {
162 // println!("\nπ Job {}:", i + 1);
163 // println!(" ID: {}", job.id);
164 // println!(" Model: {}", job.model);
165 // println!(" Status: {}", job.status);
166 // println!(" Created At: {}", job.created_at);
167 // }
168 // }
169 // Err(e) => {
170 // eprintln!("β Failed to list fine-tuning jobs: {}", e);
171 // }
172 // }
173
174 println!("π‘ Demo: Would list your fine-tuning jobs here");
175
176 // Example 3: Get specific fine-tuning job
177 println!("\nββββββββββββββββββββββββββββββββββββββββ");
178 println!("π Example 3: Get Fine-tuning Job Details");
179 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
180
181 let job_id = "ftjob-demo123";
182 println!("Retrieving job: {}\n", job_id);
183
184 // Uncomment to actually get job:
185 // match client.fine_tuning().get_job(job_id).await {
186 // Ok(job) => {
187 // println!("β
Job retrieved successfully!");
188 // println!(" ID: {}", job.id);
189 // println!(" Model: {}", job.model);
190 // println!(" Status: {}", job.status);
191 // println!(" Created At: {}", job.created_at);
192 // if let Some(finished_at) = job.finished_at {
193 // println!(" Finished At: {}", finished_at);
194 // }
195 // }
196 // Err(e) => {
197 // eprintln!("β Failed to get fine-tuning job: {}", e);
198 // }
199 // }
200
201 println!("π‘ Demo: Would show detailed job information");
202
203 // Example 4: List job events
204 println!("\nββββββββββββββββββββββββββββββββββββββββ");
205 println!("π Example 4: List Fine-tuning Job Events");
206 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
207
208 println!("Listing events for job: {}\n", job_id);
209
210 // Uncomment to actually list events:
211 // match client.fine_tuning().list_events(job_id, None, Some(10)).await {
212 // Ok(response) => {
213 // println!("β
Found {} events", response.data.len());
214 // for (i, event) in response.data.iter().enumerate() {
215 // println!("\nπ Event {}:", i + 1);
216 // println!(" Message: {}", event.message);
217 // println!(" Created At: {}", event.created_at);
218 // if let Some(level) = &event.level {
219 // println!(" Level: {}", level);
220 // }
221 // }
222 // }
223 // Err(e) => {
224 // eprintln!("β Failed to list events: {}", e);
225 // }
226 // }
227
228 println!("π‘ Demo: Would show training events like:");
229 println!(" - Job started");
230 println!(" - Training step 1/100 complete");
231 println!(" - Validation loss: 0.452");
232 println!(" - Training complete");
233
234 // Example 5: List job checkpoints
235 println!("\nββββββββββββββββββββββββββββββββββββββββ");
236 println!("π Example 5: List Fine-tuning Job Checkpoints");
237 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
238
239 println!("Listing checkpoints for job: {}\n", job_id);
240
241 // Uncomment to actually list checkpoints:
242 // match client.fine_tuning().list_checkpoints(job_id, None, Some(5)).await {
243 // Ok(response) => {
244 // println!("β
Found {} checkpoints", response.data.len());
245 // for (i, checkpoint) in response.data.iter().enumerate() {
246 // println!("\nπΎ Checkpoint {}:", i + 1);
247 // println!(" ID: {}", checkpoint.id);
248 // println!(" Created At: {}", checkpoint.created_at);
249 // println!(" Step Number: {}", checkpoint.step_number);
250 // }
251 // }
252 // Err(e) => {
253 // eprintln!("β Failed to list checkpoints: {}", e);
254 // }
255 // }
256
257 println!("π‘ Demo: Would show model checkpoints from training");
258
259 // Example 6: Cancel fine-tuning job
260 println!("\nββββββββββββββββββββββββββββββββββββββββ");
261 println!("π Example 6: Cancel Fine-tuning Job");
262 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
263
264 println!("Cancelling job: {}\n", job_id);
265
266 // Uncomment to actually cancel job:
267 // match client.fine_tuning().cancel_job(job_id).await {
268 // Ok(job) => {
269 // println!("β
Job cancelled successfully!");
270 // println!(" Job ID: {}", job.id);
271 // println!(" Status: {}", job.status);
272 // }
273 // Err(e) => {
274 // eprintln!("β Failed to cancel job: {}", e);
275 // }
276 // }
277
278 println!("π‘ Demo: Would cancel the running fine-tuning job");
279
280 // Example 7: Create job with validation file
281 println!("\nββββββββββββββββββββββββββββββββββββββββ");
282 println!("π Example 7: Create Job with Validation File");
283 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
284
285 let validation_file_id = "file-validation-data";
286
287 println!("Creating fine-tuning job with validation...");
288 println!(" Base Model: gpt-3.5-turbo");
289 println!(" Training File: {}", training_file_id);
290 println!(" Validation File: {}", validation_file_id);
291 println!(" Epochs: 5");
292 println!(" Learning Rate Multiplier: 0.1");
293
294 let builder_with_validation = FineTuningJobBuilder::new("gpt-3.5-turbo", training_file_id)
295 .validation_file(validation_file_id)
296 .epochs(5)
297 .learning_rate_multiplier(0.1);
298
299 println!("\nπ‘ Note: Validation files help monitor overfitting during training");
300
301 // Example 8: Create job with Weights & Biases integration
302 println!("\nββββββββββββββββββββββββββββββββββββββββ");
303 println!("π Example 8: Create Job with W&B Integration");
304 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
305
306 println!("Creating fine-tuning job with W&B...");
307 println!(" Base Model: gpt-3.5-turbo");
308 println!(" Training File: {}", training_file_id);
309 println!(" W&B Project: my-finetuning-project");
310
311 let builder_with_wandb = FineTuningJobBuilder::new("gpt-3.5-turbo", training_file_id)
312 .with_wandb("my-finetuning-project");
313
314 println!("\nπ‘ Note: W&B integration provides detailed training metrics visualization");
315
316 // Summary
317 println!("\nββββββββββββββββββββββββββββββββββββββββ");
318 println!("π Summary");
319 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
320
321 println!("β
Fine-tuning API examples completed!");
322 println!("\nπ Key Takeaways:");
323 println!(" β’ Fine-tuning allows customizing models for specific tasks");
324 println!(" β’ Jobs can be created with various hyperparameters");
325 println!(" β’ Progress can be monitored through events and checkpoints");
326 println!(" β’ Validation files help prevent overfitting");
327 println!(" β’ Integrations like W&B provide detailed metrics");
328 println!(" β’ Jobs can be cancelled if needed");
329
330 println!("\nπ‘ Next Steps:");
331 println!(" 1. Prepare your training data in JSONL format");
332 println!(" 2. Upload training data using the Files API");
333 println!(" 3. Create a fine-tuning job with appropriate parameters");
334 println!(" 4. Monitor progress through events");
335 println!(" 5. Use the fine-tuned model in your applications");
336
337 println!("\nπ Example completed successfully!");
338
339 Ok(())
340}Sourcepub fn epochs(self, epochs: i32) -> Self
pub fn epochs(self, epochs: i32) -> Self
Set the number of epochs to train for.
Examples found in repository?
examples/fine_tuning.rs (line 122)
89async fn main() -> Result<(), Box<dyn std::error::Error>> {
90 println!("π OpenAI Ergonomic - Comprehensive Fine-tuning Example\n");
91
92 // Initialize client from environment variables
93 println!("π Initializing OpenAI client...");
94 let client = match Client::from_env() {
95 Ok(c) => {
96 println!("β
Client initialized successfully\n");
97 c.build()
98 }
99 Err(e) => {
100 eprintln!("β Failed to initialize client: {}", e);
101 eprintln!("π‘ Make sure OPENAI_API_KEY is set");
102 return Ok(());
103 }
104 };
105
106 // Example 1: Create a fine-tuning job
107 println!("ββββββββββββββββββββββββββββββββββββββββ");
108 println!("π Example 1: Create Fine-tuning Job");
109 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
110
111 // Note: You need to upload a training file first
112 // For demonstration purposes, we'll use a placeholder file ID
113 let training_file_id = "file-training-data";
114
115 println!("Creating fine-tuning job...");
116 println!(" Base Model: gpt-3.5-turbo");
117 println!(" Training File: {}", training_file_id);
118 println!(" Suffix: my-custom-model");
119
120 let builder = FineTuningJobBuilder::new("gpt-3.5-turbo", training_file_id)
121 .suffix("my-custom-model")
122 .epochs(3);
123
124 println!("\nπ‘ Note: This would create a real fine-tuning job with your API key.");
125 println!(" Commented out to avoid accidental charges.\n");
126
127 // Uncomment to actually create the job:
128 // match client.fine_tuning().create_job(builder).await {
129 // Ok(job) => {
130 // println!("β
Fine-tuning job created successfully!");
131 // println!(" Job ID: {}", job.id);
132 // println!(" Status: {}", job.status);
133 // println!(" Model: {}", job.model);
134 // }
135 // Err(e) => {
136 // eprintln!("β Failed to create fine-tuning job: {}", e);
137 // }
138 // }
139
140 // Simulate job creation for demonstration
141 let demo_job = JobInfo::new(
142 "ftjob-demo123",
143 "gpt-3.5-turbo",
144 "validating",
145 training_file_id,
146 );
147 println!("π Demo Job Created:");
148 demo_job.display();
149
150 // Example 2: List fine-tuning jobs
151 println!("\nββββββββββββββββββββββββββββββββββββββββ");
152 println!("π Example 2: List Fine-tuning Jobs");
153 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
154
155 println!("Listing fine-tuning jobs (limit: 5)...\n");
156
157 // Uncomment to actually list jobs:
158 // match client.fine_tuning().list_jobs(None, Some(5)).await {
159 // Ok(response) => {
160 // println!("β
Found {} fine-tuning jobs", response.data.len());
161 // for (i, job) in response.data.iter().enumerate() {
162 // println!("\nπ Job {}:", i + 1);
163 // println!(" ID: {}", job.id);
164 // println!(" Model: {}", job.model);
165 // println!(" Status: {}", job.status);
166 // println!(" Created At: {}", job.created_at);
167 // }
168 // }
169 // Err(e) => {
170 // eprintln!("β Failed to list fine-tuning jobs: {}", e);
171 // }
172 // }
173
174 println!("π‘ Demo: Would list your fine-tuning jobs here");
175
176 // Example 3: Get specific fine-tuning job
177 println!("\nββββββββββββββββββββββββββββββββββββββββ");
178 println!("π Example 3: Get Fine-tuning Job Details");
179 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
180
181 let job_id = "ftjob-demo123";
182 println!("Retrieving job: {}\n", job_id);
183
184 // Uncomment to actually get job:
185 // match client.fine_tuning().get_job(job_id).await {
186 // Ok(job) => {
187 // println!("β
Job retrieved successfully!");
188 // println!(" ID: {}", job.id);
189 // println!(" Model: {}", job.model);
190 // println!(" Status: {}", job.status);
191 // println!(" Created At: {}", job.created_at);
192 // if let Some(finished_at) = job.finished_at {
193 // println!(" Finished At: {}", finished_at);
194 // }
195 // }
196 // Err(e) => {
197 // eprintln!("β Failed to get fine-tuning job: {}", e);
198 // }
199 // }
200
201 println!("π‘ Demo: Would show detailed job information");
202
203 // Example 4: List job events
204 println!("\nββββββββββββββββββββββββββββββββββββββββ");
205 println!("π Example 4: List Fine-tuning Job Events");
206 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
207
208 println!("Listing events for job: {}\n", job_id);
209
210 // Uncomment to actually list events:
211 // match client.fine_tuning().list_events(job_id, None, Some(10)).await {
212 // Ok(response) => {
213 // println!("β
Found {} events", response.data.len());
214 // for (i, event) in response.data.iter().enumerate() {
215 // println!("\nπ Event {}:", i + 1);
216 // println!(" Message: {}", event.message);
217 // println!(" Created At: {}", event.created_at);
218 // if let Some(level) = &event.level {
219 // println!(" Level: {}", level);
220 // }
221 // }
222 // }
223 // Err(e) => {
224 // eprintln!("β Failed to list events: {}", e);
225 // }
226 // }
227
228 println!("π‘ Demo: Would show training events like:");
229 println!(" - Job started");
230 println!(" - Training step 1/100 complete");
231 println!(" - Validation loss: 0.452");
232 println!(" - Training complete");
233
234 // Example 5: List job checkpoints
235 println!("\nββββββββββββββββββββββββββββββββββββββββ");
236 println!("π Example 5: List Fine-tuning Job Checkpoints");
237 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
238
239 println!("Listing checkpoints for job: {}\n", job_id);
240
241 // Uncomment to actually list checkpoints:
242 // match client.fine_tuning().list_checkpoints(job_id, None, Some(5)).await {
243 // Ok(response) => {
244 // println!("β
Found {} checkpoints", response.data.len());
245 // for (i, checkpoint) in response.data.iter().enumerate() {
246 // println!("\nπΎ Checkpoint {}:", i + 1);
247 // println!(" ID: {}", checkpoint.id);
248 // println!(" Created At: {}", checkpoint.created_at);
249 // println!(" Step Number: {}", checkpoint.step_number);
250 // }
251 // }
252 // Err(e) => {
253 // eprintln!("β Failed to list checkpoints: {}", e);
254 // }
255 // }
256
257 println!("π‘ Demo: Would show model checkpoints from training");
258
259 // Example 6: Cancel fine-tuning job
260 println!("\nββββββββββββββββββββββββββββββββββββββββ");
261 println!("π Example 6: Cancel Fine-tuning Job");
262 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
263
264 println!("Cancelling job: {}\n", job_id);
265
266 // Uncomment to actually cancel job:
267 // match client.fine_tuning().cancel_job(job_id).await {
268 // Ok(job) => {
269 // println!("β
Job cancelled successfully!");
270 // println!(" Job ID: {}", job.id);
271 // println!(" Status: {}", job.status);
272 // }
273 // Err(e) => {
274 // eprintln!("β Failed to cancel job: {}", e);
275 // }
276 // }
277
278 println!("π‘ Demo: Would cancel the running fine-tuning job");
279
280 // Example 7: Create job with validation file
281 println!("\nββββββββββββββββββββββββββββββββββββββββ");
282 println!("π Example 7: Create Job with Validation File");
283 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
284
285 let validation_file_id = "file-validation-data";
286
287 println!("Creating fine-tuning job with validation...");
288 println!(" Base Model: gpt-3.5-turbo");
289 println!(" Training File: {}", training_file_id);
290 println!(" Validation File: {}", validation_file_id);
291 println!(" Epochs: 5");
292 println!(" Learning Rate Multiplier: 0.1");
293
294 let builder_with_validation = FineTuningJobBuilder::new("gpt-3.5-turbo", training_file_id)
295 .validation_file(validation_file_id)
296 .epochs(5)
297 .learning_rate_multiplier(0.1);
298
299 println!("\nπ‘ Note: Validation files help monitor overfitting during training");
300
301 // Example 8: Create job with Weights & Biases integration
302 println!("\nββββββββββββββββββββββββββββββββββββββββ");
303 println!("π Example 8: Create Job with W&B Integration");
304 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
305
306 println!("Creating fine-tuning job with W&B...");
307 println!(" Base Model: gpt-3.5-turbo");
308 println!(" Training File: {}", training_file_id);
309 println!(" W&B Project: my-finetuning-project");
310
311 let builder_with_wandb = FineTuningJobBuilder::new("gpt-3.5-turbo", training_file_id)
312 .with_wandb("my-finetuning-project");
313
314 println!("\nπ‘ Note: W&B integration provides detailed training metrics visualization");
315
316 // Summary
317 println!("\nββββββββββββββββββββββββββββββββββββββββ");
318 println!("π Summary");
319 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
320
321 println!("β
Fine-tuning API examples completed!");
322 println!("\nπ Key Takeaways:");
323 println!(" β’ Fine-tuning allows customizing models for specific tasks");
324 println!(" β’ Jobs can be created with various hyperparameters");
325 println!(" β’ Progress can be monitored through events and checkpoints");
326 println!(" β’ Validation files help prevent overfitting");
327 println!(" β’ Integrations like W&B provide detailed metrics");
328 println!(" β’ Jobs can be cancelled if needed");
329
330 println!("\nπ‘ Next Steps:");
331 println!(" 1. Prepare your training data in JSONL format");
332 println!(" 2. Upload training data using the Files API");
333 println!(" 3. Create a fine-tuning job with appropriate parameters");
334 println!(" 4. Monitor progress through events");
335 println!(" 5. Use the fine-tuned model in your applications");
336
337 println!("\nπ Example completed successfully!");
338
339 Ok(())
340}Sourcepub fn batch_size(self, batch_size: i32) -> Self
pub fn batch_size(self, batch_size: i32) -> Self
Set the batch size for training.
Sourcepub fn learning_rate_multiplier(self, multiplier: f64) -> Self
pub fn learning_rate_multiplier(self, multiplier: f64) -> Self
Set the learning rate multiplier.
Examples found in repository?
examples/fine_tuning.rs (line 297)
89async fn main() -> Result<(), Box<dyn std::error::Error>> {
90 println!("π OpenAI Ergonomic - Comprehensive Fine-tuning Example\n");
91
92 // Initialize client from environment variables
93 println!("π Initializing OpenAI client...");
94 let client = match Client::from_env() {
95 Ok(c) => {
96 println!("β
Client initialized successfully\n");
97 c.build()
98 }
99 Err(e) => {
100 eprintln!("β Failed to initialize client: {}", e);
101 eprintln!("π‘ Make sure OPENAI_API_KEY is set");
102 return Ok(());
103 }
104 };
105
106 // Example 1: Create a fine-tuning job
107 println!("ββββββββββββββββββββββββββββββββββββββββ");
108 println!("π Example 1: Create Fine-tuning Job");
109 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
110
111 // Note: You need to upload a training file first
112 // For demonstration purposes, we'll use a placeholder file ID
113 let training_file_id = "file-training-data";
114
115 println!("Creating fine-tuning job...");
116 println!(" Base Model: gpt-3.5-turbo");
117 println!(" Training File: {}", training_file_id);
118 println!(" Suffix: my-custom-model");
119
120 let builder = FineTuningJobBuilder::new("gpt-3.5-turbo", training_file_id)
121 .suffix("my-custom-model")
122 .epochs(3);
123
124 println!("\nπ‘ Note: This would create a real fine-tuning job with your API key.");
125 println!(" Commented out to avoid accidental charges.\n");
126
127 // Uncomment to actually create the job:
128 // match client.fine_tuning().create_job(builder).await {
129 // Ok(job) => {
130 // println!("β
Fine-tuning job created successfully!");
131 // println!(" Job ID: {}", job.id);
132 // println!(" Status: {}", job.status);
133 // println!(" Model: {}", job.model);
134 // }
135 // Err(e) => {
136 // eprintln!("β Failed to create fine-tuning job: {}", e);
137 // }
138 // }
139
140 // Simulate job creation for demonstration
141 let demo_job = JobInfo::new(
142 "ftjob-demo123",
143 "gpt-3.5-turbo",
144 "validating",
145 training_file_id,
146 );
147 println!("π Demo Job Created:");
148 demo_job.display();
149
150 // Example 2: List fine-tuning jobs
151 println!("\nββββββββββββββββββββββββββββββββββββββββ");
152 println!("π Example 2: List Fine-tuning Jobs");
153 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
154
155 println!("Listing fine-tuning jobs (limit: 5)...\n");
156
157 // Uncomment to actually list jobs:
158 // match client.fine_tuning().list_jobs(None, Some(5)).await {
159 // Ok(response) => {
160 // println!("β
Found {} fine-tuning jobs", response.data.len());
161 // for (i, job) in response.data.iter().enumerate() {
162 // println!("\nπ Job {}:", i + 1);
163 // println!(" ID: {}", job.id);
164 // println!(" Model: {}", job.model);
165 // println!(" Status: {}", job.status);
166 // println!(" Created At: {}", job.created_at);
167 // }
168 // }
169 // Err(e) => {
170 // eprintln!("β Failed to list fine-tuning jobs: {}", e);
171 // }
172 // }
173
174 println!("π‘ Demo: Would list your fine-tuning jobs here");
175
176 // Example 3: Get specific fine-tuning job
177 println!("\nββββββββββββββββββββββββββββββββββββββββ");
178 println!("π Example 3: Get Fine-tuning Job Details");
179 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
180
181 let job_id = "ftjob-demo123";
182 println!("Retrieving job: {}\n", job_id);
183
184 // Uncomment to actually get job:
185 // match client.fine_tuning().get_job(job_id).await {
186 // Ok(job) => {
187 // println!("β
Job retrieved successfully!");
188 // println!(" ID: {}", job.id);
189 // println!(" Model: {}", job.model);
190 // println!(" Status: {}", job.status);
191 // println!(" Created At: {}", job.created_at);
192 // if let Some(finished_at) = job.finished_at {
193 // println!(" Finished At: {}", finished_at);
194 // }
195 // }
196 // Err(e) => {
197 // eprintln!("β Failed to get fine-tuning job: {}", e);
198 // }
199 // }
200
201 println!("π‘ Demo: Would show detailed job information");
202
203 // Example 4: List job events
204 println!("\nββββββββββββββββββββββββββββββββββββββββ");
205 println!("π Example 4: List Fine-tuning Job Events");
206 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
207
208 println!("Listing events for job: {}\n", job_id);
209
210 // Uncomment to actually list events:
211 // match client.fine_tuning().list_events(job_id, None, Some(10)).await {
212 // Ok(response) => {
213 // println!("β
Found {} events", response.data.len());
214 // for (i, event) in response.data.iter().enumerate() {
215 // println!("\nπ Event {}:", i + 1);
216 // println!(" Message: {}", event.message);
217 // println!(" Created At: {}", event.created_at);
218 // if let Some(level) = &event.level {
219 // println!(" Level: {}", level);
220 // }
221 // }
222 // }
223 // Err(e) => {
224 // eprintln!("β Failed to list events: {}", e);
225 // }
226 // }
227
228 println!("π‘ Demo: Would show training events like:");
229 println!(" - Job started");
230 println!(" - Training step 1/100 complete");
231 println!(" - Validation loss: 0.452");
232 println!(" - Training complete");
233
234 // Example 5: List job checkpoints
235 println!("\nββββββββββββββββββββββββββββββββββββββββ");
236 println!("π Example 5: List Fine-tuning Job Checkpoints");
237 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
238
239 println!("Listing checkpoints for job: {}\n", job_id);
240
241 // Uncomment to actually list checkpoints:
242 // match client.fine_tuning().list_checkpoints(job_id, None, Some(5)).await {
243 // Ok(response) => {
244 // println!("β
Found {} checkpoints", response.data.len());
245 // for (i, checkpoint) in response.data.iter().enumerate() {
246 // println!("\nπΎ Checkpoint {}:", i + 1);
247 // println!(" ID: {}", checkpoint.id);
248 // println!(" Created At: {}", checkpoint.created_at);
249 // println!(" Step Number: {}", checkpoint.step_number);
250 // }
251 // }
252 // Err(e) => {
253 // eprintln!("β Failed to list checkpoints: {}", e);
254 // }
255 // }
256
257 println!("π‘ Demo: Would show model checkpoints from training");
258
259 // Example 6: Cancel fine-tuning job
260 println!("\nββββββββββββββββββββββββββββββββββββββββ");
261 println!("π Example 6: Cancel Fine-tuning Job");
262 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
263
264 println!("Cancelling job: {}\n", job_id);
265
266 // Uncomment to actually cancel job:
267 // match client.fine_tuning().cancel_job(job_id).await {
268 // Ok(job) => {
269 // println!("β
Job cancelled successfully!");
270 // println!(" Job ID: {}", job.id);
271 // println!(" Status: {}", job.status);
272 // }
273 // Err(e) => {
274 // eprintln!("β Failed to cancel job: {}", e);
275 // }
276 // }
277
278 println!("π‘ Demo: Would cancel the running fine-tuning job");
279
280 // Example 7: Create job with validation file
281 println!("\nββββββββββββββββββββββββββββββββββββββββ");
282 println!("π Example 7: Create Job with Validation File");
283 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
284
285 let validation_file_id = "file-validation-data";
286
287 println!("Creating fine-tuning job with validation...");
288 println!(" Base Model: gpt-3.5-turbo");
289 println!(" Training File: {}", training_file_id);
290 println!(" Validation File: {}", validation_file_id);
291 println!(" Epochs: 5");
292 println!(" Learning Rate Multiplier: 0.1");
293
294 let builder_with_validation = FineTuningJobBuilder::new("gpt-3.5-turbo", training_file_id)
295 .validation_file(validation_file_id)
296 .epochs(5)
297 .learning_rate_multiplier(0.1);
298
299 println!("\nπ‘ Note: Validation files help monitor overfitting during training");
300
301 // Example 8: Create job with Weights & Biases integration
302 println!("\nββββββββββββββββββββββββββββββββββββββββ");
303 println!("π Example 8: Create Job with W&B Integration");
304 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
305
306 println!("Creating fine-tuning job with W&B...");
307 println!(" Base Model: gpt-3.5-turbo");
308 println!(" Training File: {}", training_file_id);
309 println!(" W&B Project: my-finetuning-project");
310
311 let builder_with_wandb = FineTuningJobBuilder::new("gpt-3.5-turbo", training_file_id)
312 .with_wandb("my-finetuning-project");
313
314 println!("\nπ‘ Note: W&B integration provides detailed training metrics visualization");
315
316 // Summary
317 println!("\nββββββββββββββββββββββββββββββββββββββββ");
318 println!("π Summary");
319 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
320
321 println!("β
Fine-tuning API examples completed!");
322 println!("\nπ Key Takeaways:");
323 println!(" β’ Fine-tuning allows customizing models for specific tasks");
324 println!(" β’ Jobs can be created with various hyperparameters");
325 println!(" β’ Progress can be monitored through events and checkpoints");
326 println!(" β’ Validation files help prevent overfitting");
327 println!(" β’ Integrations like W&B provide detailed metrics");
328 println!(" β’ Jobs can be cancelled if needed");
329
330 println!("\nπ‘ Next Steps:");
331 println!(" 1. Prepare your training data in JSONL format");
332 println!(" 2. Upload training data using the Files API");
333 println!(" 3. Create a fine-tuning job with appropriate parameters");
334 println!(" 4. Monitor progress through events");
335 println!(" 5. Use the fine-tuned model in your applications");
336
337 println!("\nπ Example completed successfully!");
338
339 Ok(())
340}Sourcepub fn suffix(self, suffix: impl Into<String>) -> Self
pub fn suffix(self, suffix: impl Into<String>) -> Self
Set a suffix for the fine-tuned model name.
Examples found in repository?
examples/fine_tuning.rs (line 121)
89async fn main() -> Result<(), Box<dyn std::error::Error>> {
90 println!("π OpenAI Ergonomic - Comprehensive Fine-tuning Example\n");
91
92 // Initialize client from environment variables
93 println!("π Initializing OpenAI client...");
94 let client = match Client::from_env() {
95 Ok(c) => {
96 println!("β
Client initialized successfully\n");
97 c.build()
98 }
99 Err(e) => {
100 eprintln!("β Failed to initialize client: {}", e);
101 eprintln!("π‘ Make sure OPENAI_API_KEY is set");
102 return Ok(());
103 }
104 };
105
106 // Example 1: Create a fine-tuning job
107 println!("ββββββββββββββββββββββββββββββββββββββββ");
108 println!("π Example 1: Create Fine-tuning Job");
109 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
110
111 // Note: You need to upload a training file first
112 // For demonstration purposes, we'll use a placeholder file ID
113 let training_file_id = "file-training-data";
114
115 println!("Creating fine-tuning job...");
116 println!(" Base Model: gpt-3.5-turbo");
117 println!(" Training File: {}", training_file_id);
118 println!(" Suffix: my-custom-model");
119
120 let builder = FineTuningJobBuilder::new("gpt-3.5-turbo", training_file_id)
121 .suffix("my-custom-model")
122 .epochs(3);
123
124 println!("\nπ‘ Note: This would create a real fine-tuning job with your API key.");
125 println!(" Commented out to avoid accidental charges.\n");
126
127 // Uncomment to actually create the job:
128 // match client.fine_tuning().create_job(builder).await {
129 // Ok(job) => {
130 // println!("β
Fine-tuning job created successfully!");
131 // println!(" Job ID: {}", job.id);
132 // println!(" Status: {}", job.status);
133 // println!(" Model: {}", job.model);
134 // }
135 // Err(e) => {
136 // eprintln!("β Failed to create fine-tuning job: {}", e);
137 // }
138 // }
139
140 // Simulate job creation for demonstration
141 let demo_job = JobInfo::new(
142 "ftjob-demo123",
143 "gpt-3.5-turbo",
144 "validating",
145 training_file_id,
146 );
147 println!("π Demo Job Created:");
148 demo_job.display();
149
150 // Example 2: List fine-tuning jobs
151 println!("\nββββββββββββββββββββββββββββββββββββββββ");
152 println!("π Example 2: List Fine-tuning Jobs");
153 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
154
155 println!("Listing fine-tuning jobs (limit: 5)...\n");
156
157 // Uncomment to actually list jobs:
158 // match client.fine_tuning().list_jobs(None, Some(5)).await {
159 // Ok(response) => {
160 // println!("β
Found {} fine-tuning jobs", response.data.len());
161 // for (i, job) in response.data.iter().enumerate() {
162 // println!("\nπ Job {}:", i + 1);
163 // println!(" ID: {}", job.id);
164 // println!(" Model: {}", job.model);
165 // println!(" Status: {}", job.status);
166 // println!(" Created At: {}", job.created_at);
167 // }
168 // }
169 // Err(e) => {
170 // eprintln!("β Failed to list fine-tuning jobs: {}", e);
171 // }
172 // }
173
174 println!("π‘ Demo: Would list your fine-tuning jobs here");
175
176 // Example 3: Get specific fine-tuning job
177 println!("\nββββββββββββββββββββββββββββββββββββββββ");
178 println!("π Example 3: Get Fine-tuning Job Details");
179 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
180
181 let job_id = "ftjob-demo123";
182 println!("Retrieving job: {}\n", job_id);
183
184 // Uncomment to actually get job:
185 // match client.fine_tuning().get_job(job_id).await {
186 // Ok(job) => {
187 // println!("β
Job retrieved successfully!");
188 // println!(" ID: {}", job.id);
189 // println!(" Model: {}", job.model);
190 // println!(" Status: {}", job.status);
191 // println!(" Created At: {}", job.created_at);
192 // if let Some(finished_at) = job.finished_at {
193 // println!(" Finished At: {}", finished_at);
194 // }
195 // }
196 // Err(e) => {
197 // eprintln!("β Failed to get fine-tuning job: {}", e);
198 // }
199 // }
200
201 println!("π‘ Demo: Would show detailed job information");
202
203 // Example 4: List job events
204 println!("\nββββββββββββββββββββββββββββββββββββββββ");
205 println!("π Example 4: List Fine-tuning Job Events");
206 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
207
208 println!("Listing events for job: {}\n", job_id);
209
210 // Uncomment to actually list events:
211 // match client.fine_tuning().list_events(job_id, None, Some(10)).await {
212 // Ok(response) => {
213 // println!("β
Found {} events", response.data.len());
214 // for (i, event) in response.data.iter().enumerate() {
215 // println!("\nπ Event {}:", i + 1);
216 // println!(" Message: {}", event.message);
217 // println!(" Created At: {}", event.created_at);
218 // if let Some(level) = &event.level {
219 // println!(" Level: {}", level);
220 // }
221 // }
222 // }
223 // Err(e) => {
224 // eprintln!("β Failed to list events: {}", e);
225 // }
226 // }
227
228 println!("π‘ Demo: Would show training events like:");
229 println!(" - Job started");
230 println!(" - Training step 1/100 complete");
231 println!(" - Validation loss: 0.452");
232 println!(" - Training complete");
233
234 // Example 5: List job checkpoints
235 println!("\nββββββββββββββββββββββββββββββββββββββββ");
236 println!("π Example 5: List Fine-tuning Job Checkpoints");
237 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
238
239 println!("Listing checkpoints for job: {}\n", job_id);
240
241 // Uncomment to actually list checkpoints:
242 // match client.fine_tuning().list_checkpoints(job_id, None, Some(5)).await {
243 // Ok(response) => {
244 // println!("β
Found {} checkpoints", response.data.len());
245 // for (i, checkpoint) in response.data.iter().enumerate() {
246 // println!("\nπΎ Checkpoint {}:", i + 1);
247 // println!(" ID: {}", checkpoint.id);
248 // println!(" Created At: {}", checkpoint.created_at);
249 // println!(" Step Number: {}", checkpoint.step_number);
250 // }
251 // }
252 // Err(e) => {
253 // eprintln!("β Failed to list checkpoints: {}", e);
254 // }
255 // }
256
257 println!("π‘ Demo: Would show model checkpoints from training");
258
259 // Example 6: Cancel fine-tuning job
260 println!("\nββββββββββββββββββββββββββββββββββββββββ");
261 println!("π Example 6: Cancel Fine-tuning Job");
262 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
263
264 println!("Cancelling job: {}\n", job_id);
265
266 // Uncomment to actually cancel job:
267 // match client.fine_tuning().cancel_job(job_id).await {
268 // Ok(job) => {
269 // println!("β
Job cancelled successfully!");
270 // println!(" Job ID: {}", job.id);
271 // println!(" Status: {}", job.status);
272 // }
273 // Err(e) => {
274 // eprintln!("β Failed to cancel job: {}", e);
275 // }
276 // }
277
278 println!("π‘ Demo: Would cancel the running fine-tuning job");
279
280 // Example 7: Create job with validation file
281 println!("\nββββββββββββββββββββββββββββββββββββββββ");
282 println!("π Example 7: Create Job with Validation File");
283 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
284
285 let validation_file_id = "file-validation-data";
286
287 println!("Creating fine-tuning job with validation...");
288 println!(" Base Model: gpt-3.5-turbo");
289 println!(" Training File: {}", training_file_id);
290 println!(" Validation File: {}", validation_file_id);
291 println!(" Epochs: 5");
292 println!(" Learning Rate Multiplier: 0.1");
293
294 let builder_with_validation = FineTuningJobBuilder::new("gpt-3.5-turbo", training_file_id)
295 .validation_file(validation_file_id)
296 .epochs(5)
297 .learning_rate_multiplier(0.1);
298
299 println!("\nπ‘ Note: Validation files help monitor overfitting during training");
300
301 // Example 8: Create job with Weights & Biases integration
302 println!("\nββββββββββββββββββββββββββββββββββββββββ");
303 println!("π Example 8: Create Job with W&B Integration");
304 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
305
306 println!("Creating fine-tuning job with W&B...");
307 println!(" Base Model: gpt-3.5-turbo");
308 println!(" Training File: {}", training_file_id);
309 println!(" W&B Project: my-finetuning-project");
310
311 let builder_with_wandb = FineTuningJobBuilder::new("gpt-3.5-turbo", training_file_id)
312 .with_wandb("my-finetuning-project");
313
314 println!("\nπ‘ Note: W&B integration provides detailed training metrics visualization");
315
316 // Summary
317 println!("\nββββββββββββββββββββββββββββββββββββββββ");
318 println!("π Summary");
319 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
320
321 println!("β
Fine-tuning API examples completed!");
322 println!("\nπ Key Takeaways:");
323 println!(" β’ Fine-tuning allows customizing models for specific tasks");
324 println!(" β’ Jobs can be created with various hyperparameters");
325 println!(" β’ Progress can be monitored through events and checkpoints");
326 println!(" β’ Validation files help prevent overfitting");
327 println!(" β’ Integrations like W&B provide detailed metrics");
328 println!(" β’ Jobs can be cancelled if needed");
329
330 println!("\nπ‘ Next Steps:");
331 println!(" 1. Prepare your training data in JSONL format");
332 println!(" 2. Upload training data using the Files API");
333 println!(" 3. Create a fine-tuning job with appropriate parameters");
334 println!(" 4. Monitor progress through events");
335 println!(" 5. Use the fine-tuned model in your applications");
336
337 println!("\nπ Example completed successfully!");
338
339 Ok(())
340}Sourcepub fn with_wandb(self, project: impl Into<String>) -> Self
pub fn with_wandb(self, project: impl Into<String>) -> Self
Add a Weights & Biases integration.
Examples found in repository?
examples/fine_tuning.rs (line 312)
89async fn main() -> Result<(), Box<dyn std::error::Error>> {
90 println!("π OpenAI Ergonomic - Comprehensive Fine-tuning Example\n");
91
92 // Initialize client from environment variables
93 println!("π Initializing OpenAI client...");
94 let client = match Client::from_env() {
95 Ok(c) => {
96 println!("β
Client initialized successfully\n");
97 c.build()
98 }
99 Err(e) => {
100 eprintln!("β Failed to initialize client: {}", e);
101 eprintln!("π‘ Make sure OPENAI_API_KEY is set");
102 return Ok(());
103 }
104 };
105
106 // Example 1: Create a fine-tuning job
107 println!("ββββββββββββββββββββββββββββββββββββββββ");
108 println!("π Example 1: Create Fine-tuning Job");
109 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
110
111 // Note: You need to upload a training file first
112 // For demonstration purposes, we'll use a placeholder file ID
113 let training_file_id = "file-training-data";
114
115 println!("Creating fine-tuning job...");
116 println!(" Base Model: gpt-3.5-turbo");
117 println!(" Training File: {}", training_file_id);
118 println!(" Suffix: my-custom-model");
119
120 let builder = FineTuningJobBuilder::new("gpt-3.5-turbo", training_file_id)
121 .suffix("my-custom-model")
122 .epochs(3);
123
124 println!("\nπ‘ Note: This would create a real fine-tuning job with your API key.");
125 println!(" Commented out to avoid accidental charges.\n");
126
127 // Uncomment to actually create the job:
128 // match client.fine_tuning().create_job(builder).await {
129 // Ok(job) => {
130 // println!("β
Fine-tuning job created successfully!");
131 // println!(" Job ID: {}", job.id);
132 // println!(" Status: {}", job.status);
133 // println!(" Model: {}", job.model);
134 // }
135 // Err(e) => {
136 // eprintln!("β Failed to create fine-tuning job: {}", e);
137 // }
138 // }
139
140 // Simulate job creation for demonstration
141 let demo_job = JobInfo::new(
142 "ftjob-demo123",
143 "gpt-3.5-turbo",
144 "validating",
145 training_file_id,
146 );
147 println!("π Demo Job Created:");
148 demo_job.display();
149
150 // Example 2: List fine-tuning jobs
151 println!("\nββββββββββββββββββββββββββββββββββββββββ");
152 println!("π Example 2: List Fine-tuning Jobs");
153 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
154
155 println!("Listing fine-tuning jobs (limit: 5)...\n");
156
157 // Uncomment to actually list jobs:
158 // match client.fine_tuning().list_jobs(None, Some(5)).await {
159 // Ok(response) => {
160 // println!("β
Found {} fine-tuning jobs", response.data.len());
161 // for (i, job) in response.data.iter().enumerate() {
162 // println!("\nπ Job {}:", i + 1);
163 // println!(" ID: {}", job.id);
164 // println!(" Model: {}", job.model);
165 // println!(" Status: {}", job.status);
166 // println!(" Created At: {}", job.created_at);
167 // }
168 // }
169 // Err(e) => {
170 // eprintln!("β Failed to list fine-tuning jobs: {}", e);
171 // }
172 // }
173
174 println!("π‘ Demo: Would list your fine-tuning jobs here");
175
176 // Example 3: Get specific fine-tuning job
177 println!("\nββββββββββββββββββββββββββββββββββββββββ");
178 println!("π Example 3: Get Fine-tuning Job Details");
179 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
180
181 let job_id = "ftjob-demo123";
182 println!("Retrieving job: {}\n", job_id);
183
184 // Uncomment to actually get job:
185 // match client.fine_tuning().get_job(job_id).await {
186 // Ok(job) => {
187 // println!("β
Job retrieved successfully!");
188 // println!(" ID: {}", job.id);
189 // println!(" Model: {}", job.model);
190 // println!(" Status: {}", job.status);
191 // println!(" Created At: {}", job.created_at);
192 // if let Some(finished_at) = job.finished_at {
193 // println!(" Finished At: {}", finished_at);
194 // }
195 // }
196 // Err(e) => {
197 // eprintln!("β Failed to get fine-tuning job: {}", e);
198 // }
199 // }
200
201 println!("π‘ Demo: Would show detailed job information");
202
203 // Example 4: List job events
204 println!("\nββββββββββββββββββββββββββββββββββββββββ");
205 println!("π Example 4: List Fine-tuning Job Events");
206 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
207
208 println!("Listing events for job: {}\n", job_id);
209
210 // Uncomment to actually list events:
211 // match client.fine_tuning().list_events(job_id, None, Some(10)).await {
212 // Ok(response) => {
213 // println!("β
Found {} events", response.data.len());
214 // for (i, event) in response.data.iter().enumerate() {
215 // println!("\nπ Event {}:", i + 1);
216 // println!(" Message: {}", event.message);
217 // println!(" Created At: {}", event.created_at);
218 // if let Some(level) = &event.level {
219 // println!(" Level: {}", level);
220 // }
221 // }
222 // }
223 // Err(e) => {
224 // eprintln!("β Failed to list events: {}", e);
225 // }
226 // }
227
228 println!("π‘ Demo: Would show training events like:");
229 println!(" - Job started");
230 println!(" - Training step 1/100 complete");
231 println!(" - Validation loss: 0.452");
232 println!(" - Training complete");
233
234 // Example 5: List job checkpoints
235 println!("\nββββββββββββββββββββββββββββββββββββββββ");
236 println!("π Example 5: List Fine-tuning Job Checkpoints");
237 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
238
239 println!("Listing checkpoints for job: {}\n", job_id);
240
241 // Uncomment to actually list checkpoints:
242 // match client.fine_tuning().list_checkpoints(job_id, None, Some(5)).await {
243 // Ok(response) => {
244 // println!("β
Found {} checkpoints", response.data.len());
245 // for (i, checkpoint) in response.data.iter().enumerate() {
246 // println!("\nπΎ Checkpoint {}:", i + 1);
247 // println!(" ID: {}", checkpoint.id);
248 // println!(" Created At: {}", checkpoint.created_at);
249 // println!(" Step Number: {}", checkpoint.step_number);
250 // }
251 // }
252 // Err(e) => {
253 // eprintln!("β Failed to list checkpoints: {}", e);
254 // }
255 // }
256
257 println!("π‘ Demo: Would show model checkpoints from training");
258
259 // Example 6: Cancel fine-tuning job
260 println!("\nββββββββββββββββββββββββββββββββββββββββ");
261 println!("π Example 6: Cancel Fine-tuning Job");
262 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
263
264 println!("Cancelling job: {}\n", job_id);
265
266 // Uncomment to actually cancel job:
267 // match client.fine_tuning().cancel_job(job_id).await {
268 // Ok(job) => {
269 // println!("β
Job cancelled successfully!");
270 // println!(" Job ID: {}", job.id);
271 // println!(" Status: {}", job.status);
272 // }
273 // Err(e) => {
274 // eprintln!("β Failed to cancel job: {}", e);
275 // }
276 // }
277
278 println!("π‘ Demo: Would cancel the running fine-tuning job");
279
280 // Example 7: Create job with validation file
281 println!("\nββββββββββββββββββββββββββββββββββββββββ");
282 println!("π Example 7: Create Job with Validation File");
283 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
284
285 let validation_file_id = "file-validation-data";
286
287 println!("Creating fine-tuning job with validation...");
288 println!(" Base Model: gpt-3.5-turbo");
289 println!(" Training File: {}", training_file_id);
290 println!(" Validation File: {}", validation_file_id);
291 println!(" Epochs: 5");
292 println!(" Learning Rate Multiplier: 0.1");
293
294 let builder_with_validation = FineTuningJobBuilder::new("gpt-3.5-turbo", training_file_id)
295 .validation_file(validation_file_id)
296 .epochs(5)
297 .learning_rate_multiplier(0.1);
298
299 println!("\nπ‘ Note: Validation files help monitor overfitting during training");
300
301 // Example 8: Create job with Weights & Biases integration
302 println!("\nββββββββββββββββββββββββββββββββββββββββ");
303 println!("π Example 8: Create Job with W&B Integration");
304 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
305
306 println!("Creating fine-tuning job with W&B...");
307 println!(" Base Model: gpt-3.5-turbo");
308 println!(" Training File: {}", training_file_id);
309 println!(" W&B Project: my-finetuning-project");
310
311 let builder_with_wandb = FineTuningJobBuilder::new("gpt-3.5-turbo", training_file_id)
312 .with_wandb("my-finetuning-project");
313
314 println!("\nπ‘ Note: W&B integration provides detailed training metrics visualization");
315
316 // Summary
317 println!("\nββββββββββββββββββββββββββββββββββββββββ");
318 println!("π Summary");
319 println!("ββββββββββββββββββββββββββββββββββββββββ\n");
320
321 println!("β
Fine-tuning API examples completed!");
322 println!("\nπ Key Takeaways:");
323 println!(" β’ Fine-tuning allows customizing models for specific tasks");
324 println!(" β’ Jobs can be created with various hyperparameters");
325 println!(" β’ Progress can be monitored through events and checkpoints");
326 println!(" β’ Validation files help prevent overfitting");
327 println!(" β’ Integrations like W&B provide detailed metrics");
328 println!(" β’ Jobs can be cancelled if needed");
329
330 println!("\nπ‘ Next Steps:");
331 println!(" 1. Prepare your training data in JSONL format");
332 println!(" 2. Upload training data using the Files API");
333 println!(" 3. Create a fine-tuning job with appropriate parameters");
334 println!(" 4. Monitor progress through events");
335 println!(" 5. Use the fine-tuned model in your applications");
336
337 println!("\nπ Example completed successfully!");
338
339 Ok(())
340}Sourcepub fn training_file(&self) -> &str
pub fn training_file(&self) -> &str
Get the training file ID.
Sourcepub fn validation_file_ref(&self) -> Option<&str>
pub fn validation_file_ref(&self) -> Option<&str>
Get the validation file ID.
Sourcepub fn hyperparameters(&self) -> &FineTuningHyperparameters
pub fn hyperparameters(&self) -> &FineTuningHyperparameters
Get the hyperparameters.
Sourcepub fn suffix_ref(&self) -> Option<&str>
pub fn suffix_ref(&self) -> Option<&str>
Get the model suffix.
Sourcepub fn integrations(&self) -> &[FineTuningIntegration]
pub fn integrations(&self) -> &[FineTuningIntegration]
Get the integrations.
Trait ImplementationsΒ§
SourceΒ§impl Clone for FineTuningJobBuilder
impl Clone for FineTuningJobBuilder
SourceΒ§fn clone(&self) -> FineTuningJobBuilder
fn clone(&self) -> FineTuningJobBuilder
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 moreAuto Trait ImplementationsΒ§
impl Freeze for FineTuningJobBuilder
impl RefUnwindSafe for FineTuningJobBuilder
impl Send for FineTuningJobBuilder
impl Sync for FineTuningJobBuilder
impl Unpin for FineTuningJobBuilder
impl UnwindSafe for FineTuningJobBuilder
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