All files / shared/src/types/api/routes/fine-tuning-api response.ts

96.29% Statements 104/108
100% Branches 1/1
100% Functions 0/0
96.29% Lines 104/108

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 297 298 299 300 301 3021x         1x 1x 1x 1x 1x 1x 1x           1x   1x   1x   1x 1x             1x   1x   1x   1x 1x                 1x   1x   1x   1x   1x   1x   1x 1x 1x             1x   1x   1x   1x         1x   1x   1x   1x   1x   1x   1x   1x   1x   1x   1x   1x   1x   1x   1x   1x 1x             1x             1x             1x   1x   1x   1x   1x   1x   1x   1x 1x             1x   1x   1x   1x   1x   1x   1x   1x 1x             1x   1x   1x   1x   1x   1x   1x   1x 1x             1x   1x   1x   1x   1x   1x 1x             1x   1x   1x   1x   1x   1x 1x             1x   1x   1x   1x   1x   1x 1x             1x                 1x                 1x                 1x                 1x                 1x          
import { z } from 'zod';
 
/**
 * The status of a fine-tuning job.
 */
export enum FineTuningJobStatus {
  VALIDATING_FILES = 'validating_files',
  QUEUED = 'queued',
  RUNNING = 'running',
  SUCCEEDED = 'succeeded',
  FAILED = 'failed',
  CANCELLED = 'cancelled',
}
 
/**
 * Error information for a fine-tuning job.
 */
export const FineTuningJobError = z.object({
  /** Machine-readable error code. */
  code: z.string(),
  /** Human-readable error message. */
  message: z.string(),
  /** The parameter that caused the error, if applicable. */
  param: z.string().nullable().optional(),
});
 
export type FineTuningJobError = z.infer<typeof FineTuningJobError>;
 
/**
 * The hyperparameters used for the fine-tuning job.
 */
export const FineTuningJobHyperparameters = z.object({
  /** Number of epochs to train the model for. */
  n_epochs: z.union([z.number().int(), z.literal('auto')]),
  /** Batch size used for training. */
  batch_size: z.union([z.number().int(), z.literal('auto')]).optional(),
  /** Learning rate multiplier used for training. */
  learning_rate_multiplier: z.union([z.number(), z.literal('auto')]).optional(),
});
 
export type FineTuningJobHyperparameters = z.infer<
  typeof FineTuningJobHyperparameters
>;
 
/**
 * Integration configuration for fine-tuning job.
 */
export const FineTuningJobIntegration = z.object({
  /** The type of integration. */
  type: z.literal('wandb'),
  /** The Weights and Biases integration configuration. */
  wandb: z.object({
    /** The name of the project that the new run will be created under. */
    project: z.string(),
    /** A display name to set for the run. */
    name: z.string().optional(),
    /** The entity to use for the run. */
    entity: z.string().optional(),
    /** A list of tags to be attached to the newly created run. */
    tags: z.array(z.string()).optional(),
  }),
});
 
export type FineTuningJobIntegration = z.infer<typeof FineTuningJobIntegration>;
 
/**
 * A fine-tuning job object.
 */
export const FineTuningJob = z.object({
  /** The object identifier, which can be referenced in the API endpoints. */
  id: z.string(),
  /** The object type, which is always "fine_tuning.job". */
  object: z.literal('fine_tuning.job'),
  /** The Unix timestamp (in seconds) for when the fine-tuning job was created. */
  created_at: z.number().transform((v) => {
    if (v.toString().length === 10) {
      return v * 1000;
    }
    return v;
  }),
  /** For fine-tuning jobs that have failed, this will contain more information on the cause of the failure. */
  error: FineTuningJobError.nullable().optional(),
  /** The name of the fine-tuned model that is being created. The value will be null if the fine-tuning job is still running. */
  fine_tuned_model: z.string().nullable().optional(),
  /** The Unix timestamp (in seconds) for when the fine-tuning job was finished. The value will be null if the fine-tuning job is still running. */
  finished_at: z.number().nullable().optional(),
  /** The hyperparameters used for the fine-tuning job. */
  hyperparameters: FineTuningJobHyperparameters,
  /** The base model that is being fine-tuned. */
  model: z.string(),
  /** The organization that owns the fine-tuning job. */
  organization_id: z.string().optional(),
  /** The compiled results file ID(s) for the fine-tuning job. You can retrieve the results with the Files API. */
  result_files: z.array(z.string()).optional(),
  /** The current status of the fine-tuning job. */
  status: z.enum(FineTuningJobStatus),
  /** The total number of billable tokens processed by this fine-tuning job. The value will be null if the fine-tuning job is still running. */
  trained_tokens: z.number().nullable().optional(),
  /** The file ID used for training. You can retrieve the training data with the Files API. */
  training_file: z.string(),
  /** The file ID used for validation. You can retrieve the validation results with the Files API. */
  validation_file: z.string().nullable().optional(),
  /** A list of integrations to enable for your fine-tuning job. */
  integrations: z.array(FineTuningJobIntegration).optional(),
  /** The seed used for the fine-tuning job. */
  seed: z.number().optional(),
  /** The Unix timestamp (in seconds) for when the fine-tuning job is estimated to finish. The value will be null if the fine-tuning job is not running. */
  estimated_finish: z.number().nullable().optional(),
  /** Set of 16 key-value pairs that can be attached to an object. */
  metadata: z.record(z.string(), z.string()).optional(),
});
 
export type FineTuningJob = z.infer<typeof FineTuningJob>;
 
/**
 * The type of fine-tuning event.
 */
export const FineTuningEventLevel = z.enum(['info', 'warn', 'error']);
 
export type FineTuningEventLevel = z.infer<typeof FineTuningEventLevel>;
 
/**
 * The type of fine-tuning event.
 */
export const FineTuningEventType = z.enum(['message', 'metrics']);
 
export type FineTuningEventType = z.infer<typeof FineTuningEventType>;
 
/**
 * Fine-tuning job event object.
 */
export const FineTuningEvent = z.object({
  /** The object identifier. */
  id: z.string(),
  /** The object type, which is always "fine_tuning.job.event". */
  object: z.literal('fine_tuning.job.event'),
  /** The Unix timestamp (in seconds) for when the event was created. */
  created_at: z.number(),
  /** The level of the event. */
  level: FineTuningEventLevel,
  /** The message of the event. */
  message: z.string(),
  /** The type of event. */
  type: FineTuningEventType,
  /** Metrics at the step number during the fine-tuning job. Use these numbers to understand if your training is going smoothly (loss should decrease, token accuracy should increase). */
  data: z.record(z.string(), z.unknown()).optional(),
});
 
export type FineTuningEvent = z.infer<typeof FineTuningEvent>;
 
/**
 * Metrics at a step during the fine-tuning job.
 */
export const FineTuningStepMetrics = z.object({
  /** The step number. */
  step: z.number(),
  /** The training loss at this step. */
  train_loss: z.number().optional(),
  /** The training token accuracy at this step. */
  train_mean_token_accuracy: z.number().optional(),
  /** The valid loss at this step. */
  valid_loss: z.number().optional(),
  /** The valid mean token accuracy at this step. */
  valid_mean_token_accuracy: z.number().optional(),
  /** The full valid loss at this step. */
  full_valid_loss: z.number().optional(),
  /** The full valid mean token accuracy at this step. */
  full_valid_mean_token_accuracy: z.number().optional(),
});
 
export type FineTuningStepMetrics = z.infer<typeof FineTuningStepMetrics>;
 
/**
 * Fine-tuning job checkpoint object.
 */
export const FineTuningCheckpoint = z.object({
  /** The checkpoint identifier, which can be referenced in the API endpoints. */
  id: z.string(),
  /** The object type, which is always "fine_tuning.job.checkpoint". */
  object: z.literal('fine_tuning.job.checkpoint'),
  /** The Unix timestamp (in seconds) for when the checkpoint was created. */
  created_at: z.number(),
  /** The name of the fine-tuned checkpoint model that is created. */
  fine_tuned_model_checkpoint: z.string(),
  /** The step number that the checkpoint was created at. */
  step_number: z.number(),
  /** Metrics at the step number during the fine-tuning job. */
  metrics: FineTuningStepMetrics,
  /** The name of the fine-tuning job that this checkpoint was created from. */
  fine_tuning_job_id: z.string(),
});
 
export type FineTuningCheckpoint = z.infer<typeof FineTuningCheckpoint>;
 
/**
 * List of fine-tuning job objects.
 */
export const FineTuningJobList = z.object({
  /** The object type, which is always "list". */
  object: z.literal('list'),
  /** Array of fine-tuning job objects. */
  data: z.array(FineTuningJob),
  /** The first_id if pagination is needed. */
  first_id: z.string().optional(),
  /** The last_id if pagination is needed. */
  last_id: z.string().optional(),
  /** True if there are more fine-tuning jobs available. */
  has_more: z.boolean(),
});
 
export type FineTuningJobList = z.infer<typeof FineTuningJobList>;
 
/**
 * List of fine-tuning event objects.
 */
export const FineTuningEventList = z.object({
  /** The object type, which is always "list". */
  object: z.literal('list'),
  /** Array of fine-tuning event objects. */
  data: z.array(FineTuningEvent),
  /** The first_id if pagination is needed. */
  first_id: z.string().optional(),
  /** The last_id if pagination is needed. */
  last_id: z.string().optional(),
  /** True if there are more fine-tuning events available. */
  has_more: z.boolean(),
});
 
export type FineTuningEventList = z.infer<typeof FineTuningEventList>;
 
/**
 * List of fine-tuning checkpoint objects.
 */
export const FineTuningCheckpointList = z.object({
  /** The object type, which is always "list". */
  object: z.literal('list'),
  /** Array of fine-tuning checkpoint objects. */
  data: z.array(FineTuningCheckpoint),
  /** The first_id if pagination is needed. */
  first_id: z.string().optional(),
  /** The last_id if pagination is needed. */
  last_id: z.string().optional(),
  /** True if there are more checkpoints available. */
  has_more: z.boolean(),
});
 
export type FineTuningCheckpointList = z.infer<typeof FineTuningCheckpointList>;
 
/**
 * Response for creating a fine-tuning job.
 */
export const CreateFineTuningJobResponseBody = FineTuningJob;
 
export type CreateFineTuningJobResponseBody = z.infer<
  typeof CreateFineTuningJobResponseBody
>;
 
/**
 * Response for retrieving a fine-tuning job.
 */
export const RetrieveFineTuningJobResponseBody = FineTuningJob;
 
export type RetrieveFineTuningJobResponseBody = z.infer<
  typeof RetrieveFineTuningJobResponseBody
>;
 
/**
 * Response for listing fine-tuning jobs.
 */
export const ListFineTuningJobsResponseBody = FineTuningJobList;
 
export type ListFineTuningJobsResponseBody = z.infer<
  typeof ListFineTuningJobsResponseBody
>;
 
/**
 * Response for cancelling a fine-tuning job.
 */
export const CancelFineTuningJobResponseBody = FineTuningJob;
 
export type CancelFineTuningJobResponseBody = z.infer<
  typeof CancelFineTuningJobResponseBody
>;
 
/**
 * Response for listing fine-tuning events.
 */
export const ListFineTuningEventsResponseBody = FineTuningEventList;
 
export type ListFineTuningEventsResponseBody = z.infer<
  typeof ListFineTuningEventsResponseBody
>;
 
/**
 * Response for listing fine-tuning checkpoints.
 */
export const ListFineTuningCheckpointsResponseBody = FineTuningCheckpointList;
 
export type ListFineTuningCheckpointsResponseBody = z.infer<
  typeof ListFineTuningCheckpointsResponseBody
>;