Skip to content

Commit

Permalink
feat(openai_dart): Support new chat completion API functionality (#198)
Browse files Browse the repository at this point in the history
- Added `gpt-4-1106-preview`

> GPT-4 Turbo is more capable and has knowledge of world events up to April 2023. It has a 128k context window so it can fit the equivalent of more than 300 pages of text in a single prompt. We also optimized its performance so we are able to offer GPT-4 Turbo at a 3x cheaper price for input tokens and a 2x cheaper price for output tokens compared to GPT-4.

- Support new function calling structure

> We’re releasing several improvements today, including the ability to call multiple functions in a single message: users can send one message requesting multiple actions, such as “open the car window and turn off the A/C”, which would previously require multiple roundtrips with the model (learn more). We are also improving function calling accuracy: GPT-4 Turbo is more likely to return the right function parameters.

- Support `response_format`

> GPT-4 Turbo performs better than our previous models on tasks that require the careful following of instructions, such as generating specific formats (e.g., “always respond in XML”). It also supports our new JSON mode, which ensures the model will respond with valid JSON. The new API parameter response_format enables the model to constrain its output to generate a syntactically correct JSON object. JSON mode is useful for developers generating JSON in the Chat Completions API outside of function calling.

- Support `seed`

> The new seed parameter enables reproducible outputs by making the model return consistent completions most of the time. This beta feature is useful for use cases such as replaying requests for debugging, writing more comprehensive unit tests, and generally having a higher degree of control over the model behavior. We at OpenAI have been using this feature internally for our own unit tests and have found it invaluable. We’re excited to see how developers will use it.
  • Loading branch information
davidmigloz committed Nov 7, 2023
1 parent bb87c19 commit 01820d6
Show file tree
Hide file tree
Showing 58 changed files with 11,576 additions and 4,258 deletions.
1 change: 0 additions & 1 deletion packages/openai_dart/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ targets:
json_serializable:
options:
explicit_to_json: true
include_if_null: false
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: invalid_annotation_target
// ignore_for_file: invalid_annotation_target, unused_import
part of open_a_i_schema;

// ==========================================
Expand All @@ -11,14 +11,16 @@ part of open_a_i_schema;
/// The reason the model stopped generating tokens. This will be `stop` if the model hit a natural stop point or a provided stop sequence,
/// `length` if the maximum number of tokens specified in the request was reached,
/// `content_filter` if content was omitted due to a flag from our content filters,
/// or `function_call` if the model called a function.
/// `tool_calls` if the model called a tool, or `function_call` (deprecated) if the model called a function.
enum ChatCompletionFinishReason {
@JsonValue('stop')
stop,
@JsonValue('length')
length,
@JsonValue('function_call')
functionCall,
@JsonValue('tool_calls')
toolCalls,
@JsonValue('content_filter')
contentFilter,
@JsonValue('function_call')
functionCall,
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: invalid_annotation_target
// ignore_for_file: invalid_annotation_target, unused_import
part of open_a_i_schema;

// ==========================================
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: invalid_annotation_target
// ignore_for_file: invalid_annotation_target, unused_import
part of open_a_i_schema;

// ==========================================
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: invalid_annotation_target
// ignore_for_file: invalid_annotation_target, unused_import
part of open_a_i_schema;

// ==========================================
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: invalid_annotation_target
// ignore_for_file: invalid_annotation_target, unused_import
part of open_a_i_schema;

// ==========================================
// CLASS: ChatCompletionMessage
// ==========================================

/// A message in a chat conversation.
/// A chat completion message generated by the model.
@freezed
class ChatCompletionMessage with _$ChatCompletionMessage {
const ChatCompletionMessage._();

/// Factory constructor for ChatCompletionMessage
const factory ChatCompletionMessage({
/// The role of the messages author. One of `system`, `user`, `assistant`, or `function`.
/// The role of the messages author. One of `system`, `user`, `assistant`, or `tool` (`function` is deprecated).
required ChatCompletionMessageRole role,

/// The contents of the message. `content` is required for all messages, and may be null for assistant messages with function calls.
required String? content,

/// The name and arguments of a function that should be called, as generated by the model.
/// No Description
@JsonKey(name: 'tool_calls', includeIfNull: false)
ChatCompletionMessageToolCalls? toolCalls,

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

/// Tool call that this message is responding to.
@JsonKey(name: 'tool_call_id', includeIfNull: false) String? toolCallId,

/// The name of the author of this message. `name` is required if role is `function`, and it should be the name of the function whose response is in the `content`. May contain a-z, A-Z, 0-9, and underscores, with a maximum length of 64 characters.
@JsonKey(includeIfNull: false) String? name,
}) = _ChatCompletionMessage;
Expand All @@ -37,7 +44,9 @@ class ChatCompletionMessage with _$ChatCompletionMessage {
static const List<String> propertyNames = [
'role',
'content',
'tool_calls',
'function_call',
'tool_call_id',
'name'
];

Expand All @@ -51,7 +60,9 @@ class ChatCompletionMessage with _$ChatCompletionMessage {
return {
'role': role,
'content': content,
'tool_calls': toolCalls,
'function_call': functionCall,
'tool_call_id': toolCallId,
'name': name,
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: invalid_annotation_target
// ignore_for_file: invalid_annotation_target, unused_import
part of open_a_i_schema;

// ==========================================
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: invalid_annotation_target
// ignore_for_file: invalid_annotation_target, unused_import
part of open_a_i_schema;

// ==========================================
// ENUM: ChatCompletionMessageRole
// ==========================================

/// The role of the messages author. One of `system`, `user`, `assistant`, or `function`.
/// The role of the messages author. One of `system`, `user`, `assistant`, or `tool` (`function` is deprecated).
enum ChatCompletionMessageRole {
@JsonValue('system')
system,
@JsonValue('user')
user,
@JsonValue('assistant')
assistant,
@JsonValue('tool')
tool,
@JsonValue('function')
function,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: invalid_annotation_target, unused_import
part of open_a_i_schema;

// ==========================================
// CLASS: ChatCompletionMessageToolCall
// ==========================================

/// A tool call generated by the model, such as a function call.
@freezed
class ChatCompletionMessageToolCall with _$ChatCompletionMessageToolCall {
const ChatCompletionMessageToolCall._();

/// Factory constructor for ChatCompletionMessageToolCall
const factory ChatCompletionMessageToolCall({
/// The ID of the tool call.
required String id,

/// The type of the tool. Currently, only `function` is supported.
required ChatCompletionMessageToolCallType type,

/// The name and arguments of a function that should be called, as generated by the model.
required ChatCompletionMessageFunctionCall function,
}) = _ChatCompletionMessageToolCall;

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

/// List of all property names of schema
static const List<String> propertyNames = ['id', 'type', 'function'];

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

/// Map representation of object (not serialized)
Map<String, dynamic> toMap() {
return {
'id': id,
'type': type,
'function': function,
};
}
}

// ==========================================
// ENUM: ChatCompletionMessageToolCallType
// ==========================================

/// The type of the tool. Currently, only `function` is supported.
enum ChatCompletionMessageToolCallType {
@JsonValue('function')
function,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: invalid_annotation_target, unused_import
part of open_a_i_schema;

// ==========================================
// TYPE: ChatCompletionMessageToolCalls
// ==========================================

/// The tool calls generated by the model, such as function calls.
typedef ChatCompletionMessageToolCalls = List<ChatCompletionMessageToolCall>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: invalid_annotation_target, unused_import
part of open_a_i_schema;

// ==========================================
// CLASS: ChatCompletionNamedToolChoice
// ==========================================

/// Specifies a tool the model should use. Use to force the model to call a specific function.
@freezed
class ChatCompletionNamedToolChoice with _$ChatCompletionNamedToolChoice {
const ChatCompletionNamedToolChoice._();

/// Factory constructor for ChatCompletionNamedToolChoice
const factory ChatCompletionNamedToolChoice({
/// The type of the tool. Currently, only `function` is supported.
@JsonKey(
includeIfNull: false,
unknownEnumValue: JsonKey.nullForUndefinedEnumValue,
)
ChatCompletionNamedToolChoiceType? type,

/// Forces the model to call the specified function.
@JsonKey(includeIfNull: false) ChatCompletionFunctionCallOption? function,
}) = _ChatCompletionNamedToolChoice;

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

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

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

/// Map representation of object (not serialized)
Map<String, dynamic> toMap() {
return {
'type': type,
'function': function,
};
}
}

// ==========================================
// ENUM: ChatCompletionNamedToolChoiceType
// ==========================================

/// The type of the tool. Currently, only `function` is supported.
enum ChatCompletionNamedToolChoiceType {
@JsonValue('function')
function,
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: invalid_annotation_target
// ignore_for_file: invalid_annotation_target, unused_import
part of open_a_i_schema;

// ==========================================
Expand All @@ -18,14 +18,14 @@ class ChatCompletionResponseChoice with _$ChatCompletionResponseChoice {
/// The reason the model stopped generating tokens. This will be `stop` if the model hit a natural stop point or a provided stop sequence,
/// `length` if the maximum number of tokens specified in the request was reached,
/// `content_filter` if content was omitted due to a flag from our content filters,
/// or `function_call` if the model called a function.
/// `tool_calls` if the model called a tool, or `function_call` (deprecated) if the model called a function.
@JsonKey(name: 'finish_reason')
required ChatCompletionFinishReason finishReason,

/// The index of the choice in the list of choices.
required int index,

/// A message in a chat conversation.
/// A chat completion message generated by the model.
required ChatCompletionMessage message,
}) = _ChatCompletionResponseChoice;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: invalid_annotation_target
// ignore_for_file: invalid_annotation_target, unused_import
part of open_a_i_schema;

// ==========================================
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: invalid_annotation_target, unused_import
part of open_a_i_schema;

// ==========================================
// CLASS: ChatCompletionStreamMessageToolCallChunk
// ==========================================

/// The tool that should be called, as generated by the model.
@freezed
class ChatCompletionStreamMessageToolCallChunk
with _$ChatCompletionStreamMessageToolCallChunk {
const ChatCompletionStreamMessageToolCallChunk._();

/// Factory constructor for ChatCompletionStreamMessageToolCallChunk
const factory ChatCompletionStreamMessageToolCallChunk({
/// No Description
required int index,

/// The ID of the tool call.
@JsonKey(includeIfNull: false) String? id,

/// The type of the tool. Currently, only `function` is supported.
@JsonKey(
includeIfNull: false,
unknownEnumValue: JsonKey.nullForUndefinedEnumValue,
)
ChatCompletionStreamMessageToolCallChunkType? type,

/// The name and arguments of a function that should be called, as generated by the model.
@JsonKey(includeIfNull: false)
ChatCompletionStreamMessageFunctionCall? function,
}) = _ChatCompletionStreamMessageToolCallChunk;

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

/// List of all property names of schema
static const List<String> propertyNames = ['index', 'id', 'type', 'function'];

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

/// Map representation of object (not serialized)
Map<String, dynamic> toMap() {
return {
'index': index,
'id': id,
'type': type,
'function': function,
};
}
}

// ==========================================
// ENUM: ChatCompletionStreamMessageToolCallChunkType
// ==========================================

/// The type of the tool. Currently, only `function` is supported.
enum ChatCompletionStreamMessageToolCallChunkType {
@JsonValue('function')
function,
}

0 comments on commit 01820d6

Please sign in to comment.