Skip to main content

MessageCollection

Namespace: Wisej.AI

Assembly: Wisej.AI

Represents a collection of messages in a session.

public class MessageCollection : ObservableCollection<>, ICloneable

Constructors

MessageCollection()

Initializes a new instance of MessageCollection.

Methods

Add(role, content)

Adds a message with the specified role and content.

ParameterTypeDescription
roleMessageRoleThe role of the message.
contentStringThe content of the message.

Returns: MessageCollection. The current MessageCollection instance.

Throws:

AddRange(messages)

Adds a range of messages to the collection.

ParameterTypeDescription
messagesIList<Message>The messages to add.

Returns: MessageCollection. The current MessageCollection instance.

Clone()

Creates a shallow clone of the collection.

Returns: MessageCollection. A shallow clone of the MessageCollection.

InsertItem(index, item)

Inserts a message at the specified index.

ParameterTypeDescription
indexInt32The zero-based index at which the message should be inserted.
itemMessageThe message to insert.

MoveItem(oldIndex, newIndex)

Moves a message from one index to another.

ParameterTypeDescription
oldIndexInt32The zero-based index specifying the location to move from.
newIndexInt32The zero-based index specifying the location to move to.

RemoveAll(predicate)

Removes all messages that match the specified predicate.

ParameterTypeDescription
predicatePredicate<Message>The predicate to match messages.

Returns: MessageCollection. The current MessageCollection instance.

RemoveLast(count)

Removes the last message(s) from the collection.

ParameterTypeDescription
count Int32The number of messages to remove. Default is 1.

Returns: MessageCollection. The current MessageCollection instance.