Namespace: LLama
The main chat session class.
public class ChatSession
Inheritance Object → ChatSession
The output transform used in this session.
public ITextStreamTransform OutputTransform;
The filename for the serialized model state (KV cache, etc).
public static string MODEL_STATE_FILENAME;
The filename for the serialized executor state.
public static string EXECUTOR_STATE_FILENAME;
The filename for the serialized chat history.
public static string HISTORY_STATE_FILENAME;
The filename for the serialized input transform pipeline.
public static string INPUT_TRANSFORM_FILENAME;
The filename for the serialized output transform.
public static string OUTPUT_TRANSFORM_FILENAME;
The filename for the serialized history transform.
public static string HISTORY_TRANSFORM_FILENAME;
The executor for this session.
public ILLamaExecutor Executor { get; private set; }
The chat history for this session.
public ChatHistory History { get; private set; }
The history transform used in this session.
public IHistoryTransform HistoryTransform { get; set; }
The input transform pipeline used in this session.
public List<ITextTransform> InputTransformPipeline { get; set; }
Create a new chat session.
public ChatSession(ILLamaExecutor executor)
executor ILLamaExecutor
The executor for this session
Create a new chat session with a custom history.
public ChatSession(ILLamaExecutor executor, ChatHistory history)
executor ILLamaExecutor
history ChatHistory
Create a new chat session and preprocess history.
public static Task<ChatSession> InitializeSessionFromHistoryAsync(ILLamaExecutor executor, ChatHistory history)
executor ILLamaExecutor
The executor for this session
history ChatHistory
History for this session
Use a custom history transform.
public ChatSession WithHistoryTransform(IHistoryTransform transform)
transform IHistoryTransform
Add a text transform to the input transform pipeline.
public ChatSession AddInputTransform(ITextTransform transform)
transform ITextTransform
Use a custom output transform.
public ChatSession WithOutputTransform(ITextStreamTransform transform)
transform ITextStreamTransform
Save a session from a directory.
public void SaveSession(string path)
path String
Get the session state.
public SessionState GetSessionState()
SessionState
SessionState object representing session state in-memory
Load a session from a session state.
public void LoadSession(SessionState state, bool loadTransforms)
state SessionState
loadTransforms Boolean
If true loads transforms saved in the session state.
Load a session from a directory.
public void LoadSession(string path, bool loadTransforms)
path String
loadTransforms Boolean
If true loads transforms saved in the session state.
Add a message to the chat history.
public ChatSession AddMessage(Message message)
message Message
Add a system message to the chat history.
public ChatSession AddSystemMessage(string content)
content String
Add an assistant message to the chat history.
public ChatSession AddAssistantMessage(string content)
content String
Add a user message to the chat history.
public ChatSession AddUserMessage(string content)
content String
Remove the last message from the chat history.
public ChatSession RemoveLastMessage()
Compute KV cache for the message and add it to the chat history.
public Task<ChatSession> AddAndProcessMessage(Message message)
message Message
Compute KV cache for the system message and add it to the chat history.
public Task<ChatSession> AddAndProcessSystemMessage(string content)
content String
Compute KV cache for the user message and add it to the chat history.
public Task<ChatSession> AddAndProcessUserMessage(string content)
content String
Compute KV cache for the assistant message and add it to the chat history.
public Task<ChatSession> AddAndProcessAssistantMessage(string content)
content String
Replace a user message with a new message and remove all messages after the new message.
This is useful when the user wants to edit a message. And regenerate the response.
public ChatSession ReplaceUserMessage(Message oldMessage, Message newMessage)
oldMessage Message
newMessage Message
Chat with the model.
public IAsyncEnumerable<string> ChatAsync(Message message, bool applyInputTransformPipeline, IInferenceParams inferenceParams, CancellationToken cancellationToken)
message Message
applyInputTransformPipeline Boolean
inferenceParams IInferenceParams
cancellationToken CancellationToken
Chat with the model.
public IAsyncEnumerable<string> ChatAsync(Message message, IInferenceParams inferenceParams, CancellationToken cancellationToken)
message Message
inferenceParams IInferenceParams
cancellationToken CancellationToken
Chat with the model.
public IAsyncEnumerable<string> ChatAsync(ChatHistory history, bool applyInputTransformPipeline, IInferenceParams inferenceParams, CancellationToken cancellationToken)
history ChatHistory
applyInputTransformPipeline Boolean
inferenceParams IInferenceParams
cancellationToken CancellationToken
Chat with the model.
public IAsyncEnumerable<string> ChatAsync(ChatHistory history, IInferenceParams inferenceParams, CancellationToken cancellationToken)
history ChatHistory
inferenceParams IInferenceParams
cancellationToken CancellationToken
Regenerate the last assistant message.
public IAsyncEnumerable<string> RegenerateAssistantMessageAsync(InferenceParams inferenceParams, CancellationToken cancellationToken)
inferenceParams InferenceParams
cancellationToken CancellationToken