openai_tools/fine_tuning/response.rs
1//! OpenAI Fine-tuning API Response Types
2//!
3//! This module defines the response types for the OpenAI Fine-tuning API.
4
5use serde::{Deserialize, Serialize};
6
7/// The status of a fine-tuning job.
8#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
9#[serde(rename_all = "snake_case")]
10#[non_exhaustive]
11pub enum FineTuningJobStatus {
12 /// Files are being validated.
13 ValidatingFiles,
14 /// Job is queued for processing.
15 Queued,
16 /// Job is currently running.
17 Running,
18 /// Job completed successfully.
19 Succeeded,
20 /// Job failed.
21 Failed,
22 /// Job was cancelled.
23 Cancelled,
24 /// A status this version of the library does not know about.
25 ///
26 /// OpenAI can add lifecycle states at any time; capturing the raw value
27 /// keeps the surrounding response parseable.
28 #[serde(untagged)]
29 Other(String),
30}
31
32/// Hyperparameters used for fine-tuning.
33#[derive(Debug, Clone, Serialize, Deserialize, Default)]
34pub struct Hyperparameters {
35 /// Number of epochs to train for.
36 /// Can be "auto" in API but represented as Option here.
37 #[serde(skip_serializing_if = "Option::is_none")]
38 pub n_epochs: Option<u32>,
39
40 /// Batch size for training.
41 /// Can be "auto" in API but represented as Option here.
42 #[serde(skip_serializing_if = "Option::is_none")]
43 pub batch_size: Option<u32>,
44
45 /// Learning rate multiplier.
46 /// Can be "auto" in API but represented as Option here.
47 #[serde(skip_serializing_if = "Option::is_none")]
48 pub learning_rate_multiplier: Option<f64>,
49}
50
51/// Error information for a failed fine-tuning job.
52#[derive(Debug, Clone, Serialize, Deserialize)]
53pub struct FineTuningError {
54 /// A machine-readable error code.
55 pub code: String,
56 /// A human-readable error message.
57 pub message: String,
58 /// The parameter related to the error, if any.
59 pub param: Option<String>,
60}
61
62/// Integration configuration (e.g., Weights & Biases).
63#[derive(Debug, Clone, Serialize, Deserialize)]
64pub struct Integration {
65 /// The type of integration (e.g., "wandb").
66 #[serde(rename = "type")]
67 pub integration_type: String,
68
69 /// Integration-specific settings.
70 #[serde(flatten)]
71 pub settings: serde_json::Value,
72}
73
74/// Method configuration for fine-tuning.
75#[derive(Debug, Clone, Serialize, Deserialize)]
76pub struct MethodConfig {
77 /// The type of fine-tuning method (e.g., "supervised", "dpo").
78 #[serde(rename = "type")]
79 pub method_type: String,
80
81 /// Supervised fine-tuning configuration.
82 #[serde(skip_serializing_if = "Option::is_none")]
83 pub supervised: Option<SupervisedConfig>,
84
85 /// DPO fine-tuning configuration.
86 #[serde(skip_serializing_if = "Option::is_none")]
87 pub dpo: Option<DpoConfig>,
88}
89
90/// Configuration for supervised fine-tuning.
91#[derive(Debug, Clone, Serialize, Deserialize)]
92pub struct SupervisedConfig {
93 /// Hyperparameters for supervised fine-tuning.
94 #[serde(skip_serializing_if = "Option::is_none")]
95 pub hyperparameters: Option<Hyperparameters>,
96}
97
98/// Configuration for DPO (Direct Preference Optimization) fine-tuning.
99#[derive(Debug, Clone, Serialize, Deserialize)]
100pub struct DpoConfig {
101 /// Hyperparameters for DPO fine-tuning.
102 #[serde(skip_serializing_if = "Option::is_none")]
103 pub hyperparameters: Option<Hyperparameters>,
104}
105
106/// A fine-tuning job object.
107#[derive(Debug, Clone, Serialize, Deserialize)]
108pub struct FineTuningJob {
109 /// The unique identifier for the job.
110 pub id: String,
111
112 /// The object type (always "fine_tuning.job").
113 pub object: String,
114
115 /// The base model being fine-tuned.
116 pub model: String,
117
118 /// The Unix timestamp when the job was created.
119 pub created_at: i64,
120
121 /// The Unix timestamp when the job finished.
122 pub finished_at: Option<i64>,
123
124 /// The name of the fine-tuned model (available after success).
125 pub fine_tuned_model: Option<String>,
126
127 /// The organization ID that owns the job.
128 pub organization_id: String,
129
130 /// Array of result file IDs.
131 pub result_files: Vec<String>,
132
133 /// The current status of the job.
134 pub status: FineTuningJobStatus,
135
136 /// The validation file ID, if provided.
137 pub validation_file: Option<String>,
138
139 /// The training file ID.
140 pub training_file: String,
141
142 /// The hyperparameters used for training.
143 pub hyperparameters: Hyperparameters,
144
145 /// The number of tokens trained on (null while running).
146 pub trained_tokens: Option<u64>,
147
148 /// Error information if the job failed.
149 pub error: Option<FineTuningError>,
150
151 /// The seed used for training.
152 pub seed: u64,
153
154 /// Estimated finish time (Unix timestamp).
155 pub estimated_finish: Option<i64>,
156
157 /// Configured integrations.
158 pub integrations: Option<Vec<Integration>>,
159
160 /// The fine-tuning method used.
161 pub method: Option<MethodConfig>,
162
163 /// User-provided suffix for the model name.
164 pub user_provided_suffix: Option<String>,
165}
166
167/// Response for listing fine-tuning jobs.
168#[derive(Debug, Clone, Serialize, Deserialize)]
169pub struct FineTuningJobListResponse {
170 /// The object type (always "list").
171 pub object: String,
172
173 /// The list of fine-tuning jobs.
174 pub data: Vec<FineTuningJob>,
175
176 /// Whether there are more jobs to retrieve.
177 pub has_more: bool,
178}
179
180/// A fine-tuning event object.
181#[derive(Debug, Clone, Serialize, Deserialize)]
182pub struct FineTuningEvent {
183 /// The unique identifier for the event.
184 pub id: String,
185
186 /// The object type (always "fine_tuning.job.event").
187 pub object: String,
188
189 /// The Unix timestamp when the event was created.
190 pub created_at: i64,
191
192 /// The level of the event ("info", "warn", "error").
193 pub level: String,
194
195 /// The event message.
196 pub message: String,
197
198 /// Additional data associated with the event.
199 pub data: Option<serde_json::Value>,
200
201 /// The type of event.
202 #[serde(rename = "type")]
203 pub event_type: String,
204}
205
206/// Response for listing fine-tuning events.
207#[derive(Debug, Clone, Serialize, Deserialize)]
208pub struct FineTuningEventListResponse {
209 /// The object type (always "list").
210 pub object: String,
211
212 /// The list of events.
213 pub data: Vec<FineTuningEvent>,
214
215 /// Whether there are more events to retrieve.
216 pub has_more: bool,
217}
218
219/// Metrics for a fine-tuning checkpoint.
220#[derive(Debug, Clone, Serialize, Deserialize)]
221pub struct CheckpointMetrics {
222 /// The training step number.
223 pub step: u32,
224
225 /// The training loss at this checkpoint.
226 pub train_loss: f64,
227
228 /// The mean token accuracy during training.
229 pub train_mean_token_accuracy: f64,
230
231 /// The validation loss at this checkpoint.
232 pub valid_loss: Option<f64>,
233
234 /// The mean token accuracy during validation.
235 pub valid_mean_token_accuracy: Option<f64>,
236
237 /// The full validation loss.
238 pub full_valid_loss: Option<f64>,
239
240 /// The full validation mean token accuracy.
241 pub full_valid_mean_token_accuracy: Option<f64>,
242}
243
244/// A fine-tuning checkpoint object.
245#[derive(Debug, Clone, Serialize, Deserialize)]
246pub struct FineTuningCheckpoint {
247 /// The unique identifier for the checkpoint.
248 pub id: String,
249
250 /// The object type (always "fine_tuning.job.checkpoint").
251 pub object: String,
252
253 /// The Unix timestamp when the checkpoint was created.
254 pub created_at: i64,
255
256 /// The ID of the fine-tuning job.
257 pub fine_tuning_job_id: String,
258
259 /// The name of the checkpoint model.
260 pub fine_tuned_model_checkpoint: String,
261
262 /// The step number at which this checkpoint was created.
263 pub step_number: u32,
264
265 /// Training metrics at this checkpoint.
266 pub metrics: CheckpointMetrics,
267}
268
269/// Response for listing fine-tuning checkpoints.
270#[derive(Debug, Clone, Serialize, Deserialize)]
271pub struct FineTuningCheckpointListResponse {
272 /// The object type (always "list").
273 pub object: String,
274
275 /// The list of checkpoints.
276 pub data: Vec<FineTuningCheckpoint>,
277
278 /// The ID of the first checkpoint in the list.
279 pub first_id: Option<String>,
280
281 /// The ID of the last checkpoint in the list.
282 pub last_id: Option<String>,
283
284 /// Whether there are more checkpoints to retrieve.
285 pub has_more: bool,
286}