> 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/ji-cheng/connections/vllm.md).

# 将 vLLM 连接到 Unsloth，用于本地聊天推理

了解如何连接 **vLLM 连接到** [**Unsloth**](https://github.com/unslothai/unsloth) 使用 vLLM 的 **兼容 OpenAI 的 API** 这样你就可以在一个开源 UI 聊天界面中本地提供模型服务并与它们聊天。本指南将带你安装 vLLM、启动本地 vLLM 服务器、配置 API 基础 URL、加载可用的模型 ID，并选择你托管的 vLLM 模型。

到最后，你通过 vLLM 提供服务的模型将与本地模型一起显示，让你能够以快速且灵活的方式在 UI 聊天界面中运行外部 LLM 推理。

### 设置

{% stepper %}
{% step %}

#### 安装 vLLM

先安装 vLLM，这样你就可以运行 `vllm serve` 命令。请根据你的平台和硬件，按照官方 [vLLM 安装指南](https://docs.vllm.ai/en/stable/getting_started/installation/) 进行操作。

安装完成后，请检查 vLLM 是否能在你的终端中正常工作： `vllm --help`
{% endstep %}

{% step %}

#### 选择模型

vLLM 从 Hugging Face 提供模型服务。

例如，使用 Unsloth 模型启动一个 vLLM 服务器：

```bash
vllm serve unsloth/gemma-4-26B-A4B-it 
\ --dtype auto
```

这会在以下地址暴露一个 API 端点：

`http://localhost:8000/v1`

若要要求 API 密钥，请添加：

```bash
--api-key token-abc123
```

{% endstep %}

{% step %}

#### 将 vLLM 连接到 Unsloth

打开 **设置 → 连接**，然后点击 **添加连接**.

选择 **vLLM**，然后输入你的服务器详细信息。

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FN80ObNBvpN7hDypheYkt%2Fimage.png?alt=media&amp;token=481f4c1f-afb6-438d-ae35-85566f15e414" alt=""><figcaption></figcaption></figure>

输入你的 vLLM 服务器详细信息：

* **API 密钥：** 除非你使用 --api-key 启动了 vLLM，否则留空
* **基础 URL：** 例如，<http://localhost:8000/v1>
* **推理模型：** 如果所服务的模型支持思考，请启用此项
* **模型 ID：** 点击 **加载模型**，或手动输入自定义 ID

点击后 **添加连接**，你启用的模型将显示在 **连接** 模型下拉菜单中。
{% endstep %}

{% step %}

#### 准备聊天

保存连接后，你的 vLLM 模型将显示在 **已连接** 模型下拉菜单中。选择它即可通过你的 vLLM 服务器开始聊天。

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FpoXSmL3PcpprEy8CIT7S%2Fexport-1779046578662.gif?alt=media&amp;token=acf1de86-6fa4-466f-97f7-2d91662a124e" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
如果你的 vLLM 服务器响应较慢（尤其是在模型加载期间），你可以调整超时时间：

```bash
AIOHTTP_CLIENT_TIMEOUT_MODEL_LIST=30
```

{% endhint %}
{% endstep %}
{% endstepper %}

### 常见的 vLLM 参数

上面的示例使用了核心服务设置。你可以根据你的模型和硬件添加更多 vllm serve 参数。

常见选项包括：

```bash
vllm serve unsloth/gemma-4-26B-A4B-it \
  --dtype auto \
  --host 0.0.0.0 \\
  --port 8000 \
  --api-key token-abc123 \
  --max-model-len 8192 \
  --gpu-memory-utilization 0.9
```

有关 vLLM 服务器参数的完整列表，请参阅官方 vLLM [OpenAI 兼容服务器](https://docs.vllm.ai/en/stable/serving/openai_compatible_server/) 文档。


---

# 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/ji-cheng/connections/vllm.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.
