portkey_sdk/model/
fine_tuning.rs

1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5/// Request to create a fine-tuning job.
6///
7/// # Example
8///
9/// ```rust,ignore
10/// use portkey::model::CreateFineTuningJobRequest;
11///
12/// let request = CreateFineTuningJobRequest::builder()
13///     .model("gpt-3.5-turbo")
14///     .training_file("file-abc123")
15///     .build()
16///     .unwrap();
17/// ```
18#[derive(Clone, Debug, Default, Serialize, Deserialize)]
19pub struct CreateFineTuningJobRequest {
20    /// The name of the model to fine-tune.
21    pub model: String,
22
23    /// The ID of an uploaded file that contains training data.
24    pub training_file: String,
25
26    /// The hyperparameters used for the fine-tuning job.
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub hyperparameters: Option<Hyperparameters>,
29
30    /// A string of up to 18 characters that will be added to your fine-tuned model name.
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub suffix: Option<String>,
33
34    /// The ID of an uploaded file that contains validation data.
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub validation_file: Option<String>,
37
38    /// A list of integrations to enable for your fine-tuning job.
39    #[serde(skip_serializing_if = "Option::is_none")]
40    pub integrations: Option<Vec<Integration>>,
41
42    /// The seed controls the reproducibility of the job.
43    #[serde(skip_serializing_if = "Option::is_none")]
44    pub seed: Option<i64>,
45}
46
47/// The hyperparameters used for the fine-tuning job.
48#[derive(Clone, Debug, Default, Serialize, Deserialize)]
49pub struct Hyperparameters {
50    /// Number of examples in each batch.
51    #[serde(skip_serializing_if = "Option::is_none")]
52    pub batch_size: Option<HyperparameterValue>,
53
54    /// Scaling factor for the learning rate.
55    #[serde(skip_serializing_if = "Option::is_none")]
56    pub learning_rate_multiplier: Option<HyperparameterValue>,
57
58    /// The number of epochs to train the model for.
59    #[serde(skip_serializing_if = "Option::is_none")]
60    pub n_epochs: Option<HyperparameterValue>,
61}
62
63/// A hyperparameter value can be either "auto" or a specific number.
64#[derive(Clone, Debug, Serialize, Deserialize)]
65#[serde(untagged)]
66pub enum HyperparameterValue {
67    Auto(String),
68    Number(f64),
69}
70
71/// Integration configuration for a fine-tuning job.
72#[derive(Clone, Debug, Serialize, Deserialize)]
73pub struct Integration {
74    /// The type of integration to enable.
75    #[serde(rename = "type")]
76    pub integration_type: String,
77
78    /// The settings for the wandb integration.
79    pub wandb: WandbIntegration,
80}
81
82/// Weights & Biases integration configuration.
83#[derive(Clone, Debug, Serialize, Deserialize)]
84pub struct WandbIntegration {
85    /// The name of the project that the new run will be created under.
86    pub project: String,
87
88    /// A display name to set for the run.
89    #[serde(skip_serializing_if = "Option::is_none")]
90    pub name: Option<String>,
91
92    /// The entity to use for the run.
93    #[serde(skip_serializing_if = "Option::is_none")]
94    pub entity: Option<String>,
95
96    /// A list of tags to be attached to the newly created run.
97    #[serde(skip_serializing_if = "Option::is_none")]
98    pub tags: Option<Vec<String>>,
99}
100
101/// The fine-tuning job object.
102#[derive(Clone, Debug, Serialize, Deserialize)]
103pub struct FineTuningJob {
104    /// The object identifier, which can be referenced in the API endpoints.
105    pub id: String,
106
107    /// The Unix timestamp (in seconds) for when the fine-tuning job was created.
108    pub created_at: i64,
109
110    /// For fine-tuning jobs that have failed, this will contain more information on the cause of the failure.
111    #[serde(skip_serializing_if = "Option::is_none")]
112    pub error: Option<FineTuningError>,
113
114    /// The name of the fine-tuned model that is being created.
115    #[serde(skip_serializing_if = "Option::is_none")]
116    pub fine_tuned_model: Option<String>,
117
118    /// The Unix timestamp (in seconds) for when the fine-tuning job was finished.
119    #[serde(skip_serializing_if = "Option::is_none")]
120    pub finished_at: Option<i64>,
121
122    /// The hyperparameters used for the fine-tuning job.
123    pub hyperparameters: Hyperparameters,
124
125    /// The base model that is being fine-tuned.
126    pub model: String,
127
128    /// The object type, which is always "fine_tuning.job".
129    pub object: String,
130
131    /// The organization that owns the fine-tuning job.
132    pub organization_id: String,
133
134    /// The compiled results file ID(s) for the fine-tuning job.
135    pub result_files: Vec<String>,
136
137    /// The current status of the fine-tuning job.
138    pub status: String,
139
140    /// The total number of billable tokens processed by this fine-tuning job.
141    #[serde(skip_serializing_if = "Option::is_none")]
142    pub trained_tokens: Option<i64>,
143
144    /// The file ID used for training.
145    pub training_file: String,
146
147    /// The file ID used for validation.
148    #[serde(skip_serializing_if = "Option::is_none")]
149    pub validation_file: Option<String>,
150
151    /// A list of integrations to enable for your fine-tuning job.
152    #[serde(skip_serializing_if = "Option::is_none")]
153    pub integrations: Option<Vec<Integration>>,
154
155    /// The seed used for the fine-tuning job.
156    #[serde(skip_serializing_if = "Option::is_none")]
157    pub seed: Option<i64>,
158
159    /// The Unix timestamp (in seconds) for when the fine-tuning job is estimated to finish.
160    #[serde(skip_serializing_if = "Option::is_none")]
161    pub estimated_finish: Option<i64>,
162}
163
164/// Error information for a failed fine-tuning job.
165#[derive(Clone, Debug, Serialize, Deserialize)]
166pub struct FineTuningError {
167    /// A machine-readable error code.
168    pub code: String,
169
170    /// A human-readable error message.
171    pub message: String,
172
173    /// The parameter that was invalid.
174    #[serde(skip_serializing_if = "Option::is_none")]
175    pub param: Option<String>,
176}
177
178/// Response containing a list of fine-tuning jobs.
179#[derive(Clone, Debug, Serialize, Deserialize)]
180pub struct ListFineTuningJobsResponse {
181    pub object: String,
182    pub data: Vec<FineTuningJob>,
183    pub has_more: bool,
184}
185
186/// A fine-tuning job event object.
187#[derive(Clone, Debug, Serialize, Deserialize)]
188pub struct FineTuningJobEvent {
189    pub id: String,
190    pub created_at: i64,
191    pub level: String,
192    pub message: String,
193    pub object: String,
194}
195
196/// Response containing a list of fine-tuning job events.
197#[derive(Clone, Debug, Serialize, Deserialize)]
198pub struct ListFineTuningJobEventsResponse {
199    pub object: String,
200    pub data: Vec<FineTuningJobEvent>,
201}
202
203/// A fine-tuning job checkpoint object.
204#[derive(Clone, Debug, Serialize, Deserialize)]
205pub struct FineTuningJobCheckpoint {
206    /// The checkpoint identifier, which can be referenced in the API endpoints.
207    pub id: String,
208
209    /// The Unix timestamp (in seconds) for when the checkpoint was created.
210    pub created_at: i64,
211
212    /// The name of the fine-tuned checkpoint model that is created.
213    pub fine_tuned_model_checkpoint: String,
214
215    /// The step number that the checkpoint was created at.
216    pub step_number: i64,
217
218    /// Metrics at the step number during the fine-tuning job.
219    pub metrics: HashMap<String, f64>,
220
221    /// The name of the fine-tuning job that this checkpoint was created from.
222    pub fine_tuning_job_id: String,
223
224    /// The object type, which is always "fine_tuning.job.checkpoint".
225    pub object: String,
226}
227
228/// Response containing a list of fine-tuning job checkpoints.
229#[derive(Clone, Debug, Serialize, Deserialize)]
230pub struct ListFineTuningJobCheckpointsResponse {
231    pub object: String,
232    pub data: Vec<FineTuningJobCheckpoint>,
233    pub first_id: Option<String>,
234    pub last_id: Option<String>,
235    pub has_more: bool,
236}