Skip to content

Commit

Permalink
fix(openai_dart): Handle nullable function call fields when streaming (
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmigloz committed Nov 6, 2023
1 parent cd71963 commit 8f23cf1
Show file tree
Hide file tree
Showing 6 changed files with 293 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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: ChatCompletionStreamMessageFunctionCall
// ==========================================

/// The name and arguments of a function that should be called, as generated by the model.
@freezed
class ChatCompletionStreamMessageFunctionCall
with _$ChatCompletionStreamMessageFunctionCall {
const ChatCompletionStreamMessageFunctionCall._();

/// Factory constructor for ChatCompletionStreamMessageFunctionCall
const factory ChatCompletionStreamMessageFunctionCall({
/// The name of the function to call.
@JsonKey(includeIfNull: false) String? name,

/// The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function.
@JsonKey(includeIfNull: false) String? arguments,
}) = _ChatCompletionStreamMessageFunctionCall;

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

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

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

/// Map representation of object (not serialized)
Map<String, dynamic> toMap() {
return {
'name': name,
'arguments': arguments,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ChatCompletionStreamResponseDelta

/// The name and arguments of a function that should be called, as generated by the model.
@JsonKey(name: 'function_call', includeIfNull: false)
ChatCompletionMessageFunctionCall? functionCall,
ChatCompletionStreamMessageFunctionCall? functionCall,

/// The role of the messages author. One of `system`, `user`, `assistant`, or `function`.
@JsonKey(
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 @@ -28,6 +28,7 @@ part 'chat_completion_finish_reason.dart';
part 'create_chat_completion_stream_response.dart';
part 'chat_completion_stream_response_choice.dart';
part 'chat_completion_stream_response_delta.dart';
part 'chat_completion_stream_message_function_call.dart';
part 'completion_usage.dart';
part 'create_embedding_request.dart';
part 'create_embedding_response.dart';
Expand Down
222 changes: 210 additions & 12 deletions packages/openai_dart/lib/src/generated/schema/schema.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7229,7 +7229,7 @@ mixin _$ChatCompletionStreamResponseDelta {

/// The name and arguments of a function that should be called, as generated by the model.
@JsonKey(name: 'function_call', includeIfNull: false)
ChatCompletionMessageFunctionCall? get functionCall =>
ChatCompletionStreamMessageFunctionCall? get functionCall =>
throw _privateConstructorUsedError;

/// The role of the messages author. One of `system`, `user`, `assistant`, or `function`.
Expand All @@ -7254,13 +7254,13 @@ abstract class $ChatCompletionStreamResponseDeltaCopyWith<$Res> {
$Res call(
{@JsonKey(includeIfNull: false) String? content,
@JsonKey(name: 'function_call', includeIfNull: false)
ChatCompletionMessageFunctionCall? functionCall,
ChatCompletionStreamMessageFunctionCall? functionCall,
@JsonKey(
includeIfNull: false,
unknownEnumValue: JsonKey.nullForUndefinedEnumValue)
ChatCompletionMessageRole? role});

$ChatCompletionMessageFunctionCallCopyWith<$Res>? get functionCall;
$ChatCompletionStreamMessageFunctionCallCopyWith<$Res>? get functionCall;
}

/// @nodoc
Expand Down Expand Up @@ -7289,7 +7289,7 @@ class _$ChatCompletionStreamResponseDeltaCopyWithImpl<$Res,
functionCall: freezed == functionCall
? _value.functionCall
: functionCall // ignore: cast_nullable_to_non_nullable
as ChatCompletionMessageFunctionCall?,
as ChatCompletionStreamMessageFunctionCall?,
role: freezed == role
? _value.role
: role // ignore: cast_nullable_to_non_nullable
Expand All @@ -7299,12 +7299,12 @@ class _$ChatCompletionStreamResponseDeltaCopyWithImpl<$Res,

@override
@pragma('vm:prefer-inline')
$ChatCompletionMessageFunctionCallCopyWith<$Res>? get functionCall {
$ChatCompletionStreamMessageFunctionCallCopyWith<$Res>? get functionCall {
if (_value.functionCall == null) {
return null;
}

return $ChatCompletionMessageFunctionCallCopyWith<$Res>(
return $ChatCompletionStreamMessageFunctionCallCopyWith<$Res>(
_value.functionCall!, (value) {
return _then(_value.copyWith(functionCall: value) as $Val);
});
Expand All @@ -7323,14 +7323,14 @@ abstract class _$$ChatCompletionStreamResponseDeltaImplCopyWith<$Res>
$Res call(
{@JsonKey(includeIfNull: false) String? content,
@JsonKey(name: 'function_call', includeIfNull: false)
ChatCompletionMessageFunctionCall? functionCall,
ChatCompletionStreamMessageFunctionCall? functionCall,
@JsonKey(
includeIfNull: false,
unknownEnumValue: JsonKey.nullForUndefinedEnumValue)
ChatCompletionMessageRole? role});

@override
$ChatCompletionMessageFunctionCallCopyWith<$Res>? get functionCall;
$ChatCompletionStreamMessageFunctionCallCopyWith<$Res>? get functionCall;
}

/// @nodoc
Expand Down Expand Up @@ -7358,7 +7358,7 @@ class __$$ChatCompletionStreamResponseDeltaImplCopyWithImpl<$Res>
functionCall: freezed == functionCall
? _value.functionCall
: functionCall // ignore: cast_nullable_to_non_nullable
as ChatCompletionMessageFunctionCall?,
as ChatCompletionStreamMessageFunctionCall?,
role: freezed == role
? _value.role
: role // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -7392,7 +7392,7 @@ class _$ChatCompletionStreamResponseDeltaImpl
/// The name and arguments of a function that should be called, as generated by the model.
@override
@JsonKey(name: 'function_call', includeIfNull: false)
final ChatCompletionMessageFunctionCall? functionCall;
final ChatCompletionStreamMessageFunctionCall? functionCall;

/// The role of the messages author. One of `system`, `user`, `assistant`, or `function`.
@override
Expand Down Expand Up @@ -7441,7 +7441,7 @@ abstract class _ChatCompletionStreamResponseDelta
const factory _ChatCompletionStreamResponseDelta(
{@JsonKey(includeIfNull: false) final String? content,
@JsonKey(name: 'function_call', includeIfNull: false)
final ChatCompletionMessageFunctionCall? functionCall,
final ChatCompletionStreamMessageFunctionCall? functionCall,
@JsonKey(
includeIfNull: false,
unknownEnumValue: JsonKey.nullForUndefinedEnumValue)
Expand All @@ -7462,7 +7462,7 @@ abstract class _ChatCompletionStreamResponseDelta

/// The name and arguments of a function that should be called, as generated by the model.
@JsonKey(name: 'function_call', includeIfNull: false)
ChatCompletionMessageFunctionCall? get functionCall;
ChatCompletionStreamMessageFunctionCall? get functionCall;
@override

/// The role of the messages author. One of `system`, `user`, `assistant`, or `function`.
Expand All @@ -7476,6 +7476,204 @@ abstract class _ChatCompletionStreamResponseDelta
get copyWith => throw _privateConstructorUsedError;
}

ChatCompletionStreamMessageFunctionCall
_$ChatCompletionStreamMessageFunctionCallFromJson(
Map<String, dynamic> json) {
return _ChatCompletionStreamMessageFunctionCall.fromJson(json);
}

/// @nodoc
mixin _$ChatCompletionStreamMessageFunctionCall {
/// The name of the function to call.
@JsonKey(includeIfNull: false)
String? get name => throw _privateConstructorUsedError;

/// The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function.
@JsonKey(includeIfNull: false)
String? get arguments => throw _privateConstructorUsedError;

Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$ChatCompletionStreamMessageFunctionCallCopyWith<
ChatCompletionStreamMessageFunctionCall>
get copyWith => throw _privateConstructorUsedError;
}

/// @nodoc
abstract class $ChatCompletionStreamMessageFunctionCallCopyWith<$Res> {
factory $ChatCompletionStreamMessageFunctionCallCopyWith(
ChatCompletionStreamMessageFunctionCall value,
$Res Function(ChatCompletionStreamMessageFunctionCall) then) =
_$ChatCompletionStreamMessageFunctionCallCopyWithImpl<$Res,
ChatCompletionStreamMessageFunctionCall>;
@useResult
$Res call(
{@JsonKey(includeIfNull: false) String? name,
@JsonKey(includeIfNull: false) String? arguments});
}

/// @nodoc
class _$ChatCompletionStreamMessageFunctionCallCopyWithImpl<$Res,
$Val extends ChatCompletionStreamMessageFunctionCall>
implements $ChatCompletionStreamMessageFunctionCallCopyWith<$Res> {
_$ChatCompletionStreamMessageFunctionCallCopyWithImpl(
this._value, this._then);

// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;

@pragma('vm:prefer-inline')
@override
$Res call({
Object? name = freezed,
Object? arguments = freezed,
}) {
return _then(_value.copyWith(
name: freezed == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String?,
arguments: freezed == arguments
? _value.arguments
: arguments // ignore: cast_nullable_to_non_nullable
as String?,
) as $Val);
}
}

/// @nodoc
abstract class _$$ChatCompletionStreamMessageFunctionCallImplCopyWith<$Res>
implements $ChatCompletionStreamMessageFunctionCallCopyWith<$Res> {
factory _$$ChatCompletionStreamMessageFunctionCallImplCopyWith(
_$ChatCompletionStreamMessageFunctionCallImpl value,
$Res Function(_$ChatCompletionStreamMessageFunctionCallImpl) then) =
__$$ChatCompletionStreamMessageFunctionCallImplCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{@JsonKey(includeIfNull: false) String? name,
@JsonKey(includeIfNull: false) String? arguments});
}

/// @nodoc
class __$$ChatCompletionStreamMessageFunctionCallImplCopyWithImpl<$Res>
extends _$ChatCompletionStreamMessageFunctionCallCopyWithImpl<$Res,
_$ChatCompletionStreamMessageFunctionCallImpl>
implements _$$ChatCompletionStreamMessageFunctionCallImplCopyWith<$Res> {
__$$ChatCompletionStreamMessageFunctionCallImplCopyWithImpl(
_$ChatCompletionStreamMessageFunctionCallImpl _value,
$Res Function(_$ChatCompletionStreamMessageFunctionCallImpl) _then)
: super(_value, _then);

@pragma('vm:prefer-inline')
@override
$Res call({
Object? name = freezed,
Object? arguments = freezed,
}) {
return _then(_$ChatCompletionStreamMessageFunctionCallImpl(
name: freezed == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String?,
arguments: freezed == arguments
? _value.arguments
: arguments // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}

/// @nodoc
@JsonSerializable()
class _$ChatCompletionStreamMessageFunctionCallImpl
extends _ChatCompletionStreamMessageFunctionCall {
const _$ChatCompletionStreamMessageFunctionCallImpl(
{@JsonKey(includeIfNull: false) this.name,
@JsonKey(includeIfNull: false) this.arguments})
: super._();

factory _$ChatCompletionStreamMessageFunctionCallImpl.fromJson(
Map<String, dynamic> json) =>
_$$ChatCompletionStreamMessageFunctionCallImplFromJson(json);

/// The name of the function to call.
@override
@JsonKey(includeIfNull: false)
final String? name;

/// The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function.
@override
@JsonKey(includeIfNull: false)
final String? arguments;

@override
String toString() {
return 'ChatCompletionStreamMessageFunctionCall(name: $name, arguments: $arguments)';
}

@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ChatCompletionStreamMessageFunctionCallImpl &&
(identical(other.name, name) || other.name == name) &&
(identical(other.arguments, arguments) ||
other.arguments == arguments));
}

@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(runtimeType, name, arguments);

@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$ChatCompletionStreamMessageFunctionCallImplCopyWith<
_$ChatCompletionStreamMessageFunctionCallImpl>
get copyWith =>
__$$ChatCompletionStreamMessageFunctionCallImplCopyWithImpl<
_$ChatCompletionStreamMessageFunctionCallImpl>(this, _$identity);

@override
Map<String, dynamic> toJson() {
return _$$ChatCompletionStreamMessageFunctionCallImplToJson(
this,
);
}
}

abstract class _ChatCompletionStreamMessageFunctionCall
extends ChatCompletionStreamMessageFunctionCall {
const factory _ChatCompletionStreamMessageFunctionCall(
{@JsonKey(includeIfNull: false) final String? name,
@JsonKey(includeIfNull: false) final String? arguments}) =
_$ChatCompletionStreamMessageFunctionCallImpl;
const _ChatCompletionStreamMessageFunctionCall._() : super._();

factory _ChatCompletionStreamMessageFunctionCall.fromJson(
Map<String, dynamic> json) =
_$ChatCompletionStreamMessageFunctionCallImpl.fromJson;

@override

/// The name of the function to call.
@JsonKey(includeIfNull: false)
String? get name;
@override

/// The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function.
@JsonKey(includeIfNull: false)
String? get arguments;
@override
@JsonKey(ignore: true)
_$$ChatCompletionStreamMessageFunctionCallImplCopyWith<
_$ChatCompletionStreamMessageFunctionCallImpl>
get copyWith => throw _privateConstructorUsedError;
}

CompletionUsage _$CompletionUsageFromJson(Map<String, dynamic> json) {
return _CompletionUsage.fromJson(json);
}
Expand Down

0 comments on commit 8f23cf1

Please sign in to comment.