API reference · Kjarni 0.2.7
Class Chat
Namespace: Kjarni
Assembly: Kjarni.dll
High-level chat interface for conversational AI using local decoder models.
public class Chat : IDisposable
Inheritance
Implements
Constructors
Chat(string, string?, ChatMode, bool, string?, bool)
Create a new Chat instance.
public Chat(string model, string? systemPrompt = null, ChatMode mode = ChatMode.Default, bool quiet = false, string? device = null, bool quantized = false)
Parameters
model string
Model name, e.g. "llama3.2-1b-instruct", "qwen2-0.5b-instruct"
systemPrompt string?
Optional system prompt
mode ChatMode
Chat mode (Default, Creative, Reasoning)
quiet bool
Suppress loading output
device string?
Device: "cpu" or "gpu"
quantized bool
Load the 4-bit GGUF weights instead of full precision: a fraction of the memory and several times faster to generate on a CPU.
Properties
ContextSize
Get the context window size.
public int ContextSize { get; }
Property Value
ModelName
Get the model name.
public string ModelName { get; }
Property Value
Methods
Conversation()
Starts a conversation whose history the engine keeps between messages.
public ChatConversation Conversation()
Returns
Dispose()
Releases the native model. The object cannot be used afterwards.
public void Dispose()
Send(string)
Send a message and get the full response (blocking).
public string Send(string message)
Parameters
message string
Returns
Send(string, GenerationConfig)
Send a message with custom generation config.
public string Send(string message, GenerationConfig config)
Parameters
message string
config GenerationConfig
Returns
SendWithHistory(IEnumerable<ChatTurn>, string)
Create a stateful conversation that maintains history.
public string SendWithHistory(IEnumerable<ChatTurn> history, string message)
Parameters
history IEnumerable<ChatTurn>
Prior turns, oldest first. May be empty.
message string
The new user message to respond to.
Returns
Remarks
IChatClient and most stateless server-side chat APIs work.
A
SendWithHistory(IEnumerable<ChatTurn>, string, GenerationConfig?)
Send a message with an explicit conversation history and generation config.
public string SendWithHistory(IEnumerable<ChatTurn> history, string message, GenerationConfig? config)
Parameters
history IEnumerable<ChatTurn>
message string
config GenerationConfig?
Returns
Stream(string, Func<string, bool>)
Stream a response token by token. Return false from the callback to stop generation.
public void Stream(string message, Func<string, bool> onToken)
Parameters
message string
Stream(string, GenerationConfig, Func<string, bool>)
Stream with custom generation config.
public void Stream(string message, GenerationConfig config, Func<string, bool> onToken)
Parameters
message string
config GenerationConfig
StreamWithHistory(IEnumerable<ChatTurn>, string, Func<string, bool>)
Stream a response to message given an explicit history.
Return false from onToken to stop.
public void StreamWithHistory(IEnumerable<ChatTurn> history, string message, Func<string, bool> onToken)
Parameters
history IEnumerable<ChatTurn>
message string
StreamWithHistory(IEnumerable<ChatTurn>, string, GenerationConfig?, Func<string, bool>)
Stream a response with an explicit history and generation config.
public void StreamWithHistory(IEnumerable<ChatTurn> history, string message, GenerationConfig? config, Func<string, bool> onToken)
Parameters
history IEnumerable<ChatTurn>
message string
config GenerationConfig?
Kjarni runs the same engine on every platform: