copy method

List<LlamaMessage> copy()

Creates a copy of the list of LlamaMessage objects.

This method iterates over the current list of LlamaMessage instances, creates a new LlamaMessage for each one with the same role and content, and returns a new list containing these copied messages.

Returns: A new list of LlamaMessage objects with the same role and content as the original list.

Implementation

List<LlamaMessage> copy() {
  final List<LlamaMessage> messages = [];

  for (var message in this) {
    messages.add(
      LlamaMessage.withRole(role: message.role, content: message.content),
    );
  }

  return messages;
}