Skip to content

Commit

Permalink
feat: Add support for service tier in openai_dart (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmigloz authored Jul 18, 2024
1 parent c46d676 commit 0838e4b
Show file tree
Hide file tree
Showing 10 changed files with 352 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ class CreateChatCompletionRequest with _$CreateChatCompletionRequest {
/// Determinism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend.
@JsonKey(includeIfNull: false) int? seed,

/// Specifies the latency tier to use for processing the request. This parameter is relevant for customers
/// subscribed to the scale tier service:
/// - If set to 'auto', the system will utilize scale tier credits until they are exhausted.
/// - If set to 'default', the request will be processed using the default service tier with a lower
/// uptime SLA and no latency guarantee.
///
/// When this parameter is set, the response body will include the `service_tier` utilized.
@JsonKey(
name: 'service_tier',
includeIfNull: false,
unknownEnumValue: JsonKey.nullForUndefinedEnumValue,
)
CreateChatCompletionRequestServiceTier? serviceTier,

/// Up to 4 sequences where the API will stop generating further tokens.
@_ChatCompletionStopConverter()
@JsonKey(includeIfNull: false)
Expand Down Expand Up @@ -148,6 +162,7 @@ class CreateChatCompletionRequest with _$CreateChatCompletionRequest {
'presence_penalty',
'response_format',
'seed',
'service_tier',
'stop',
'stream',
'stream_options',
Expand Down Expand Up @@ -237,6 +252,7 @@ class CreateChatCompletionRequest with _$CreateChatCompletionRequest {
'presence_penalty': presencePenalty,
'response_format': responseFormat,
'seed': seed,
'service_tier': serviceTier,
'stop': stop,
'stream': stream,
'stream_options': streamOptions,
Expand Down Expand Up @@ -398,6 +414,24 @@ class ChatCompletionResponseFormat with _$ChatCompletionResponseFormat {
}
}

// ==========================================
// ENUM: CreateChatCompletionRequestServiceTier
// ==========================================

/// Specifies the latency tier to use for processing the request. This parameter is relevant for customers
/// subscribed to the scale tier service:
/// - If set to 'auto', the system will utilize scale tier credits until they are exhausted.
/// - If set to 'default', the request will be processed using the default service tier with a lower
/// uptime SLA and no latency guarantee.
///
/// When this parameter is set, the response body will include the `service_tier` utilized.
enum CreateChatCompletionRequestServiceTier {
@JsonValue('auto')
auto,
@JsonValue('default')
vDefault,
}

// ==========================================
// CLASS: ChatCompletionStop
// ==========================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ class CreateChatCompletionResponse with _$CreateChatCompletionResponse {
/// The model used for the chat completion.
required String model,

/// The service tier used for processing the request. This field is only included if the `service_tier` parameter
/// is specified in the request.
@JsonKey(
name: 'service_tier',
includeIfNull: false,
unknownEnumValue: JsonKey.nullForUndefinedEnumValue,
)
ServiceTier? serviceTier,

/// This fingerprint represents the backend configuration that the model runs with.
///
/// Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism.
Expand All @@ -50,6 +59,7 @@ class CreateChatCompletionResponse with _$CreateChatCompletionResponse {
'choices',
'created',
'model',
'service_tier',
'system_fingerprint',
'object',
'usage'
Expand All @@ -67,6 +77,7 @@ class CreateChatCompletionResponse with _$CreateChatCompletionResponse {
'choices': choices,
'created': created,
'model': model,
'service_tier': serviceTier,
'system_fingerprint': systemFingerprint,
'object': object,
'usage': usage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ class CreateChatCompletionStreamResponse
/// The model to generate the completion.
@JsonKey(includeIfNull: false) String? model,

/// The service tier used for processing the request. This field is only included if the `service_tier` parameter
/// is specified in the request.
@JsonKey(
name: 'service_tier',
includeIfNull: false,
unknownEnumValue: JsonKey.nullForUndefinedEnumValue,
)
ServiceTier? serviceTier,

/// This fingerprint represents the backend configuration that the model runs with.
///
/// Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact
Expand All @@ -53,6 +62,7 @@ class CreateChatCompletionStreamResponse
'choices',
'created',
'model',
'service_tier',
'system_fingerprint',
'object',
'usage'
Expand All @@ -70,6 +80,7 @@ class CreateChatCompletionStreamResponse
'choices': choices,
'created': created,
'model': model,
'service_tier': serviceTier,
'system_fingerprint': systemFingerprint,
'object': object,
'usage': usage,
Expand Down
1 change: 1 addition & 0 deletions packages/openai_dart/lib/src/generated/schema/schema.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ part 'chat_completion_stream_options.dart';
part 'create_chat_completion_response.dart';
part 'chat_completion_response_choice.dart';
part 'chat_completion_finish_reason.dart';
part 'service_tier.dart';
part 'chat_completion_logprobs.dart';
part 'chat_completion_token_logprob.dart';
part 'chat_completion_token_top_logprob.dart';
Expand Down
Loading

0 comments on commit 0838e4b

Please sign in to comment.