Skip to content

Commit

Permalink
feat: Add support for checkpoints in fine-tuning jobs in openai_dart (d…
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmigloz authored and KennethKnudsen97 committed Apr 22, 2024
1 parent cb6a4ef commit c0b48ac
Show file tree
Hide file tree
Showing 9 changed files with 3,773 additions and 320 deletions.
33 changes: 33 additions & 0 deletions packages/openai_dart/lib/src/generated/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,39 @@ class OpenAIClient {
return FineTuningJob.fromJson(_jsonDecode(r));
}

// ------------------------------------------
// METHOD: listFineTuningJobCheckpoints
// ------------------------------------------

/// List checkpoints for a fine-tuning job.
///
/// `fineTuningJobId`: The ID of the fine-tuning job to get checkpoints for.
///
/// `after`: Identifier for the last checkpoint ID from the previous pagination request.
///
/// `limit`: Number of checkpoints to retrieve.
///
/// `GET` `https://api.openai.com/v1/fine_tuning/jobs/{fine_tuning_job_id}/checkpoints`
Future<ListFineTuningJobCheckpointsResponse> listFineTuningJobCheckpoints({
required String fineTuningJobId,
String? after,
int limit = 10,
}) async {
final r = await makeRequest(
baseUrl: 'https://api.openai.com/v1',
path: '/fine_tuning/jobs/$fineTuningJobId/checkpoints',
method: HttpMethod.get,
isMultipart: false,
requestType: '',
responseType: 'application/json',
queryParams: {
if (after != null) 'after': after,
'limit': limit,
},
);
return ListFineTuningJobCheckpointsResponse.fromJson(_jsonDecode(r));
}

// ------------------------------------------
// METHOD: createImage
// ------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: invalid_annotation_target
part of open_a_i_schema;

// ==========================================
// CLASS: FineTuningJobCheckpoint
// ==========================================

/// The `fine_tuning.job.checkpoint` object represents a model checkpoint for a fine-tuning job that is ready to use.
@freezed
class FineTuningJobCheckpoint with _$FineTuningJobCheckpoint {
const FineTuningJobCheckpoint._();

/// Factory constructor for FineTuningJobCheckpoint
const factory FineTuningJobCheckpoint({
/// The checkpoint identifier, which can be referenced in the API endpoints.
required String id,

/// The Unix timestamp (in seconds) for when the checkpoint was created.
@JsonKey(name: 'created_at') required int createdAt,

/// The name of the fine-tuned checkpoint model that is created.
@JsonKey(name: 'fine_tuned_model_checkpoint')
required String fineTunedModelCheckpoint,

/// The step number that the checkpoint was created at.
@JsonKey(name: 'step_number') required int stepNumber,

/// Metrics at the step number during the fine-tuning job.
required FineTuningJobCheckpointMetrics metrics,

/// The name of the fine-tuning job that this checkpoint was created from.
@JsonKey(name: 'fine_tuning_job_id') required String fineTuningJobId,

/// The object type, which is always "fine_tuning.job.checkpoint".
required FineTuningJobCheckpointObject object,
}) = _FineTuningJobCheckpoint;

/// Object construction from a JSON representation
factory FineTuningJobCheckpoint.fromJson(Map<String, dynamic> json) =>
_$FineTuningJobCheckpointFromJson(json);

/// List of all property names of schema
static const List<String> propertyNames = [
'id',
'created_at',
'fine_tuned_model_checkpoint',
'step_number',
'metrics',
'fine_tuning_job_id',
'object'
];

/// Perform validations on the schema property values
String? validateSchema() {
return null;
}

/// Map representation of object (not serialized)
Map<String, dynamic> toMap() {
return {
'id': id,
'created_at': createdAt,
'fine_tuned_model_checkpoint': fineTunedModelCheckpoint,
'step_number': stepNumber,
'metrics': metrics,
'fine_tuning_job_id': fineTuningJobId,
'object': object,
};
}
}

// ==========================================
// CLASS: FineTuningJobCheckpointMetrics
// ==========================================

/// Metrics at the step number during the fine-tuning job.
@freezed
class FineTuningJobCheckpointMetrics with _$FineTuningJobCheckpointMetrics {
const FineTuningJobCheckpointMetrics._();

/// Factory constructor for FineTuningJobCheckpointMetrics
const factory FineTuningJobCheckpointMetrics({
/// The step number that the metrics were recorded at.
@JsonKey(includeIfNull: false) double? step,

/// The training loss at the step number.
@JsonKey(name: 'train_loss', includeIfNull: false) double? trainLoss,

/// The training mean token accuracy at the step number.
@JsonKey(name: 'train_mean_token_accuracy', includeIfNull: false)
double? trainMeanTokenAccuracy,

/// The validation loss at the step number.
@JsonKey(name: 'valid_loss', includeIfNull: false) double? validLoss,

/// The validation mean token accuracy at the step number.
@JsonKey(name: 'valid_mean_token_accuracy', includeIfNull: false)
double? validMeanTokenAccuracy,

/// The full validation loss at the step number.
@JsonKey(name: 'full_valid_loss', includeIfNull: false)
double? fullValidLoss,

/// The full validation mean token accuracy at the step number.
@JsonKey(name: 'full_valid_mean_token_accuracy', includeIfNull: false)
double? fullValidMeanTokenAccuracy,
}) = _FineTuningJobCheckpointMetrics;

/// Object construction from a JSON representation
factory FineTuningJobCheckpointMetrics.fromJson(Map<String, dynamic> json) =>
_$FineTuningJobCheckpointMetricsFromJson(json);

/// List of all property names of schema
static const List<String> propertyNames = [
'step',
'train_loss',
'train_mean_token_accuracy',
'valid_loss',
'valid_mean_token_accuracy',
'full_valid_loss',
'full_valid_mean_token_accuracy'
];

/// Perform validations on the schema property values
String? validateSchema() {
return null;
}

/// Map representation of object (not serialized)
Map<String, dynamic> toMap() {
return {
'step': step,
'train_loss': trainLoss,
'train_mean_token_accuracy': trainMeanTokenAccuracy,
'valid_loss': validLoss,
'valid_mean_token_accuracy': validMeanTokenAccuracy,
'full_valid_loss': fullValidLoss,
'full_valid_mean_token_accuracy': fullValidMeanTokenAccuracy,
};
}
}

// ==========================================
// ENUM: FineTuningJobCheckpointObject
// ==========================================

/// The object type, which is always "fine_tuning.job.checkpoint".
enum FineTuningJobCheckpointObject {
@JsonValue('fine_tuning.job.checkpoint')
fineTuningJobCheckpoint,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: invalid_annotation_target
part of open_a_i_schema;

// ==========================================
// CLASS: ListFineTuningJobCheckpointsResponse
// ==========================================

/// Represents a list of fine-tuning job checkpoints.
@freezed
class ListFineTuningJobCheckpointsResponse
with _$ListFineTuningJobCheckpointsResponse {
const ListFineTuningJobCheckpointsResponse._();

/// Factory constructor for ListFineTuningJobCheckpointsResponse
const factory ListFineTuningJobCheckpointsResponse({
/// The list of fine-tuning job checkpoints.
required List<FineTuningJobCheckpoint> data,

/// The object type, which is always "list".
required ListFineTuningJobCheckpointsResponseObject object,

/// The ID of the first checkpoint in the list.
@JsonKey(name: 'first_id', includeIfNull: false) String? firstId,

/// The ID of the last checkpoint in the list.
@JsonKey(name: 'last_id', includeIfNull: false) String? lastId,

/// Whether there are more checkpoints to retrieve.
@JsonKey(name: 'has_more') required bool hasMore,
}) = _ListFineTuningJobCheckpointsResponse;

/// Object construction from a JSON representation
factory ListFineTuningJobCheckpointsResponse.fromJson(
Map<String, dynamic> json) =>
_$ListFineTuningJobCheckpointsResponseFromJson(json);

/// List of all property names of schema
static const List<String> propertyNames = [
'data',
'object',
'first_id',
'last_id',
'has_more'
];

/// Perform validations on the schema property values
String? validateSchema() {
return null;
}

/// Map representation of object (not serialized)
Map<String, dynamic> toMap() {
return {
'data': data,
'object': object,
'first_id': firstId,
'last_id': lastId,
'has_more': hasMore,
};
}
}

// ==========================================
// ENUM: ListFineTuningJobCheckpointsResponseObject
// ==========================================

/// The object type, which is always "list".
enum ListFineTuningJobCheckpointsResponseObject {
@JsonValue('list')
list,
}
2 changes: 2 additions & 0 deletions packages/openai_dart/lib/src/generated/schema/schema.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ part 'fine_tuning_job_error.dart';
part 'fine_tuning_job_hyperparameters.dart';
part 'list_paginated_fine_tuning_jobs_response.dart';
part 'list_fine_tuning_job_events_response.dart';
part 'list_fine_tuning_job_checkpoints_response.dart';
part 'fine_tuning_job_event.dart';
part 'fine_tuning_job_checkpoint.dart';
part 'create_image_request.dart';
part 'images_response.dart';
part 'image.dart';
Expand Down
Loading

0 comments on commit c0b48ac

Please sign in to comment.