Table of Contents

Class ChatHistory

Namespace
LMKit.TextGeneration.Chat
Assembly
LM-Kit.NET.dll

This class represents the chat history between a user and an assistant within a chat session.

public sealed class ChatHistory
Inheritance
ChatHistory
Inherited Members

Constructors

ChatHistory(LLM)

Create a new instance of the ChatHistory class.

Properties

AssistantMessageSuffix

Gets or sets the suffix to append after each assistant message.

AssistantPrefix

Specifies the assistant message prefix used to prompt the language model.

MessageCount

Returns the number of messages in the history.

Messages

Specifies a list of all messages exchanged in the chat.

Model

Gets or sets the LLM (Language Model) instance associated with this object. The model instance can be changed unless the object is marked as internal/sealed. Throws exceptions when an invalid model is provided or the instance is sealed.

PromptPrefix

Defines a text string that will be added at the start of the chat prompt.

SystemMessageSuffix

Gets or sets the suffix to append after each system message.

SystemPrefix

Gets or sets the system message prefix used to prompt the language model.

TokenCount

Indicates the total count of tokens needed by the associated language model to tokenize the content of this instance.

UserMessageCount

Returns the number of user messages in the history.

UserMessageSuffix

Gets or sets the suffix to append after each user message.

UserPrefix

Specifies the user message prefix used to prompt the language model.

Methods

AddMessage(AuthorRole, string)

Adds a message to the history.

AddMessage(Message)

Adds a message to the history.

ClearHistory()

Clears the history.

Clone()

Creates a deep copy of the current ChatHistory instance.

Deserialize(byte[], LLM)

Deserializes the given binary data into a ChatHistory instance using the specified model for context.
This method reconstructs a ChatHistory object from its binary form, applying the model to interpret or configure the data appropriately.

Deserialize(Stream, LLM)

Deserializes a ChatHistory from a stream using the provided model for context.
This method reconstructs a ChatHistory object from its binary form, applying the model to interpret or configure the data appropriately.

Deserialize(string, LLM)

Deserializes the binary data from the specified file path into a ChatHistory instance using the provided model for context. This method reconstructs a ChatHistory object from its binary form, applying the model to interpret or configure the data appropriately.

Serialize()

Serializes this instance into a binary format and returns the resulting data as a byte array.

Serialize(Stream)

Serializes this instance into a binary format and writes it to the specified stream.

Serialize(string)

Serializes this instance into a binary format and writes it to the specified file path. This method converts the current instance into its binary representation and writes the data to a file at the given path.

StartNewConversation()

Initiates the beginning of a new conversation.

ToString()

Overrides ToString() by directly invoking the ToText() method.

ToText()

Converts the complete chat history, including the formatting provided by the chat template, into a single string.

ToTokens()

Returns the complete history in the form of model tokens.