元編程參考文件

語言模型

8 個節點

本頁內容 8

提問

函數

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

簽名
提問 -> 文字
    模型: Language Model
    問題: 文字
    系統提示: 文字
    設定: Generation Settings
string Ask(
    LanguageModel model,
    string question,
    string system,
    GenerationSettings settings)

參數

名稱型別預設值說明
模型Language Model—A model that can chat (one with a chat template, usually named Instruct or Chat).
問題文字—What to ask.
系統提示文字—What the model is told about its part first; empty for none.
設定Generation Settings—How it chooses its words; empty for the model's own defaults.

返回

回覆文字
所屬發行版
元編程(專業版)
可用的圖種類
資料流 函數 事件 例程 藍圖 狀態機狀態
宣告於
語言模型
所屬包
機器學習

對話

函數

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

簽名
對話 -> (回覆: 文字, 續接的對話: Conversation)
    模型: Language Model
    訊息: 文字
    對話: Conversation
    設定: Generation Settings
string Chat(
    LanguageModel model,
    string message,
    Conversation conversation,
    GenerationSettings settings,
    out Conversation continued)

參數

名稱型別預設值說明
模型Language Model—A model that can chat.
訊息文字—What the user says.
對話Conversation—The conversation so far, from Start Conversation or an earlier Chat; empty to start one.
設定Generation Settings—How it chooses its words; empty for the model's own defaults.

返回

回覆文字
續接的對話Conversation
所屬發行版
元編程(專業版)
可用的圖種類
資料流 函數 事件 例程 藍圖 狀態機狀態
宣告於
語言模型
所屬包
機器學習

繼續對話

函數

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

簽名
繼續對話 -> 文字
    模型: Language Model
    對話: Conversation
    設定: Generation Settings
string ContinueConversation(
    LanguageModel model,
    Conversation conversation,
    GenerationSettings settings)

參數

名稱型別預設值說明
模型Language Model—A model that can chat.
對話Conversation—The conversation, ending with what the user said.
設定Generation Settings—How it chooses its words; empty for the model's own defaults.

返回

回覆文字
所屬發行版
元編程(專業版)
可用的圖種類
資料流 函數 事件 例程 藍圖 狀態機狀態
宣告於
語言模型
所屬包
機器學習

計算詞元數

函數

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

簽名
計算詞元數(模型: Language Model, 文字: 文字) -> 整數
int CountTokens(LanguageModel model, string text)

參數

名稱型別預設值說明
模型Language Model—The model whose tokenizer counts.
文字文字—The text.

返回

詞元數整數
所屬發行版
元編程(專業版)
可用的圖種類
資料流 函數 事件 例程 藍圖 狀態機狀態
宣告於
語言模型
所屬包
機器學習

生成文字

函數

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

簽名
生成文字 -> 文字
    模型: Language Model
    提示詞: 文字
    設定: Generation Settings
string GenerateText(
    LanguageModel model,
    string prompt,
    GenerationSettings settings)

參數

名稱型別預設值說明
模型Language Model—Any language model, base or chat.
提示詞文字—The text to continue.
設定Generation Settings—How it chooses its words; empty for the model's own defaults.

返回

續寫文字
所屬發行版
元編程(專業版)
可用的圖種類
資料流 函數 事件 例程 藍圖 狀態機狀態
宣告於
語言模型
所屬包
機器學習

載入語言模型

函數

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

簽名
載入語言模型 -> Language Model
    模型: 文字
    裝置: Compute Device
    精度: Precision
    適配器: 文字
    四位量化: 真否
LanguageModel LoadLanguageModel(
    string model,
    ComputeDevice device = ComputeDevice.Auto,
    Precision precision = Precision.Auto,
    string adapter,
    bool fourBit = false)

參數

名稱型別預設值說明
模型文字—A repository id such as HuggingFaceTB/SmolLM2-135M-Instruct, or a folder holding config.json, the weights and the tokenizer.
裝置Compute Device自動Where it runs.
精度Precision自動The number format of its weights; Auto is Float32 on the CPU and the model's own on the GPU.
適配器文字—A LoRA adapter to apply, as Fine-Tune Language Model saves one: its folder or a repository id; empty for none.
四位量化真否FalseQuantize the weights to 4-bit NF4 as they load, as QLoRA does: a quarter of the memory, a little less accuracy.

返回

模型Language Model
所屬發行版
元編程(專業版)
可用的圖種類
資料流 函數 事件 例程 藍圖 狀態機狀態
宣告於
語言模型
所屬包
機器學習

載入 ONNX 語言模型

函數

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.

簽名
載入 ONNX 語言模型(模型: 文字) -> Language Model
LanguageModel LoadOnnxLanguageModel(string model)

參數

名稱型別預設值說明
模型文字—A repository id, or a folder with config.json, the tokenizer and onnx/model.onnx.

返回

模型Language Model
所屬發行版
元編程(專業版)
可用的圖種類
資料流 函數 事件 例程 藍圖 狀態機狀態
宣告於
語言模型
所屬包
機器學習

流式對話

函數

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.

簽名
流式對話 -> (回覆: 文字, 續接的對話: Conversation)
    模型: Language Model
    訊息: 文字
    對話: Conversation
    設定: Generation Settings
    文字回撥: Action<文字>
string StreamChat(
    LanguageModel model,
    string message,
    Conversation conversation,
    GenerationSettings settings,
    Action<string> onText,
    out Conversation continued)

參數

名稱型別預設值說明
模型Language Model—A model that can chat.
訊息文字—What the user says.
對話Conversation—The conversation so far; empty to start one.
設定Generation Settings—How it chooses its words; empty for the model's own defaults.
文字回撥Action<文字>—Called with each new piece of the reply, in order.

返回

回覆文字
續接的對話Conversation
所屬發行版
元編程(專業版)
可用的圖種類
事件 例程 狀態機狀態
宣告於
語言模型
所屬包
機器學習