Skip to content

Commit

Permalink
feat: Add support for maxCompletionTokens and reasoningTokens in open…
Browse files Browse the repository at this point in the history
…ai_dart (#556)
  • Loading branch information
davidmigloz committed Sep 25, 2024
1 parent 9ceb5ff commit 37d75b6
Show file tree
Hide file tree
Showing 19 changed files with 853 additions and 277 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ class AssistantObject with _$AssistantObject {
/// [GPT-4 Turbo](https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4), and all GPT-3.5 Turbo models
/// since `gpt-3.5-turbo-1106`.
///
/// Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs which guarantees
/// Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs which ensures
/// the model will match your supplied JSON schema. Learn more in the
/// [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
///
/// Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the message the model generates
/// Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message the model generates
/// is valid JSON.
///
/// **Important:** when using JSON mode, you **must** also instruct the model to produce JSON yourself via a
Expand Down Expand Up @@ -191,11 +191,11 @@ enum AssistantResponseFormatMode {
/// [GPT-4 Turbo](https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4), and all GPT-3.5 Turbo models
/// since `gpt-3.5-turbo-1106`.
///
/// Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs which guarantees
/// Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs which ensures
/// the model will match your supplied JSON schema. Learn more in the
/// [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
///
/// Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the message the model generates
/// Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message the model generates
/// is valid JSON.
///
/// **Important:** when using JSON mode, you **must** also instruct the model to produce JSON yourself via a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ class AssistantToolsFileSearchFileSearch
/// for more information.
@JsonKey(name: 'max_num_results', includeIfNull: false) int? maxNumResults,

/// The ranking options for the file search.
/// The ranking options for the file search. If not specified, the file search tool will use the `auto` ranker and
/// a score_threshold of 0.
///
/// See the [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search/customizing-file-search-settings)
/// for more information.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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: CompletionTokensDetails
// ==========================================

/// Breakdown of tokens used in a completion.
@freezed
class CompletionTokensDetails with _$CompletionTokensDetails {
const CompletionTokensDetails._();

/// Factory constructor for CompletionTokensDetails
const factory CompletionTokensDetails({
/// Tokens generated by the model for reasoning.
@JsonKey(name: 'reasoning_tokens', includeIfNull: false)
int? reasoningTokens,
}) = _CompletionTokensDetails;

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

/// List of all property names of schema
static const List<String> propertyNames = ['reasoning_tokens'];

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

/// Map representation of object (not serialized)
Map<String, dynamic> toMap() {
return {
'reasoning_tokens': reasoningTokens,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class CompletionUsage with _$CompletionUsage {

/// Total number of tokens used in the request (prompt + completion).
@JsonKey(name: 'total_tokens') required int totalTokens,

/// Breakdown of tokens used in a completion.
@JsonKey(name: 'completion_tokens_details', includeIfNull: false)
CompletionTokensDetails? completionTokensDetails,
}) = _CompletionUsage;

/// Object construction from a JSON representation
Expand All @@ -33,7 +37,8 @@ class CompletionUsage with _$CompletionUsage {
static const List<String> propertyNames = [
'completion_tokens',
'prompt_tokens',
'total_tokens'
'total_tokens',
'completion_tokens_details'
];

/// Perform validations on the schema property values
Expand All @@ -47,6 +52,7 @@ class CompletionUsage with _$CompletionUsage {
'completion_tokens': completionTokens,
'prompt_tokens': promptTokens,
'total_tokens': totalTokens,
'completion_tokens_details': completionTokensDetails,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ class CreateAssistantRequest with _$CreateAssistantRequest {
/// [GPT-4 Turbo](https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4), and all GPT-3.5 Turbo models
/// since `gpt-3.5-turbo-1106`.
///
/// Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs which guarantees
/// Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs which ensures
/// the model will match your supplied JSON schema. Learn more in the
/// [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
///
/// Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the message the model generates
/// Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message the model generates
/// is valid JSON.
///
/// **Important:** when using JSON mode, you **must** also instruct the model to produce JSON yourself via a
Expand Down Expand Up @@ -185,8 +185,6 @@ enum AssistantModels {
gpt4o20240513,
@JsonValue('gpt-4o-2024-08-06')
gpt4o20240806,
@JsonValue('gpt-4o-2024-08-06')
gpt4o20240806,
@JsonValue('gpt-4o-mini')
gpt4oMini,
@JsonValue('gpt-4o-mini-2024-07-18')
Expand Down Expand Up @@ -289,11 +287,11 @@ enum CreateAssistantResponseFormatMode {
/// [GPT-4 Turbo](https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4), and all GPT-3.5 Turbo models
/// since `gpt-3.5-turbo-1106`.
///
/// Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs which guarantees
/// Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured Outputs which ensures
/// the model will match your supplied JSON schema. Learn more in the
/// [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
///
/// Setting to `{ "type": "json_object" }` enables JSON mode, which guarantees the message the model generates
/// Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the message the model generates
/// is valid JSON.
///
/// **Important:** when using JSON mode, you **must** also instruct the model to produce JSON yourself via a
Expand Down
Loading

0 comments on commit 37d75b6

Please sign in to comment.