Freigeben über


ChatHistory Class

Definition

Provides a history of chat messages from a chat conversation.

public class ChatHistory : System.Collections.Generic.ICollection<Microsoft.SemanticKernel.ChatMessageContent>, System.Collections.Generic.IEnumerable<Microsoft.SemanticKernel.ChatMessageContent>, System.Collections.Generic.IList<Microsoft.SemanticKernel.ChatMessageContent>, System.Collections.Generic.IReadOnlyCollection<Microsoft.SemanticKernel.ChatMessageContent>, System.Collections.Generic.IReadOnlyList<Microsoft.SemanticKernel.ChatMessageContent>
type ChatHistory = class
    interface IList<ChatMessageContent>
    interface ICollection<ChatMessageContent>
    interface seq<ChatMessageContent>
    interface IEnumerable
    interface IReadOnlyList<ChatMessageContent>
    interface IReadOnlyCollection<ChatMessageContent>
Public Class ChatHistory
Implements ICollection(Of ChatMessageContent), IEnumerable(Of ChatMessageContent), IList(Of ChatMessageContent), IReadOnlyCollection(Of ChatMessageContent), IReadOnlyList(Of ChatMessageContent)
Inheritance
ChatHistory
Implements

Constructors

ChatHistory()

Initializes an empty history.

ChatHistory(IEnumerable<ChatMessageContent>)

Initializes the history will all of the specified messages.

ChatHistory(String)

Creates a new instance of the ChatHistory class with a system message

Properties

Count

Gets the number of messages in the history.

Item[Int32]

Gets or sets the message at the specified index in the history.

Methods

Add(ChatMessageContent)

Adds a message to the history.

AddAssistantMessage(String)

Add an assistant message to the chat history

AddMessage(AuthorRole, ChatMessageContentItemCollection, Encoding, IReadOnlyDictionary<String,Object>)
AddMessage(AuthorRole, String, Encoding, IReadOnlyDictionary<String,Object>)
AddRange(IEnumerable<ChatMessageContent>)

Adds the messages to the history.

AddSystemMessage(String)

Add a system message to the chat history

AddUserMessage(ChatMessageContentItemCollection)

Add a user message to the chat history

AddUserMessage(String)

Add a user message to the chat history

Clear()

Removes all messages from the history.

Contains(ChatMessageContent)

Determines whether a message is in the history.

CopyTo(ChatMessageContent[], Int32)

Copies all of the messages in the history to an array, starting at the specified destination array index.

IndexOf(ChatMessageContent)

Searches for the specified message and returns the index of the first occurrence.

Insert(Int32, ChatMessageContent)

Inserts a message into the history at the specified index.

Remove(ChatMessageContent)

Removes the first occurrence of the specified message from the history.

RemoveAt(Int32)

Removes the message at the specified index from the history.

RemoveRange(Int32, Int32)

Removes a range of messages from the history.

Explicit Interface Implementations

ICollection<ChatMessageContent>.IsReadOnly

Gets a value indicating whether the ICollection<T> is read-only.

IEnumerable.GetEnumerator()

Returns an enumerator that iterates through a collection.

IEnumerable<ChatMessageContent>.GetEnumerator()

Returns an enumerator that iterates through the collection.

Extension Methods

ToDescending(ChatHistory)

Enumeration of chat-history in descending order.

ToDescendingAsync(ChatHistory)

Asynchronous enumeration of chat-history in descending order.

AddStreamingMessageAsync(ChatHistory, IAsyncEnumerable<OpenAIStreamingChatMessageContent>)

Add a message to the chat history at the end of the streamed message

Applies to