Skip to content

Commit

Permalink
feat: Add five new voice types in openai_realtime_dart and minor impr…
Browse files Browse the repository at this point in the history
…ovements (#593)
  • Loading branch information
davidmigloz authored Oct 31, 2024
1 parent 7e9e139 commit 6d0c8d3
Show file tree
Hide file tree
Showing 18 changed files with 5,074 additions and 4,178 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class InputAudioTranscriptionConfig with _$InputAudioTranscriptionConfig {
/// Whether input audio transcription is enabled.
@JsonKey(includeIfNull: false) bool? enabled,

/// The model used for transcription.
/// The model to use for transcription, `whisper-1` is the only currently
/// supported model.
@JsonKey(includeIfNull: false) String? model,
}) = _InputAudioTranscriptionConfig;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ sealed class Item with _$Item {
@FreezedUnionValue('message')
const factory Item.message({
/// The unique ID of the item.
/// The unique ID of the item, this can be generated by the client to help manage server-side context,
/// but is not required because the server will generate one if not provided.
required String id,

/// The object type, must be "realtime.item".
Expand All @@ -34,7 +35,8 @@ sealed class Item with _$Item {
/// The type of the item.
@Default(ItemType.message) ItemType type,

/// The status of the item.
/// The status of the item. These have no effect on the conversation, but are accepted for consistency
/// with the `conversation.item.created` event.
@JsonKey(
includeIfNull: false,
unknownEnumValue: JsonKey.nullForUndefinedEnumValue,
Expand All @@ -44,7 +46,9 @@ sealed class Item with _$Item {
/// The role of the message sender.
required ItemRole role,

/// The content of the message.
/// The content of the message. Message items with a role of `system` support only `input_text` content,
/// message items of role `user` support `input_text` and `input_audio` content, and message items of role
/// `assistant` support `text` content.
required List<ContentPart> content,
}) = ItemMessage;

Expand All @@ -56,7 +60,8 @@ sealed class Item with _$Item {
@FreezedUnionValue('function_call')
const factory Item.functionCall({
/// The unique ID of the item.
/// The unique ID of the item, this can be generated by the client to help manage server-side context,
/// but is not required because the server will generate one if not provided.
required String id,

/// The object type.
Expand All @@ -65,14 +70,17 @@ sealed class Item with _$Item {
/// The type of the item.
@Default(ItemType.functionCall) ItemType type,

/// The status of the item.
/// The status of the item. These have no effect on the conversation, but are accepted for consistency
/// with the `conversation.item.created` event.
@JsonKey(
includeIfNull: false,
unknownEnumValue: JsonKey.nullForUndefinedEnumValue,
)
ItemStatus? status,

/// The ID of the function call.
/// The ID of the function call (for `function_call` and `function_call_output` items). If passed on a
/// `function_call_output` item, the server will check that a `function_call` item with the same ID
/// exists in the conversation history.
@JsonKey(name: 'call_id') required String callId,

/// The name of the function being called.
Expand All @@ -90,7 +98,8 @@ sealed class Item with _$Item {
@FreezedUnionValue('function_call_output')
const factory Item.functionCallOutput({
/// The unique ID of the item.
/// The unique ID of the item, this can be generated by the client to help manage server-side context,
/// but is not required because the server will generate one if not provided.
required String id,

/// The object type. Always "realtime.item".
Expand All @@ -103,7 +112,8 @@ sealed class Item with _$Item {
/// The type of the item.
@Default(ItemType.functionCallOutput) ItemType type,

/// The status of the item.
/// The status of the item. These have no effect on the conversation, but are accepted for consistency
/// with the `conversation.item.created` event.
@JsonKey(
includeIfNull: false,
unknownEnumValue: JsonKey.nullForUndefinedEnumValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RateLimit with _$RateLimit {

/// Factory constructor for RateLimit
const factory RateLimit({
/// The name of the rate limit.
/// The name of the rate limit (`requests`, `tokens`).
required RateLimitName name,

/// The maximum allowed value for the rate limit.
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ class Response with _$Response {
required ResponseStatus status,

/// Additional details about the status.
/// Any of: [ResponseStatusDetailsIncomplete], [ResponseStatusDetailsFailed]
/// Any of: [ResponseStatusDetailsCancelled], [ResponseStatusDetailsIncomplete], [ResponseStatusDetailsFailed]
@JsonKey(name: 'status_details', includeIfNull: false)
ResponseStatusDetails? statusDetails,

/// The list of output items generated by the response.
required List<Item> output,

/// Usage statistics for the response
/// Usage statistics for the Response, this will correspond to billing. A Realtime API session will
/// maintain a conversation context and append new Items to the Conversation, thus output from
/// previous turns (text and audio tokens) will become the input for later turns.
@JsonKey(includeIfNull: false) Usage? usage,
}) = _Response;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,28 @@ part of openai_realtime_schema;
sealed class ResponseStatusDetails with _$ResponseStatusDetails {
const ResponseStatusDetails._();

// ------------------------------------------
// UNION: ResponseStatusDetailsCancelled
// ------------------------------------------

/// Details about the cancelled response.
@FreezedUnionValue('cancelled')
const factory ResponseStatusDetails.cancelled({
/// The type of error that caused the response to fail.
@Default(ResponseStatusType.cancelled) ResponseStatusType type,

/// The reason the Response did not complete. For a `cancelled` Response, one of `turn_detected`
/// (the server VAD detected a new start of speech) or `client_cancelled` (the client sent a
/// cancel event). For an `incomplete` Response, one of `max_output_tokens` or `content_filter`
/// (the server-side safety filter activated and cut off the response).
@JsonKey(
includeIfNull: false,
unknownEnumValue: JsonKey.nullForUndefinedEnumValue,
)
ResponseStatusIncompleteReason? reason,
}) = ResponseStatusDetailsCancelled;

// ------------------------------------------
// UNION: ResponseStatusDetailsIncomplete
// ------------------------------------------
Expand All @@ -21,10 +43,13 @@ sealed class ResponseStatusDetails with _$ResponseStatusDetails {
@FreezedUnionValue('incomplete')
const factory ResponseStatusDetails.incomplete({
/// The type of the status.
/// The type of error that caused the response to fail.
@Default(ResponseStatusType.incomplete) ResponseStatusType type,

/// The reason the response is incomplete.
/// The reason the Response did not complete. For a `cancelled` Response, one of `turn_detected`
/// (the server VAD detected a new start of speech) or `client_cancelled` (the client sent a
/// cancel event). For an `incomplete` Response, one of `max_output_tokens` or `content_filter`
/// (the server-side safety filter activated and cut off the response).
@JsonKey(
includeIfNull: false,
unknownEnumValue: JsonKey.nullForUndefinedEnumValue,
Expand All @@ -40,7 +65,7 @@ sealed class ResponseStatusDetails with _$ResponseStatusDetails {
@FreezedUnionValue('failed')
const factory ResponseStatusDetails.failed({
/// The type of the status.
/// The type of error that caused the response to fail.
@Default(ResponseStatusType.failed) ResponseStatusType type,

/// Details of the API error.
Expand All @@ -57,6 +82,8 @@ sealed class ResponseStatusDetails with _$ResponseStatusDetails {
// ==========================================

enum ResponseStatusDetailsEnumType {
@JsonValue('cancelled')
cancelled,
@JsonValue('incomplete')
incomplete,
@JsonValue('failed')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ part of openai_realtime_schema;
// ENUM: ResponseStatusIncompleteReason
// ==========================================

/// The reason the response is incomplete.
/// The reason the Response did not complete. For a `cancelled` Response, one of `turn_detected`
/// (the server VAD detected a new start of speech) or `client_cancelled` (the client sent a
/// cancel event). For an `incomplete` Response, one of `max_output_tokens` or `content_filter`
/// (the server-side safety filter activated and cut off the response).
enum ResponseStatusIncompleteReason {
@JsonValue('turn_detected')
turnDetected,
@JsonValue('client_cancelled')
clientCancelled,
@JsonValue('interruption')
interruption,
@JsonValue('max_output_tokens')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ part of openai_realtime_schema;
// ENUM: ResponseStatusType
// ==========================================

/// The type of the status.
/// The type of error that caused the response to fail.
enum ResponseStatusType {
@JsonValue('cancelled')
cancelled,
@JsonValue('incomplete')
incomplete,
@JsonValue('failed')
Expand Down
Loading

0 comments on commit 6d0c8d3

Please sign in to comment.