Divooka Reference

Language Models

8 nodes

On this page 8

Ask

Function

Asks a chat model one question and answers with its reply: a one-message conversation, rendered through the model's chat template.

Signature
Ask -> Text
    model: Language Model
    question: Text
    system: Text
    settings: Generation Settings
string Ask(
    LanguageModel model,
    string question,
    string system,
    GenerationSettings settings)

Parameters

nametypedefaultdescription
modelLanguage Model—A model that can chat (one with a chat template, usually named Instruct or Chat).
questionText—What to ask.
systemText—What the model is told about its part first; empty for none.
settingsGeneration Settings—How it chooses its words; empty for the model's own defaults.

Returns

ReplyText
Ships with
Divooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Language Models
Package
Machine Learning

Chat

Function

Says a message in a conversation and answers with the model's reply, and the conversation with both added, to continue from.

Signature
Chat -> (Reply: Text, continued: Conversation)
    model: Language Model
    message: Text
    conversation: Conversation
    settings: Generation Settings
string Chat(
    LanguageModel model,
    string message,
    Conversation conversation,
    GenerationSettings settings,
    out Conversation continued)

Parameters

nametypedefaultdescription
modelLanguage Model—A model that can chat.
messageText—What the user says.
conversationConversation—The conversation so far, from Start Conversation or an earlier Chat; empty to start one.
settingsGeneration Settings—How it chooses its words; empty for the model's own defaults.

Returns

ReplyText
continuedConversation
Ships with
Divooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Language Models
Package
Machine Learning

Continue Conversation

Function

The model's next reply to a conversation that ends with the user's message.

Signature
ContinueConversation -> Text
    model: Language Model
    conversation: Conversation
    settings: Generation Settings
string ContinueConversation(
    LanguageModel model,
    Conversation conversation,
    GenerationSettings settings)

Parameters

nametypedefaultdescription
modelLanguage Model—A model that can chat.
conversationConversation—The conversation, ending with what the user said.
settingsGeneration Settings—How it chooses its words; empty for the model's own defaults.

Returns

ReplyText
Ships with
Divooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Language Models
Package
Machine Learning

Count Tokens

Function

How many tokens a text is to a model, which is what its length limits and Generation Settings count.

Signature
CountTokens(model: Language Model, text: Text) -> Integer
int CountTokens(LanguageModel model, string text)

Parameters

nametypedefaultdescription
modelLanguage Model—The model whose tokenizer counts.
textText—The text.

Returns

TokensInteger
Ships with
Divooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Language Models
Package
Machine Learning

Generate Text

Function

Continues a text as the model would write it, without a chat template: the model's continuation alone, not the prompt.

Signature
GenerateText -> Text
    model: Language Model
    prompt: Text
    settings: Generation Settings
string GenerateText(
    LanguageModel model,
    string prompt,
    GenerationSettings settings)

Parameters

nametypedefaultdescription
modelLanguage Model—Any language model, base or chat.
promptText—The text to continue.
settingsGeneration Settings—How it chooses its words; empty for the model's own defaults.

Returns

ContinuationText
Ships with
Divooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Language Models
Package
Machine Learning

Load Language Model

Function

Loads a language model and its tokenizer from a Hugging Face Hub repository or a folder, downloading what is missing.

Signature
LoadLanguageModel -> Language Model
    model: Text
    device: Compute Device
    precision: Precision
    adapter: Text
    fourBit: Truth
LanguageModel LoadLanguageModel(
    string model,
    ComputeDevice device = ComputeDevice.Auto,
    Precision precision = Precision.Auto,
    string adapter,
    bool fourBit = false)

Parameters

nametypedefaultdescription
modelText—A repository id such as HuggingFaceTB/SmolLM2-135M-Instruct, or a folder holding config.json, the weights and the tokenizer.
deviceCompute DeviceAutoWhere it runs.
precisionPrecisionAutoThe number format of its weights; Auto is Float32 on the CPU and the model's own on the GPU.
adapterText—A LoRA adapter to apply, as Fine-Tune Language Model saves one: its folder or a repository id; empty for none.
fourBitTruthFalseQuantize the weights to 4-bit NF4 as they load, as QLoRA does: a quarter of the memory, a little less accuracy.

Returns

ModelLanguage Model
Ships with
Divooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Language Models
Package
Machine Learning

Load ONNX Language Model

Function

Loads a language model to run on the ONNX backend: the repository's own ONNX file when it has one, such as one Export Language Model to ONNX wrote, otherwise a graph built from its checkpoint. Runs on the CPU, fully managed.

Signature
LoadOnnxLanguageModel(model: Text) -> Language Model
LanguageModel LoadOnnxLanguageModel(string model)

Parameters

nametypedefaultdescription
modelText—A repository id, or a folder with config.json, the tokenizer and onnx/model.onnx.

Returns

ModelLanguage Model
Ships with
Divooka Compute
Graph kinds
Flows Function Events Routine Constructs StateMachineState
Declared by
Language Models
Package
Machine Learning

Stream Chat

Function

Chat, with the reply handed to a function piece by piece as it is written - whole words, line by line - so it can be shown before it is finished.

Signature
StreamChat -> (Reply: Text, continued: Conversation)
    model: Language Model
    message: Text
    conversation: Conversation
    settings: Generation Settings
    onText: Action<Text>
string StreamChat(
    LanguageModel model,
    string message,
    Conversation conversation,
    GenerationSettings settings,
    Action<string> onText,
    out Conversation continued)

Parameters

nametypedefaultdescription
modelLanguage Model—A model that can chat.
messageText—What the user says.
conversationConversation—The conversation so far; empty to start one.
settingsGeneration Settings—How it chooses its words; empty for the model's own defaults.
onTextAction<Text>—Called with each new piece of the reply, in order.

Returns

ReplyText
continuedConversation
Ships with
Divooka Compute
Graph kinds
Events Routine StateMachineState
Declared by
Language Models
Package
Machine Learning