[ Add ] addeed missing name field in chat completion message object

This commit is contained in:
Anas Fikhi
2024-02-22 00:21:47 +01:00
parent 76fa736389
commit 087b62b897
2 changed files with 7 additions and 0 deletions

View File

@ -27,6 +27,7 @@ void main() async {
// ),
],
role: OpenAIChatMessageRole.user,
name: "anas",
);
final requestMessages = [

View File

@ -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;
@ -35,6 +38,7 @@ 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.
@ -42,6 +46,7 @@ final class OpenAIChatCompletionChoiceMessageModel {
Map<String, dynamic> json,
) {
return OpenAIChatCompletionChoiceMessageModel(
name: json['name'],
role: OpenAIChatMessageRole.values
.firstWhere((role) => role.name == json['role']),
content: json['content'] != null
@ -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,
};
}