> ## Documentation Index
> Fetch the complete documentation index at: https://docs2.openclaw.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# ds4

[ds4](https://github.com/antirez/ds4) 透過本機 Metal 後端提供 DeepSeek V4 Flash，並具備與 OpenAI 相容的 `/v1` API。OpenClaw 透過通用 `openai-completions` 提供者系列連線至 ds4。

ds4 並非 OpenClaw 隨附的提供者外掛。請在
`models.providers.ds4` 下進行設定，然後選取 `ds4/deepseek-v4-flash`。

| 屬性     | 值                                                   |
| ------ | --------------------------------------------------- |
| 提供者 ID | `ds4`                                               |
| 外掛     | 無（僅設定）                                              |
| API    | 與 OpenAI 相容的 Chat Completions（`openai-completions`） |
| 基礎 URL | `http://127.0.0.1:18000/v1`（建議）                     |
| 模型 ID  | `deepseek-v4-flash`                                 |
| 工具呼叫   | OpenAI 風格的 `tools` / `tool_calls`                   |
| 推理     | DeepSeek 風格的 `thinking` 和 `reasoning_effort`        |

## 需求

* 支援 Metal 的 macOS。
* 可正常運作且包含 `ds4-server` 與 DeepSeek V4 Flash GGUF 檔案的 ds4 簽出。
* 足以容納所選上下文的記憶體；較大的 `--ctx` 值會在伺服器啟動時配置更多
  KV 記憶體。

<Warning>
  OpenClaw 代理程次包含工具結構描述與工作區上下文。像
  `--ctx 4096` 這樣極小的上下文可能通過直接 curl 測試，卻會使完整代理執行因
  `500 prompt exceeds context` 而失敗。代理與工具煙霧測試請至少使用 `--ctx 32768`。
  只有在記憶體充足且要啟用 ds4 Think Max 時，才使用 `--ctx 393216`。
</Warning>

## 快速入門

<Steps>
  <Step title="啟動 ds4-server">
    將 `<DS4_DIR>` 替換為 ds4 簽出路徑。

    ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
    <DS4_DIR>/ds4-server \
      --model <DS4_DIR>/ds4flash.gguf \
      --host 127.0.0.1 \
      --port 18000 \
      --ctx 32768 \
      --tokens 128
    ```
  </Step>

  <Step title="驗證與 OpenAI 相容的端點">
    ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
    curl http://127.0.0.1:18000/v1/models
    ```

    回應應包含 `deepseek-v4-flash`。
  </Step>

  <Step title="新增 OpenClaw 提供者設定">
    新增[完整設定](#full-config)中的設定，然後執行一次性模型
    檢查：

    ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
    openclaw infer model run \
      --local \
      --model ds4/deepseek-v4-flash \
      --thinking off \
      --prompt "Reply with exactly: openclaw-ds4-ok" \
      --json
    ```
  </Step>
</Steps>

## 完整設定

ds4 已在 `127.0.0.1:18000` 上執行時，請使用此設定。

```json5 theme={"theme":{"light":"min-light","dark":"min-dark"}}
{
  agents: {
    defaults: {
      model: { primary: "ds4/deepseek-v4-flash" },
      models: {
        "ds4/deepseek-v4-flash": {
          alias: "DS4 local",
        },
      },
    },
  },
  models: {
    mode: "merge",
    providers: {
      ds4: {
        baseUrl: "http://127.0.0.1:18000/v1",
        apiKey: "ds4-local",
        api: "openai-completions",
        timeoutSeconds: 300,
        models: [
          {
            id: "deepseek-v4-flash",
            name: "DeepSeek V4 Flash (ds4)",
            reasoning: true,
            input: ["text"],
            cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
            contextWindow: 32768,
            maxTokens: 128,
            compat: {
              supportsUsageInStreaming: true,
              supportsReasoningEffort: true,
              maxTokensField: "max_tokens",
              supportsStrictMode: false,
              thinkingFormat: "deepseek",
              supportedReasoningEfforts: ["low", "medium", "high", "xhigh"],
            },
          },
        ],
      },
    },
  },
}
```

請讓 `contextWindow` 與 `ds4-server --ctx` 保持一致。除非刻意讓 OpenClaw 要求的輸出少於伺服器預設值，否則請讓 `maxTokens` 與
`--tokens` 保持一致。

## 隨選啟動

OpenClaw 可只在選取 `ds4/...` 模型時啟動 ds4。請將
`localService` 新增至同一個提供者項目：

```json5 theme={"theme":{"light":"min-light","dark":"min-dark"}}
{
  models: {
    providers: {
      ds4: {
        baseUrl: "http://127.0.0.1:18000/v1",
        apiKey: "ds4-local",
        api: "openai-completions",
        timeoutSeconds: 300,
        localService: {
          command: "<DS4_DIR>/ds4-server",
          args: [
            "--model",
            "<DS4_DIR>/ds4flash.gguf",
            "--host",
            "127.0.0.1",
            "--port",
            "18000",
            "--ctx",
            "32768",
            "--tokens",
            "128",
          ],
          cwd: "<DS4_DIR>",
          healthUrl: "http://127.0.0.1:18000/v1/models",
          readyTimeoutMs: 300000,
          idleStopMs: 0,
        },
        models: [
          {
            id: "deepseek-v4-flash",
            name: "DeepSeek V4 Flash (ds4)",
            reasoning: true,
            input: ["text"],
            cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
            contextWindow: 32768,
            maxTokens: 128,
            compat: {
              supportsUsageInStreaming: true,
              supportsReasoningEffort: true,
              maxTokensField: "max_tokens",
              supportsStrictMode: false,
              thinkingFormat: "deepseek",
              supportedReasoningEfforts: ["low", "medium", "high", "xhigh"],
            },
          },
        ],
      },
    },
  },
}
```

`command` 必須是絕對可執行檔路徑。不會使用 Shell 查找或展開
`~`。所有 `localService` 欄位請參閱[本機模型服務](/zh-TW/gateway/local-model-services)。

## Think Max

只有在下列兩項皆為真時，ds4 才會套用 Think Max：

* `ds4-server` 以 `--ctx 393216` 或更高的值啟動。
* 要求使用 `reasoning_effort: "max"`（或對應的 ds4 推理強度欄位）。

若執行如此大的上下文，請同時更新伺服器旗標與 OpenClaw 模型
中繼資料：

```json5 theme={"theme":{"light":"min-light","dark":"min-dark"}}
{
  contextWindow: 393216,
  maxTokens: 384000,
  compat: {
    supportsUsageInStreaming: true,
    supportsReasoningEffort: true,
    maxTokensField: "max_tokens",
    supportsStrictMode: false,
    thinkingFormat: "deepseek",
    supportedReasoningEfforts: ["low", "medium", "high", "xhigh", "max"],
  },
}
```

## 測試

略過 OpenClaw 的直接 HTTP 檢查：

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
curl http://127.0.0.1:18000/v1/chat/completions \
  -H 'content-type: application/json' \
  -d '{"model":"deepseek-v4-flash","messages":[{"role":"user","content":"Reply with exactly: ds4-ok"}],"max_tokens":16,"stream":false,"thinking":{"type":"disabled"}}'
```

OpenClaw 模型路由（與快速入門檢查相同）：

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
openclaw infer model run \
  --local \
  --model ds4/deepseek-v4-flash \
  --thinking off \
  --prompt "Reply with exactly: openclaw-ds4-ok" \
  --json
```

完整代理與工具呼叫煙霧測試，上下文至少為 32768：

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
openclaw agent \
  --local \
  --session-id ds4-tool-smoke \
  --model ds4/deepseek-v4-flash \
  --thinking off \
  --message "Use the shell command pwd once, then reply exactly: tool-ok <output>" \
  --json \
  --timeout 240
```

預期結果：

* `executionTrace.winnerProvider` 為 `ds4`
* `executionTrace.winnerModel` 為 `deepseek-v4-flash`
* `toolSummary.calls` 至少為 `1`
* `finalAssistantVisibleText` 以 `tool-ok` 開頭

## 疑難排解

<AccordionGroup>
  <Accordion title="curl /v1/models 無法連線">
    ds4 未執行，或未繫結至 `baseUrl` 中的主機／連接埠。請啟動
    `ds4-server`，然後重試：

    ```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
    curl http://127.0.0.1:18000/v1/models
    ```
  </Accordion>

  <Accordion title="500 提示超出上下文">
    設定的 `--ctx` 對 OpenClaw 程次而言太小。請提高
    `ds4-server --ctx`，然後更新 `models.providers.ds4.models[].contextWindow`
    以保持一致。使用工具的完整代理程次所需上下文，遠多於直接傳送單一訊息的 curl 要求。
  </Accordion>

  <Accordion title="Think Max 未啟用">
    只有當 `--ctx` 至少為 `393216`，且要求指定
    `reasoning_effort: "max"` 時，ds4 才會使用 Think Max。較小的上下文會退回高強度
    推理。
  </Accordion>

  <Accordion title="第一次要求很慢">
    ds4 具有 Metal 冷啟駐留與模型預熱階段。當 OpenClaw 隨選啟動伺服器時，請設定
    `localService.readyTimeoutMs: 300000`。
  </Accordion>
</AccordionGroup>

## 相關內容

<CardGroup cols={2}>
  <Card title="本機模型服務" href="/zh-TW/gateway/local-model-services" icon="play">
    在模型要求之前隨選啟動本機模型伺服器。
  </Card>

  <Card title="本機模型" href="/zh-TW/gateway/local-models" icon="server">
    選擇並操作本機模型後端。
  </Card>

  <Card title="模型提供者" href="/zh-TW/concepts/model-providers" icon="layers">
    設定提供者參照、驗證與容錯移轉。
  </Card>

  <Card title="DeepSeek" href="/zh-TW/providers/deepseek" icon="brain">
    原生 DeepSeek 提供者行為與思考控制。
  </Card>
</CardGroup>
