toChatResponseUpdates method

List<ChatResponseUpdate> toChatResponseUpdates()

Converts this response into a list of ChatResponseUpdates.

Implementation

List<ChatResponseUpdate> toChatResponseUpdates() {
  final updates = <ChatResponseUpdate>[];

  for (final message in messages) {
    updates.add(
      ChatResponseUpdate(
        role: message.role,
        authorName: message.authorName,
        contents: message.contents,
        responseId: responseId,
        conversationId: conversationId,
        modelId: modelId,
        createdAt: createdAt,
        additionalProperties: additionalProperties,
      ),
    );
  }

  if (updates.isNotEmpty) {
    updates.last.finishReason = finishReason;
  }

  return updates;
}