ChatSession class

Maintains a sequence of chat messages and can convert them into a prompt format compatible with chat-based language models.

Constructors

ChatSession({int? seed, String imStart = ChatSession.defaultIMStart, String imEnd = ChatSession.defaultIMEnd})
Creates a new ChatSession.

Properties

hashCode int
The hash code for this object.
no setterinherited
imEnd String
End token used to delimit chat message blocks.
final
imStart String
Start token used to delimit chat message blocks.
final
length int
Number of messages currently stored in the session.
no setter
random Random
Random number generator used for sampling and stochastic operations.
latefinal
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
seed int
Random seed used for deterministic generation.
final

Methods

addAssistant(String text) → void
Adds an assistant message to the session.
addSystem(String text) → void
Adds a system-level instruction message.
addUser(String text) → void
Adds a user message to the session.
buildPrompt({int offset = 0}) String
Builds a formatted prompt string from the stored chat messages.
endsWithImEndToken(String text) bool
Checks whether the given text ends with the configured imEnd token.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

generateSeed() int
Generates a random seed suitable for deterministic or reproducible runs.

Constants

defaultIMEnd → const String
Token used to mark the end of a message block in the chat template.
defaultIMStart → const String
Token used to mark the beginning of a message block in the chat template.