API reference · Kjarni 0.2.7
Class KjarniChatClient
Namespace: Kjarni.Extensions.AI
Assembly: Kjarni.Extensions.AI.dll
An
public sealed class KjarniChatClient : IChatClient, IDisposable
Inheritance
Implements
IChatClient, IDisposable
Remarks
The underlying native chat is not re-entrant, so concurrent calls are serialized internally. Because generation is compute-bound rather than I/O-bound, a request that waits on the gate is waiting for a real CPU or GPU, not for a socket: throughput is one conversation at a time per instance.
Constructors
KjarniChatClient(string, string?, ChatMode, string, bool)
Creates a client that owns its own
public KjarniChatClient(string model = "llama3.2-3b-instruct", string? systemPrompt = null, ChatMode mode = ChatMode.Default, string device = "cpu", bool quiet = true)
Parameters
model string
Kjarni model name, e.g. llama3.2-3b-instruct.
systemPrompt string?
Default system prompt, or null for none.
mode ChatMode
Chat mode preset.
device string
"cpu" or "gpu".
quiet bool
Suppress model download/progress output.
KjarniChatClient(Chat, string?, bool)
Wraps an existing
public KjarniChatClient(Chat chat, string? modelId = null, bool ownsChat = false)
Parameters
chat Chat
The chat instance to delegate to.
modelId string?
Model identifier reported through metadata.
ownsChat bool
When true, disposing this client also disposes chat.
Properties
ContextSize
The context window of the underlying model, in tokens.
public int ContextSize { get; }
Property Value
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
GetResponseAsync(IEnumerable<ChatMessage>, ChatOptions?, CancellationToken)
Sends chat messages and returns the response.
public Task<ChatResponse> GetResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
Parameters
messages IEnumerable<ChatMessage>
The sequence of chat messages to send.
options ChatOptions?
The chat options with which to configure the request.
cancellationToken CancellationToken
The
Returns
Task<ChatResponse>
The response messages generated by the client.
Exceptions
messages is null.
GetService(Type, object?)
Asks the serviceType.
public object? GetService(Type serviceType, object? serviceKey = null)
Parameters
serviceType Type
The type of object being requested.
serviceKey object?
An optional key that can be used to help identify the target service.
Returns
The found object, otherwise null.
Remarks
The purpose of this method is to allow for the retrieval of strongly typed services that might be provided by the
Exceptions
serviceType is null.
GetStreamingResponseAsync(IEnumerable<ChatMessage>, ChatOptions?, CancellationToken)
Sends chat messages and streams the response.
public IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(IEnumerable<ChatMessage> messages, ChatOptions? options = null, CancellationToken cancellationToken = default)
Parameters
messages IEnumerable<ChatMessage>
The sequence of chat messages to send.
options ChatOptions?
The chat options with which to configure the request.
cancellationToken CancellationToken
The
Returns
IAsyncEnumerable<ChatResponseUpdate>
The response messages generated by the client.
Remarks
Native generation is a blocking callback loop, so it runs on a background thread and feeds an unbounded channel that this method drains. Cancelling stops generation at the next token rather than after the full response, because the token callback reports the cancellation back to the native side.
Exceptions
messages is null.
Kjarni runs the same engine on every platform: