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

object ← Chat

Implements

IDisposable

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

int

ModelName

Get the model name.

public string ModelName { get; }

Property Value

string

Methods

Conversation()

Starts a conversation whose history the engine keeps between messages.

public ChatConversation Conversation()

Returns

ChatConversation

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

string

Send(string, GenerationConfig)

Send a message with custom generation config.

public string Send(string message, GenerationConfig config)

Parameters

message string

config GenerationConfig

Returns

string

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

string

Remarks

keeps history natively and is the better choice when you own the conversation. This overload exists for the opposite case: a caller that owns the transcript itself and replays it on every turn, which is how IChatClient and most stateless server-side chat APIs work.

A turn resets the history and supplies the system prompt, overriding the one given to the constructor. Only the last system turn takes effect, matching the native behaviour.

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

string

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

onToken Func<string, bool>

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

onToken Func<string, bool>

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

onToken Func<string, bool>

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?

onToken Func<string, bool>

Kjarni runs the same engine on every platform: