Skip to content

Commit

Permalink
feat: Add log probabilities for refusal tokens in openai_dart (#534)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmigloz committed Aug 21, 2024
1 parent f4c4ed9 commit 8470a24
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ class ChatCompletionLogprobs with _$ChatCompletionLogprobs {
const factory ChatCompletionLogprobs({
/// A list of message content tokens with log probability information.
@JsonKey(includeIfNull: false) List<ChatCompletionTokenLogprob>? content,

/// A list of message refusal tokens with log probability information.
@JsonKey(includeIfNull: false) List<ChatCompletionTokenLogprob>? refusal,
}) = _ChatCompletionLogprobs;

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

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

/// Perform validations on the schema property values
String? validateSchema() {
Expand All @@ -35,6 +38,7 @@ class ChatCompletionLogprobs with _$ChatCompletionLogprobs {
Map<String, dynamic> toMap() {
return {
'content': content,
'refusal': refusal,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class ChatCompletionStreamResponseChoiceLogprobs
const factory ChatCompletionStreamResponseChoiceLogprobs({
/// A list of message content tokens with log probability information.
@JsonKey(includeIfNull: false) List<ChatCompletionTokenLogprob>? content,

/// A list of message refusal tokens with log probability information.
@JsonKey(includeIfNull: false) List<ChatCompletionTokenLogprob>? refusal,
}) = _ChatCompletionStreamResponseChoiceLogprobs;

/// Object construction from a JSON representation
Expand All @@ -88,7 +91,7 @@ class ChatCompletionStreamResponseChoiceLogprobs
_$ChatCompletionStreamResponseChoiceLogprobsFromJson(json);

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

/// Perform validations on the schema property values
String? validateSchema() {
Expand All @@ -99,6 +102,7 @@ class ChatCompletionStreamResponseChoiceLogprobs
Map<String, dynamic> toMap() {
return {
'content': content,
'refusal': refusal,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class FunctionObject with _$FunctionObject {
/// Whether to enable strict schema adherence when generating the function call. If set to true, the model will
/// follow the exact schema defined in the `parameters` field. Only a subset of JSON Schema is supported when
/// `strict` is `true`. Learn more about Structured Outputs in the
/// [function calling guide](docs/guides/function-calling).
/// [function calling guide](](https://platform.openai.com/docs/guides/function-calling).
@JsonKey(includeIfNull: false) @Default(false) bool? strict,
}) = _FunctionObject;

Expand Down
134 changes: 111 additions & 23 deletions packages/openai_dart/lib/src/generated/schema/schema.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6928,7 +6928,7 @@ mixin _$FunctionObject {
/// Whether to enable strict schema adherence when generating the function call. If set to true, the model will
/// follow the exact schema defined in the `parameters` field. Only a subset of JSON Schema is supported when
/// `strict` is `true`. Learn more about Structured Outputs in the
/// [function calling guide](docs/guides/function-calling).
/// [function calling guide](](https://platform.openai.com/docs/guides/function-calling).
@JsonKey(includeIfNull: false)
bool? get strict => throw _privateConstructorUsedError;

Expand Down Expand Up @@ -7095,7 +7095,7 @@ class _$FunctionObjectImpl extends _FunctionObject {
/// Whether to enable strict schema adherence when generating the function call. If set to true, the model will
/// follow the exact schema defined in the `parameters` field. Only a subset of JSON Schema is supported when
/// `strict` is `true`. Learn more about Structured Outputs in the
/// [function calling guide](docs/guides/function-calling).
/// [function calling guide](](https://platform.openai.com/docs/guides/function-calling).
@override
@JsonKey(includeIfNull: false)
final bool? strict;
Expand Down Expand Up @@ -7172,7 +7172,7 @@ abstract class _FunctionObject extends FunctionObject {
/// Whether to enable strict schema adherence when generating the function call. If set to true, the model will
/// follow the exact schema defined in the `parameters` field. Only a subset of JSON Schema is supported when
/// `strict` is `true`. Learn more about Structured Outputs in the
/// [function calling guide](docs/guides/function-calling).
/// [function calling guide](](https://platform.openai.com/docs/guides/function-calling).
@override
@JsonKey(includeIfNull: false)
bool? get strict;
Expand Down Expand Up @@ -9041,6 +9041,11 @@ mixin _$ChatCompletionLogprobs {
List<ChatCompletionTokenLogprob>? get content =>
throw _privateConstructorUsedError;

/// A list of message refusal tokens with log probability information.
@JsonKey(includeIfNull: false)
List<ChatCompletionTokenLogprob>? get refusal =>
throw _privateConstructorUsedError;

/// Serializes this ChatCompletionLogprobs to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;

Expand All @@ -9058,8 +9063,9 @@ abstract class $ChatCompletionLogprobsCopyWith<$Res> {
_$ChatCompletionLogprobsCopyWithImpl<$Res, ChatCompletionLogprobs>;
@useResult
$Res call(
{@JsonKey(includeIfNull: false)
List<ChatCompletionTokenLogprob>? content});
{@JsonKey(includeIfNull: false) List<ChatCompletionTokenLogprob>? content,
@JsonKey(includeIfNull: false)
List<ChatCompletionTokenLogprob>? refusal});
}

/// @nodoc
Expand All @@ -9079,12 +9085,17 @@ class _$ChatCompletionLogprobsCopyWithImpl<$Res,
@override
$Res call({
Object? content = freezed,
Object? refusal = freezed,
}) {
return _then(_value.copyWith(
content: freezed == content
? _value.content
: content // ignore: cast_nullable_to_non_nullable
as List<ChatCompletionTokenLogprob>?,
refusal: freezed == refusal
? _value.refusal
: refusal // ignore: cast_nullable_to_non_nullable
as List<ChatCompletionTokenLogprob>?,
) as $Val);
}
}
Expand All @@ -9099,8 +9110,9 @@ abstract class _$$ChatCompletionLogprobsImplCopyWith<$Res>
@override
@useResult
$Res call(
{@JsonKey(includeIfNull: false)
List<ChatCompletionTokenLogprob>? content});
{@JsonKey(includeIfNull: false) List<ChatCompletionTokenLogprob>? content,
@JsonKey(includeIfNull: false)
List<ChatCompletionTokenLogprob>? refusal});
}

/// @nodoc
Expand All @@ -9119,12 +9131,17 @@ class __$$ChatCompletionLogprobsImplCopyWithImpl<$Res>
@override
$Res call({
Object? content = freezed,
Object? refusal = freezed,
}) {
return _then(_$ChatCompletionLogprobsImpl(
content: freezed == content
? _value._content
: content // ignore: cast_nullable_to_non_nullable
as List<ChatCompletionTokenLogprob>?,
refusal: freezed == refusal
? _value._refusal
: refusal // ignore: cast_nullable_to_non_nullable
as List<ChatCompletionTokenLogprob>?,
));
}
}
Expand All @@ -9134,8 +9151,11 @@ class __$$ChatCompletionLogprobsImplCopyWithImpl<$Res>
class _$ChatCompletionLogprobsImpl extends _ChatCompletionLogprobs {
const _$ChatCompletionLogprobsImpl(
{@JsonKey(includeIfNull: false)
final List<ChatCompletionTokenLogprob>? content})
final List<ChatCompletionTokenLogprob>? content,
@JsonKey(includeIfNull: false)
final List<ChatCompletionTokenLogprob>? refusal})
: _content = content,
_refusal = refusal,
super._();

factory _$ChatCompletionLogprobsImpl.fromJson(Map<String, dynamic> json) =>
Expand All @@ -9155,23 +9175,40 @@ class _$ChatCompletionLogprobsImpl extends _ChatCompletionLogprobs {
return EqualUnmodifiableListView(value);
}

/// A list of message refusal tokens with log probability information.
final List<ChatCompletionTokenLogprob>? _refusal;

/// A list of message refusal tokens with log probability information.
@override
@JsonKey(includeIfNull: false)
List<ChatCompletionTokenLogprob>? get refusal {
final value = _refusal;
if (value == null) return null;
if (_refusal is EqualUnmodifiableListView) return _refusal;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(value);
}

@override
String toString() {
return 'ChatCompletionLogprobs(content: $content)';
return 'ChatCompletionLogprobs(content: $content, refusal: $refusal)';
}

@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ChatCompletionLogprobsImpl &&
const DeepCollectionEquality().equals(other._content, _content));
const DeepCollectionEquality().equals(other._content, _content) &&
const DeepCollectionEquality().equals(other._refusal, _refusal));
}

@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode =>
Object.hash(runtimeType, const DeepCollectionEquality().hash(_content));
int get hashCode => Object.hash(
runtimeType,
const DeepCollectionEquality().hash(_content),
const DeepCollectionEquality().hash(_refusal));

/// Create a copy of ChatCompletionLogprobs
/// with the given fields replaced by the non-null parameter values.
Expand All @@ -9193,7 +9230,9 @@ class _$ChatCompletionLogprobsImpl extends _ChatCompletionLogprobs {
abstract class _ChatCompletionLogprobs extends ChatCompletionLogprobs {
const factory _ChatCompletionLogprobs(
{@JsonKey(includeIfNull: false)
final List<ChatCompletionTokenLogprob>? content}) =
final List<ChatCompletionTokenLogprob>? content,
@JsonKey(includeIfNull: false)
final List<ChatCompletionTokenLogprob>? refusal}) =
_$ChatCompletionLogprobsImpl;
const _ChatCompletionLogprobs._() : super._();

Expand All @@ -9205,6 +9244,11 @@ abstract class _ChatCompletionLogprobs extends ChatCompletionLogprobs {
@JsonKey(includeIfNull: false)
List<ChatCompletionTokenLogprob>? get content;

/// A list of message refusal tokens with log probability information.
@override
@JsonKey(includeIfNull: false)
List<ChatCompletionTokenLogprob>? get refusal;

/// Create a copy of ChatCompletionLogprobs
/// with the given fields replaced by the non-null parameter values.
@override
Expand Down Expand Up @@ -10520,6 +10564,11 @@ mixin _$ChatCompletionStreamResponseChoiceLogprobs {
List<ChatCompletionTokenLogprob>? get content =>
throw _privateConstructorUsedError;

/// A list of message refusal tokens with log probability information.
@JsonKey(includeIfNull: false)
List<ChatCompletionTokenLogprob>? get refusal =>
throw _privateConstructorUsedError;

/// Serializes this ChatCompletionStreamResponseChoiceLogprobs to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;

Expand All @@ -10540,8 +10589,9 @@ abstract class $ChatCompletionStreamResponseChoiceLogprobsCopyWith<$Res> {
ChatCompletionStreamResponseChoiceLogprobs>;
@useResult
$Res call(
{@JsonKey(includeIfNull: false)
List<ChatCompletionTokenLogprob>? content});
{@JsonKey(includeIfNull: false) List<ChatCompletionTokenLogprob>? content,
@JsonKey(includeIfNull: false)
List<ChatCompletionTokenLogprob>? refusal});
}

/// @nodoc
Expand All @@ -10562,12 +10612,17 @@ class _$ChatCompletionStreamResponseChoiceLogprobsCopyWithImpl<$Res,
@override
$Res call({
Object? content = freezed,
Object? refusal = freezed,
}) {
return _then(_value.copyWith(
content: freezed == content
? _value.content
: content // ignore: cast_nullable_to_non_nullable
as List<ChatCompletionTokenLogprob>?,
refusal: freezed == refusal
? _value.refusal
: refusal // ignore: cast_nullable_to_non_nullable
as List<ChatCompletionTokenLogprob>?,
) as $Val);
}
}
Expand All @@ -10583,8 +10638,9 @@ abstract class _$$ChatCompletionStreamResponseChoiceLogprobsImplCopyWith<$Res>
@override
@useResult
$Res call(
{@JsonKey(includeIfNull: false)
List<ChatCompletionTokenLogprob>? content});
{@JsonKey(includeIfNull: false) List<ChatCompletionTokenLogprob>? content,
@JsonKey(includeIfNull: false)
List<ChatCompletionTokenLogprob>? refusal});
}

/// @nodoc
Expand All @@ -10603,12 +10659,17 @@ class __$$ChatCompletionStreamResponseChoiceLogprobsImplCopyWithImpl<$Res>
@override
$Res call({
Object? content = freezed,
Object? refusal = freezed,
}) {
return _then(_$ChatCompletionStreamResponseChoiceLogprobsImpl(
content: freezed == content
? _value._content
: content // ignore: cast_nullable_to_non_nullable
as List<ChatCompletionTokenLogprob>?,
refusal: freezed == refusal
? _value._refusal
: refusal // ignore: cast_nullable_to_non_nullable
as List<ChatCompletionTokenLogprob>?,
));
}
}
Expand All @@ -10619,8 +10680,11 @@ class _$ChatCompletionStreamResponseChoiceLogprobsImpl
extends _ChatCompletionStreamResponseChoiceLogprobs {
const _$ChatCompletionStreamResponseChoiceLogprobsImpl(
{@JsonKey(includeIfNull: false)
final List<ChatCompletionTokenLogprob>? content})
final List<ChatCompletionTokenLogprob>? content,
@JsonKey(includeIfNull: false)
final List<ChatCompletionTokenLogprob>? refusal})
: _content = content,
_refusal = refusal,
super._();

factory _$ChatCompletionStreamResponseChoiceLogprobsImpl.fromJson(
Expand All @@ -10641,23 +10705,40 @@ class _$ChatCompletionStreamResponseChoiceLogprobsImpl
return EqualUnmodifiableListView(value);
}

/// A list of message refusal tokens with log probability information.
final List<ChatCompletionTokenLogprob>? _refusal;

/// A list of message refusal tokens with log probability information.
@override
@JsonKey(includeIfNull: false)
List<ChatCompletionTokenLogprob>? get refusal {
final value = _refusal;
if (value == null) return null;
if (_refusal is EqualUnmodifiableListView) return _refusal;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(value);
}

@override
String toString() {
return 'ChatCompletionStreamResponseChoiceLogprobs(content: $content)';
return 'ChatCompletionStreamResponseChoiceLogprobs(content: $content, refusal: $refusal)';
}

@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ChatCompletionStreamResponseChoiceLogprobsImpl &&
const DeepCollectionEquality().equals(other._content, _content));
const DeepCollectionEquality().equals(other._content, _content) &&
const DeepCollectionEquality().equals(other._refusal, _refusal));
}

@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode =>
Object.hash(runtimeType, const DeepCollectionEquality().hash(_content));
int get hashCode => Object.hash(
runtimeType,
const DeepCollectionEquality().hash(_content),
const DeepCollectionEquality().hash(_refusal));

/// Create a copy of ChatCompletionStreamResponseChoiceLogprobs
/// with the given fields replaced by the non-null parameter values.
Expand All @@ -10683,7 +10764,9 @@ abstract class _ChatCompletionStreamResponseChoiceLogprobs
extends ChatCompletionStreamResponseChoiceLogprobs {
const factory _ChatCompletionStreamResponseChoiceLogprobs(
{@JsonKey(includeIfNull: false)
final List<ChatCompletionTokenLogprob>? content}) =
final List<ChatCompletionTokenLogprob>? content,
@JsonKey(includeIfNull: false)
final List<ChatCompletionTokenLogprob>? refusal}) =
_$ChatCompletionStreamResponseChoiceLogprobsImpl;
const _ChatCompletionStreamResponseChoiceLogprobs._() : super._();

Expand All @@ -10696,6 +10779,11 @@ abstract class _ChatCompletionStreamResponseChoiceLogprobs
@JsonKey(includeIfNull: false)
List<ChatCompletionTokenLogprob>? get content;

/// A list of message refusal tokens with log probability information.
@override
@JsonKey(includeIfNull: false)
List<ChatCompletionTokenLogprob>? get refusal;

/// Create a copy of ChatCompletionStreamResponseChoiceLogprobs
/// with the given fields replaced by the non-null parameter values.
@override
Expand Down
Loading

0 comments on commit 8470a24

Please sign in to comment.