> For the complete documentation index, see [llms.txt](https://unsloth.ai/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://unsloth.ai/docs/zh/mo-xing/decision-laya.md).

# 使用 Unsloth 在本地运行和提供决策模型：Laya + Jev API

使用 Unsloth 在本地部署并运行决策模型。

运行并提供诸如以下的决策模型： **Laya** 或 **Clef**，在本地运行开源的 Jev 替代方案， **Mac**, **Windows** 和 **Linux** 设备，使用 [Unsloth](https://github.com/unslothai/unsloth)。决策模型将文本输入转化为结构化决策，供你的应用执行——从分流支持工单、过滤邮件，到自动打标签和分类。

你可以使用 Unsloth GUI 界面，通过 TypeSafe 兼容的 Jev API 提供 Laya 和 Clef，从而让现有的 Jev 集成只需指向你的本地服务器即可工作。

所有数据都保留在你的设备上，并且 **CPU**, **统一内存**，以及 **GPU** 配置都支持。

<div align="center"><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FDvcVZXYF1Cepw6sw3UGs%2Flaya-demo-v2.gif?alt=media&amp;token=d550d7d8-d315-4e22-a9c2-eee2a0dbbf82" alt="Real time packing demo powered by local Laya through Unsloth’s Decision API: suitcase items update as you type and change your travel plans" width="563"><figcaption></figcaption></figure></div>

向决策模型发送文本片段，定义你需要的决策（是/否、选项或评分），并返回经过校准的概率。

### 🖥️ 推荐设置

| 模型           | 最低内存   | 大小     | 最适合                               |
| ------------ | ------ | ------ | --------------------------------- |
| **多语言** （默认） | 4GB 内存 | 678 MB | 大多数用例。支持 100+ 种语言，1024 token 上下文。 |
| **英文**       | 5GB 内存 | 846 MB | 仅英文。更大的编码器，512 token 上下文。         |
| **类型化决策**    | 5GB 内存 | 846 MB | 仅英文。发票、安全事件、客户服务、代理轨迹。            |

CPU 是默认选项。切换 **运行于** 使用 GPU 可获得更快的回答。GPU 会将模型保留在内存中，直到你按下 **卸载** 或重启 Unsloth。如果 GPU 内存耗尽，Laya 会回退到 CPU 并继续回答。

### ⚡ 快速开始

{% stepper %}
{% step %}

#### **设置 Unsloth**

最简单的上手方式是下载 [Unsloth Desktop 应用](/docs/zh/desktop.md)。支持 [macOS](/docs/zh/kuai-su-kai-shi/install/mac.md), [Windows](/docs/zh/kuai-su-kai-shi/install/windows-installation.md)，以及 [Linux](/docs/zh/kuai-su-kai-shi/install/linux.md).

<a href="https://unsloth.ai/download" class="button primary" data-icon="down-to-bracket">下载 Unsloth</a>

* <i class="fa-apple">:apple:</i> [下载 macOS 版](https://unsloth.ai/download/mac)
* <i class="fa-windows">:windows:</i> [下载 Windows 版](https://unsloth.ai/download/windows)
* <i class="fa-linux">:linux:</i> [下载 Linux 版](https://unsloth.ai/download/linux)

或者，如果你更喜欢手动安装：

MacOS、Linux、WSL：

```bash
curl -fsSL https://unsloth.ai/install.sh | sh
```

Windows PowerShell：

```bash
irm https://unsloth.ai/install.ps1 | iex
```

{% endstep %}

{% step %}

#### 设置 Laya

前往 设置 → API → **决策 API** 并开启 **提供请求服务**。在确认是否开始下载后，默认的 Laya 模型（678 MB）将开始下载。

你的 API 密钥在同一页面的 Access tokens 下。或者开启 **无密钥 API 访问** → **聊天和推理** 并在 localhost 上跳过密钥。

<div data-with-frame="true"><figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2F0Mt4vrBDlZMpLIP4O4L2%2Fdecision-api-loaded.png?alt=media&amp;token=921d0ba2-c60f-4fc2-82f9-b44584454ba3" alt=""><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}

#### 发送决策请求

现在该发送决策请求了。在这个示例中，我们对支持工单进行分类，检测退款请求，并评估紧急程度。

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2F57Wcq0T86gBgHWMt8ISt%2FScreenshot%202026-09-28%20at%206.53.48%E2%80%AFPM.png?alt=media&amp;token=88c48aef-0454-485a-8a30-ec55b0b6ad0c" alt="" width="563"><figcaption></figcaption></figure>

```bash
curl http://localhost:8888/v1/systemone \
  -H "Authorization: Bearer sk-unsloth-YOUR_KEY" \
  -H "Content-Type: application/json" \\
  -d '{
    "model": "laya",
    "state": "我在 3 月的发票（#4411）上被重复扣费了两次。请今天退还重复的那一笔。",
    "questions": {
      "team": {
        "type": "choice",
        "instructions": "由哪个团队来处理这个问题？",
        "criteria": {
          "billing": "发票、付款、退款",
          "technical": "漏洞、故障、中断、错误",
          "sales": "定价、新方案",
          "other": "其他所有内容"
        }
      },
      "refund": {"type": "noul", "instructions": "客户是否要求退款？"},
      "urgency": {"type": "score", "instructions": "这个有多紧急？", "criteria": ["不紧急", "尽快", "今天"]}
    }
  }'
```

你将得到：

```json
{
  "model": "laya-multilingual",
  "answers": {
    "team": {"type": "choice", "choice": "billing", "confidence": 1.0, "probabilities": {"billing": 1.0, "technical": 0.0, "sales": 0.0, "other": 0.0}},
    "refund": {"type": "noul", "noul": 0.9794},
    "urgency": {"type": "score", "score": 1.9005, "confidence": 0.698, "legend": {"0": "不紧急", "1": "尽快", "2": "今天"}, "probabilities": {"0": 0.004, "1": 0.0915, "2": 0.9045}}
  },
  "usage": {"input_tokens": 172, "output_tokens": 0}
}
```

第一次请求会加载模型，这需要 10 到 20 秒。之后，在大多数 CPU 上，请求用时都远低于一秒。

`状态` 可以是字符串或任何 JSON。 `模型` 接受 `laya`, `默认`，或者 `jev-latest` 对应于你在设置中选择的模型，或者 `laya-multilingual`, `laya-english`, `laya-typed-decisions` 比如其中一个。
{% endstep %}
{% endstepper %}

### ❓ 问题类型

| 类型     | 用于     | 你将得到                   |
| ------ | ------ | ---------------------- |
| `noul` | 是或否    | “是”的概率，介于 0 到 1 之间     |
| `选择`   | 选择一个选项 | 最可能的选项，以及每个选项的概率       |
| `评分`   | 按量表评分  | 文本在你的量表上所处的位置，从 0 开始计数 |

`noul` 表示是/否。它返回“是”的概率： `0.98` 表示非常可能， `0.5` 表示两种结果的可能性相同。

`选择` 和 `评分` 也返回 `置信度`. 接近 `1` 表示有一个答案更突出。接近 `0` 表示概率分布较为均匀。

{% columns %}
{% column %}
要基于某个选择采取行动，请使用其在 `probabilities`，而不是 `置信度`. 例如，只有当 `technical` 高于 `0.8`. Laya 和 Jev 计算置信度的方式不同，所以不要复用你的 Jev 置信度阈值。

每个请求最多支持 **64 个问题**，并且最多支持 **每个选择 255 个选项** 和 **每个评分 10 个等级**.
{% endcolumn %}

{% column %}

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FlsX4Rv1JIcz1JuTkFIBO%2Fsuitcase-10mb.gif?alt=media&amp;token=1314fb64-166e-48b2-97cf-cb086d40fbe9" alt=""><figcaption><p>通过 Unsloth 的决策 API 使用本地 Laya 驱动的实时打包演示：当你输入并更改旅行计划时，行李箱物品会自动更新</p></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

### 🔁 从 Jev 迁移

使用以下命令安装 SDK `pip install typesafe-sdk`，设置两个环境变量，你现有的代码就会与 Unsloth 通信：

```bash
export TYPESAFE_BASE_URL=http://localhost:8888
export TYPESAFE_API_KEY=sk-unsloth-YOUR_KEY
```

SDK 的默认模型， `jev-latest`会映射到你在设置中选择的模型。

有两点与 Jev 不同。 `置信度` 使用不同的公式，因此在 Jev 上调好的阈值无法直接迁移；应将阈值设为 `probabilities` 。另外，选择中的各个选项共享固定的 token 预算，因此当描述超过约 20 个选项后，标签会被截断。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://unsloth.ai/docs/zh/mo-xing/decision-laya.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
