Skip to content

Commit

Permalink
[ Add ] addeed missing name field in chat completion message object
Browse files Browse the repository at this point in the history
  • Loading branch information
anasfik committed Feb 21, 2024
1 parent 76fa736 commit 087b62b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions example/lib/chat_completion_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ void main() async {
// ),
],
role: OpenAIChatMessageRole.user,
name: "anas",
);

final requestMessages = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ final class OpenAIChatCompletionChoiceMessageModel {
/// The function that the model is requesting to call.
final List<OpenAIResponseToolCall>? toolCalls;

/// The message participent name.
final String? name;

/// Weither the message have tool calls.
bool get haveToolCalls => toolCalls != null;

Expand All @@ -35,13 +38,15 @@ final class OpenAIChatCompletionChoiceMessageModel {
required this.role,
required this.content,
this.toolCalls,
this.name,
});

/// This is used to convert a [Map<String, dynamic>] object to a [OpenAIChatCompletionChoiceMessageModel] object.
factory OpenAIChatCompletionChoiceMessageModel.fromMap(
Map<String, dynamic> json,
) {
return OpenAIChatCompletionChoiceMessageModel(
name: json['name'],
role: OpenAIChatMessageRole.values
.firstWhere((role) => role.name == json['role']),
content: json['content'] != null
Expand All @@ -64,6 +69,7 @@ final class OpenAIChatCompletionChoiceMessageModel {
"content": content?.map((contentItem) => contentItem.toMap()).toList(),
if (toolCalls != null && role == OpenAIChatMessageRole.assistant)
"tool_calls": toolCalls!.map((toolCall) => toolCall.toMap()).toList(),
if (name != null) "name": name,
};
}

Expand Down

0 comments on commit 087b62b

Please sign in to comment.