MessageCollection
Namespace: Wisej.AI
Assembly: Wisej.AI
Represents a collection of messages in a session.
- C#
- VB.NET
public class MessageCollection : ObservableCollection<>, ICloneable
Public Class MessageCollection
Inherits ObservableCollection(Of )
Implements ICloneable
Constructors
MessageCollection()
Initializes a new instance of MessageCollection.
Methods
Add(role, content)
Adds a message with the specified role and content.
| Parameter | Type | Description |
|---|---|---|
| role | MessageRole | The role of the message. |
| content | String | The content of the message. |
Returns: MessageCollection. The current MessageCollection instance.
Throws:
- ArgumentNullException Thrown when the content is null.
AddRange(messages)
Adds a range of messages to the collection.
| Parameter | Type | Description |
|---|---|---|
| messages | IList<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.
| Parameter | Type | Description |
|---|---|---|
| index | Int32 | The zero-based index at which the message should be inserted. |
| item | Message | The message to insert. |
MoveItem(oldIndex, newIndex)
Moves a message from one index to another.
| Parameter | Type | Description |
|---|---|---|
| oldIndex | Int32 | The zero-based index specifying the location to move from. |
| newIndex | Int32 | The zero-based index specifying the location to move to. |
RemoveAll(predicate)
Removes all messages that match the specified predicate.
| Parameter | Type | Description |
|---|---|---|
| predicate | Predicate<Message> | The predicate to match messages. |
Returns: MessageCollection. The current MessageCollection instance.
RemoveLast(count)
Removes the last message(s) from the collection.
| Parameter | Type | Description |
|---|---|---|
| count | Int32 | The number of messages to remove. Default is 1. |
Returns: MessageCollection. The current MessageCollection instance.