元编程参考文档

语言模型

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
所属发行版
元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
语言模型
所属包
机器学习