Skip to content

Commit

Permalink
feat: Update models catalog with GPT-4 Turbo with Vision in openai_da…
Browse files Browse the repository at this point in the history
…rt (#378)
  • Loading branch information
davidmigloz committed Apr 12, 2024
1 parent a5fff1b commit 8853754
Show file tree
Hide file tree
Showing 12 changed files with 2,638 additions and 1,125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AssistantObject with _$AssistantObject {
/// ID of the model to use. You can use the [List models](https://platform.openai.com/docs/api-reference/models/list) API to see all of your available models, or see our [Model overview](https://platform.openai.com/docs/models/overview) for descriptions of them.
required String model,

/// The system instructions that the assistant uses. The maximum length is 32768 characters.
/// The system instructions that the assistant uses. The maximum length is 256,000 characters.
required String? instructions,

/// A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. Tools can be of types `code_interpreter`, `retrieval`, or `function`.
Expand Down Expand Up @@ -67,7 +67,7 @@ class AssistantObject with _$AssistantObject {
/// Validation constants
static const nameMaxLengthValue = 256;
static const descriptionMaxLengthValue = 512;
static const instructionsMaxLengthValue = 32768;
static const instructionsMaxLengthValue = 256000;

/// Perform validations on the schema property values
String? validateSchema() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ class CreateAssistantRequest with _$CreateAssistantRequest {
/// Factory constructor for CreateAssistantRequest
const factory CreateAssistantRequest({
/// ID of the model to use. You can use the [List models](https://platform.openai.com/docs/api-reference/models/list) API to see all of your available models, or see our [Model overview](https://platform.openai.com/docs/models/overview) for descriptions of them.
@_CreateAssistantRequestModelConverter()
required CreateAssistantRequestModel model,
@_AssistantModelConverter() required AssistantModel model,

/// The name of the assistant. The maximum length is 256 characters.
@JsonKey(includeIfNull: false) String? name,

/// The description of the assistant. The maximum length is 512 characters.
@JsonKey(includeIfNull: false) String? description,

/// The system instructions that the assistant uses. The maximum length is 32768 characters.
/// The system instructions that the assistant uses. The maximum length is 256,000 characters.
@JsonKey(includeIfNull: false) String? instructions,

/// A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. Tools can be of types `code_interpreter`, `retrieval`, or `function`.
Expand Down Expand Up @@ -56,7 +55,7 @@ class CreateAssistantRequest with _$CreateAssistantRequest {
/// Validation constants
static const nameMaxLengthValue = 256;
static const descriptionMaxLengthValue = 512;
static const instructionsMaxLengthValue = 32768;
static const instructionsMaxLengthValue = 256000;

/// Perform validations on the schema property values
String? validateSchema() {
Expand Down Expand Up @@ -89,43 +88,100 @@ class CreateAssistantRequest with _$CreateAssistantRequest {
}

// ==========================================
// CLASS: CreateAssistantRequestModel
// ENUM: AssistantModels
// ==========================================

/// Available assistant models. Mind that the list may not be exhaustive nor up-to-date.
enum AssistantModels {
@JsonValue('gpt-4')
gpt4,
@JsonValue('gpt-4-32k')
gpt432k,
@JsonValue('gpt-4-32k-0314')
gpt432k0314,
@JsonValue('gpt-4-32k-0613')
gpt432k0613,
@JsonValue('gpt-4-0125-preview')
gpt40125Preview,
@JsonValue('gpt-4-0314')
gpt40314,
@JsonValue('gpt-4-0613')
gpt40613,
@JsonValue('gpt-4-1106-preview')
gpt41106Preview,
@JsonValue('gpt-4-vision-preview')
gpt4VisionPreview,
@JsonValue('gpt-4-turbo')
gpt4Turbo,
@JsonValue('gpt-4-turbo-2024-04-09')
gpt4Turbo20240409,
@JsonValue('gpt-4-turbo-preview')
gpt4TurboPreview,
@JsonValue('gpt-3.5-turbo')
gpt35Turbo,
@JsonValue('gpt-3.5-turbo-16k')
gpt35Turbo16k,
@JsonValue('gpt-3.5-turbo-16k-0613')
gpt35Turbo16k0613,
@JsonValue('gpt-3.5-turbo-0125')
gpt35Turbo0125,
@JsonValue('gpt-3.5-turbo-0613')
gpt35Turbo0613,
@JsonValue('gpt-3.5-turbo-1106')
gpt35Turbo1106,
}

// ==========================================
// CLASS: AssistantModel
// ==========================================

/// ID of the model to use. You can use the [List models](https://platform.openai.com/docs/api-reference/models/list) API to see all of your available models, or see our [Model overview](https://platform.openai.com/docs/models/overview) for descriptions of them.
@freezed
sealed class CreateAssistantRequestModel with _$CreateAssistantRequestModel {
const CreateAssistantRequestModel._();
sealed class AssistantModel with _$AssistantModel {
const AssistantModel._();

/// Available assistant models. Mind that the list may not be exhaustive nor up-to-date.
const factory AssistantModel.model(
AssistantModels value,
) = AssistantModelEnumeration;

/// The ID of the model to use.
const factory CreateAssistantRequestModel.string(
const factory AssistantModel.modelId(
String value,
) = CreateAssistantRequestModelString;
) = AssistantModelString;

/// Object construction from a JSON representation
factory CreateAssistantRequestModel.fromJson(Map<String, dynamic> json) =>
_$CreateAssistantRequestModelFromJson(json);
factory AssistantModel.fromJson(Map<String, dynamic> json) =>
_$AssistantModelFromJson(json);
}

/// Custom JSON converter for [CreateAssistantRequestModel]
class _CreateAssistantRequestModelConverter
implements JsonConverter<CreateAssistantRequestModel, Object?> {
const _CreateAssistantRequestModelConverter();
/// Custom JSON converter for [AssistantModel]
class _AssistantModelConverter
implements JsonConverter<AssistantModel, Object?> {
const _AssistantModelConverter();

@override
CreateAssistantRequestModel fromJson(Object? data) {
AssistantModel fromJson(Object? data) {
if (data is String && _$AssistantModelsEnumMap.values.contains(data)) {
return AssistantModelEnumeration(
_$AssistantModelsEnumMap.keys.elementAt(
_$AssistantModelsEnumMap.values.toList().indexOf(data),
),
);
}
if (data is String) {
return CreateAssistantRequestModelString(data);
return AssistantModelString(data);
}
throw Exception(
'Unexpected value for CreateAssistantRequestModel: $data',
'Unexpected value for AssistantModel: $data',
);
}

@override
Object? toJson(CreateAssistantRequestModel data) {
Object? toJson(AssistantModel data) {
return switch (data) {
CreateAssistantRequestModelString(value: final v) => v,
AssistantModelEnumeration(value: final v) => _$AssistantModelsEnumMap[v]!,
AssistantModelString(value: final v) => v,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CreateChatCompletionRequest with _$CreateChatCompletionRequest {
@JsonKey(name: 'logit_bias', includeIfNull: false)
Map<String, int>? logitBias,

/// Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned in the `content` of `message`. This option is currently not available on the `gpt-4-vision-preview` model.
/// Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned in the `content` of `message`.
@JsonKey(includeIfNull: false) bool? logprobs,

/// An integer between 0 and 20 specifying the number of most likely tokens to return at each token position, each with an associated log probability. `logprobs` must be set to `true` if this parameter is used.
Expand Down Expand Up @@ -86,7 +86,7 @@ class CreateChatCompletionRequest with _$CreateChatCompletionRequest {
/// We generally recommend altering this or `temperature` but not both.
@JsonKey(name: 'top_p', includeIfNull: false) @Default(1.0) double? topP,

/// A list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for.
/// A list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for. A max of 128 functions are supported.
@JsonKey(includeIfNull: false) List<ChatCompletionTool>? tools,

/// Controls which (if any) function is called by the model.
Expand Down Expand Up @@ -245,38 +245,42 @@ class CreateChatCompletionRequest with _$CreateChatCompletionRequest {
enum ChatCompletionModels {
@JsonValue('gpt-4')
gpt4,
@JsonValue('gpt-4-0314')
gpt40314,
@JsonValue('gpt-4-0613')
gpt40613,
@JsonValue('gpt-4-32k')
gpt432k,
@JsonValue('gpt-4-32k-0314')
gpt432k0314,
@JsonValue('gpt-4-32k-0613')
gpt432k0613,
@JsonValue('gpt-4-turbo-preview')
gpt4TurboPreview,
@JsonValue('gpt-4-1106-preview')
gpt41106Preview,
@JsonValue('gpt-4-0125-preview')
gpt40125Preview,
@JsonValue('gpt-4-0314')
gpt40314,
@JsonValue('gpt-4-0613')
gpt40613,
@JsonValue('gpt-4-1106-preview')
gpt41106Preview,
@JsonValue('gpt-4-vision-preview')
gpt4VisionPreview,
@JsonValue('gpt-4-turbo')
gpt4Turbo,
@JsonValue('gpt-4-turbo-2024-04-09')
gpt4Turbo20240409,
@JsonValue('gpt-4-turbo-preview')
gpt4TurboPreview,
@JsonValue('gpt-3.5-turbo')
gpt35Turbo,
@JsonValue('gpt-3.5-turbo-16k')
gpt35Turbo16k,
@JsonValue('gpt-3.5-turbo-16k-0613')
gpt35Turbo16k0613,
@JsonValue('gpt-3.5-turbo-0125')
gpt35Turbo0125,
@JsonValue('gpt-3.5-turbo-0301')
gpt35Turbo0301,
@JsonValue('gpt-3.5-turbo-0613')
gpt35Turbo0613,
@JsonValue('gpt-3.5-turbo-1106')
gpt35Turbo1106,
@JsonValue('gpt-3.5-turbo-0125')
gpt35Turbo0125,
@JsonValue('gpt-3.5-turbo-16k-0613')
gpt35Turbo16k0613,
}

// ==========================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CreateCompletionRequest with _$CreateCompletionRequest {

/// Modify the likelihood of specified tokens appearing in the completion.
///
/// Accepts a JSON object that maps tokens (specified by their token ID in the GPT tokenizer) to an associated bias value from -100 to 100. You can use this [tokenizer tool](/tokenizer?view=bpe) to convert text to token IDs. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token.
/// Accepts a JSON object that maps tokens (specified by their token ID in the GPT tokenizer) to an associated bias value from -100 to 100. You can use this [tokenizer tool](https://platform.openai.com/tokenizer?view=bpe) to convert text to token IDs. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token.
///
/// As an example, you can pass `{"50256": -100}` to prevent the <|endoftext|> token from being generated.
@JsonKey(name: 'logit_bias', includeIfNull: false)
Expand Down Expand Up @@ -86,6 +86,8 @@ class CreateCompletionRequest with _$CreateCompletionRequest {
@JsonKey(includeIfNull: false) @Default(false) bool? stream,

/// The suffix that comes after a completion of inserted text.
///
/// This parameter is only supported for `gpt-3.5-turbo-instruct`.
@JsonKey(includeIfNull: false) String? suffix,

/// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
Expand Down
108 changes: 107 additions & 1 deletion packages/openai_dart/lib/src/generated/schema/create_run_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class CreateRunRequest with _$CreateRunRequest {
@JsonKey(name: 'assistant_id') required String assistantId,

/// The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to be used to execute this run. If a value is provided here, it will override the model associated with the assistant. If not, the model associated with the assistant will be used.
@JsonKey(includeIfNull: false) String? model,
@_CreateRunRequestModelConverter()
@JsonKey(includeIfNull: false)
CreateRunRequestModel? model,

/// Overrides the [instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant) of the assistant. This is useful for modifying the behavior on a per-run basis.
@JsonKey(includeIfNull: false) String? instructions,
Expand Down Expand Up @@ -66,3 +68,107 @@ class CreateRunRequest with _$CreateRunRequest {
};
}
}

// ==========================================
// ENUM: RunModels
// ==========================================

/// Available models. Mind that the list may not be exhaustive nor up-to-date.
enum RunModels {
@JsonValue('gpt-4')
gpt4,
@JsonValue('gpt-4-32k')
gpt432k,
@JsonValue('gpt-4-32k-0314')
gpt432k0314,
@JsonValue('gpt-4-32k-0613')
gpt432k0613,
@JsonValue('gpt-4-0125-preview')
gpt40125Preview,
@JsonValue('gpt-4-0314')
gpt40314,
@JsonValue('gpt-4-0613')
gpt40613,
@JsonValue('gpt-4-1106-preview')
gpt41106Preview,
@JsonValue('gpt-4-vision-preview')
gpt4VisionPreview,
@JsonValue('gpt-4-turbo')
gpt4Turbo,
@JsonValue('gpt-4-turbo-2024-04-09')
gpt4Turbo20240409,
@JsonValue('gpt-4-turbo-preview')
gpt4TurboPreview,
@JsonValue('gpt-3.5-turbo')
gpt35Turbo,
@JsonValue('gpt-3.5-turbo-16k')
gpt35Turbo16k,
@JsonValue('gpt-3.5-turbo-16k-0613')
gpt35Turbo16k0613,
@JsonValue('gpt-3.5-turbo-0125')
gpt35Turbo0125,
@JsonValue('gpt-3.5-turbo-0613')
gpt35Turbo0613,
@JsonValue('gpt-3.5-turbo-1106')
gpt35Turbo1106,
}

// ==========================================
// CLASS: CreateRunRequestModel
// ==========================================

/// The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to be used to execute this run. If a value is provided here, it will override the model associated with the assistant. If not, the model associated with the assistant will be used.
@freezed
sealed class CreateRunRequestModel with _$CreateRunRequestModel {
const CreateRunRequestModel._();

/// Available models. Mind that the list may not be exhaustive nor up-to-date.
const factory CreateRunRequestModel.enumeration(
RunModels value,
) = CreateRunRequestModelEnumeration;

/// The ID of the model to use for this request.
const factory CreateRunRequestModel.string(
String value,
) = CreateRunRequestModelString;

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

/// Custom JSON converter for [CreateRunRequestModel]
class _CreateRunRequestModelConverter
implements JsonConverter<CreateRunRequestModel?, Object?> {
const _CreateRunRequestModelConverter();

@override
CreateRunRequestModel? fromJson(Object? data) {
if (data == null) {
return null;
}
if (data is String && _$RunModelsEnumMap.values.contains(data)) {
return CreateRunRequestModelEnumeration(
_$RunModelsEnumMap.keys.elementAt(
_$RunModelsEnumMap.values.toList().indexOf(data),
),
);
}
if (data is String) {
return CreateRunRequestModelString(data);
}
throw Exception(
'Unexpected value for CreateRunRequestModel: $data',
);
}

@override
Object? toJson(CreateRunRequestModel? data) {
return switch (data) {
CreateRunRequestModelEnumeration(value: final v) =>
_$RunModelsEnumMap[v]!,
CreateRunRequestModelString(value: final v) => v,
null => null,
};
}
}

0 comments on commit 8853754

Please sign in to comment.