Class GenAiChatModel
java.lang.Object
smile.onnx.genai.GenAiChatModel
- All Implemented Interfaces:
AutoCloseable, LanguageModel
LanguageModel adapter over ONNX Runtime GenAI.
Holds a shared Model + Tokenizer and creates a per-call
Generator. Streaming uses TokenizerStream and
GenerationListener.onText(String). Cooperative cancel is checked between
Generator.generateNextToken() steps.
Serve wires this via ChatService OGA fallback (tools I/O, optional
multimodal). Continuous batching via GenAI OgaEngine is deferred.
-
Method Summary
Modifier and TypeMethodDescriptionchat(Message[] dialog, int maxGenLen, double temperature, double topp, boolean logprobs, long seed, GenerationListener listener, BooleanSupplier cancelRequested) Generates an assistant reply for a dialog.voidclose()int[]encodeChat(Message... dialog) Encodes a dialog with the model chat template, leaving the assistant turn open for completion.int[]encodeChat(Message[] dialog, ChatOptions options) Encodes a dialog with optional tool-calling options.family()Returns the architecture family label.generate(int[] prompt, int maxGenLen, double temperature, double topp, boolean logprobs, long seed, GenerationListener listener, BooleanSupplier cancelRequested) Generates a completion from an already-tokenized prompt.intReturns the configured maximum sequence length (max-model-len/ context length).name()Returns the model instance / checkpoint name.static GenAiChatModelLoads a GenAI chat model from a model directory.static GenAiChatModelLoads a GenAI chat model from a model directory using providers fromgenai_config.json.static GenAiChatModelLoads a GenAI chat model from aConfig.static GenAiChatModelOpens a GenAI chat model, preferring CUDA when available.static GenAiChatModelOpens a GenAI chat model, preferring CUDA when available (seeModel.open(Path)).provider()Returns the GenAI execution-provider path selected at open (Model.provider()).Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface LanguageModel
chat, generate
-
Method Details
-
of
Loads a GenAI chat model from a model directory.- Parameters:
modelDir- directory containinggenai_config.json.- Returns:
- chat model owned by the caller.
-
of
Loads a GenAI chat model from a model directory using providers fromgenai_config.json.- Parameters:
modelDir- directory containinggenai_config.json.- Returns:
- chat model owned by the caller.
-
open
Opens a GenAI chat model, preferring CUDA when available (seeModel.open(Path)).- Parameters:
modelDir- directory containinggenai_config.json.- Returns:
- chat model owned by the caller.
-
open
Opens a GenAI chat model, preferring CUDA when available.- Parameters:
modelDir- directory containinggenai_config.json.- Returns:
- chat model owned by the caller.
-
of
Loads a GenAI chat model from aConfig.- Parameters:
config- GenAI config.- Returns:
- chat model owned by the caller.
-
family
Description copied from interface:LanguageModelReturns the architecture family label.Examples:
meta/llama3,alibaba/qwen3.5. This is not necessarily the public API model id used by serve.- Specified by:
familyin interfaceLanguageModel- Returns:
- the family label string.
-
name
Description copied from interface:LanguageModelReturns the model instance / checkpoint name.- Specified by:
namein interfaceLanguageModel- Returns:
- the instance name (e.g. directory or HF repo leaf name).
-
provider
Returns the GenAI execution-provider path selected at open (Model.provider()).- Returns:
- provider id (e.g.
cuda,dml,default).
-
maxSeqLen
public int maxSeqLen()Description copied from interface:LanguageModelReturns the configured maximum sequence length (max-model-len/ context length).- Specified by:
maxSeqLenin interfaceLanguageModel- Returns:
- the maximum number of tokens allowed for prompt plus completion.
-
encodeChat
Description copied from interface:LanguageModelEncodes a dialog with the model chat template, leaving the assistant turn open for completion.- Specified by:
encodeChatin interfaceLanguageModel- Parameters:
dialog- ordered conversation turns (system/user/assistant).- Returns:
- prompt token ids ready for
LanguageModel.generate(int[], int, double, double, boolean, long, GenerationListener).
-
encodeChat
Description copied from interface:LanguageModelEncodes a dialog with optional tool-calling options.Default ignores
optionsand delegates toLanguageModel.encodeChat(Message...).- Specified by:
encodeChatin interfaceLanguageModel- Parameters:
dialog- ordered conversation turns.options- chat options; may benull.- Returns:
- prompt token ids.
-
generate
public ChatCompletion generate(int[] prompt, int maxGenLen, double temperature, double topp, boolean logprobs, long seed, GenerationListener listener, BooleanSupplier cancelRequested) Description copied from interface:LanguageModelGenerates a completion from an already-tokenized prompt.- Specified by:
generatein interfaceLanguageModel- Parameters:
prompt- prompt token id sequence.maxGenLen- maximum number of new tokens to generate (not including the prompt itself).temperature- sampling temperature; higher values increase randomness.topp- nucleus-sampling top-p threshold in(0, 1].logprobs-trueto include per-token log-probabilities in the result.seed- optional RNG seed for deterministic sampling;0means non-deterministic.listener- optional progress callback; may benull.cancelRequested- when non-null and returnstrue, generation stops between decode steps withCancellationException.- Returns:
- the completion for
prompt.
-
chat
public ChatCompletion chat(Message[] dialog, int maxGenLen, double temperature, double topp, boolean logprobs, long seed, GenerationListener listener, BooleanSupplier cancelRequested) Description copied from interface:LanguageModelGenerates an assistant reply for a dialog.Equivalent to
LanguageModel.encodeChat(Message...)followed byLanguageModel.generate(int[], int, double, double, boolean, long, GenerationListener).- Specified by:
chatin interfaceLanguageModel- Parameters:
dialog- ordered conversation turns.maxGenLen- maximum number of new tokens to generate.temperature- sampling temperature; higher values increase randomness.topp- nucleus-sampling top-p threshold in(0, 1].logprobs-trueto include per-token log-probabilities in the result.seed- optional RNG seed for deterministic sampling;0means non-deterministic.listener- optional progress callback; may benull.cancelRequested- cooperative cancel flag; may benull.- Returns:
- the completion for
dialog.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-