> 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="/files/acc2d06bd99c5eaf625396a89b996e818d86b420" alt=""><figcaption></figcaption></figure>

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

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

点击 **添加连接**后，你启用的模型将显示在 **连接** 下选择一个 OpenRouter 模型。
{% endstep %}

{% step %}

#### 准备聊天

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

<figure><img src="/files/3b50b7b393bfbe4ae8690b18c438426126046066" 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://unsloth.ai/docs/zh/ji-cheng/connections/vllm.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
