> 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/ru-he-zai-vs-code-zhong-yun-xing-ben-di-ai-mo-xing.md).

# 如何在 VS Code 中运行本地 AI 模型

如何使用 VS Code 运行本地 LLM

本指南将向你展示如何将运行在 Unsloth 中的本地模型连接到 VS Code 的 Copilot Chat。Unsloth 负责加载并提供模型服务，而 VS Code 提供聊天界面和编码工具。

你可以围绕代码聊天、提出问题，并使用 Agent 模式与支持工具调用的模型一起创建和编辑文件。

### 安装 VS Code

{% tabs %}
{% tab title="macOS" %}
{% stepper %}
{% step %}

#### 下载 VS Code

打开 [VS Code 下载页面](https://code.visualstudio.com/download) ，并下载适用于你的 Mac 的 macOS 版本。选择 **Apple silicon**, **Intel**，或 **Universal** ，如果你不确定。
{% endstep %}

{% step %}

#### 设置 VS Code

打开已下载的 `.zip` 文件，然后将 **Visual Studio Code.app** 拖到你的 **应用程序** 文件夹中。

然后要打开，前往 **应用程序** 并双击 **Visual Studio Code**.
{% endstep %}
{% endstepper %}
{% endtab %}

{% tab title="Windows" %}
{% stepper %}
{% step %}

#### 下载 VS Code

打开 [VS Code 下载页面](https://code.visualstudio.com/download) 并下载适用于你的设备的 Windows **用户安装程序** 。大多数电脑使用 **x64**.
{% endstep %}

{% step %}

#### 设置 VS Code

打开已下载的 `.exe` 文件，然后按照安装程序提示操作。

然后要打开，前往开始菜单，搜索 **Visual Studio Code**，并启动它。

如果你在安装期间打开了终端，请关闭并重新打开它，以应用更新后的 PATH。
{% endstep %}
{% endstepper %}
{% endtab %}

{% tab title="Linux" %}
{% stepper %}
{% step %}

#### 下载 VS Code

打开 [VS Code 下载页面](https://code.visualstudio.com/download) 并选择适合你发行版的软件包：

* **Ubuntu 或 Debian：** `.deb`
* **Fedora 或 RHEL：** `.rpm`
  {% endstep %}

{% step %}

#### 设置 VS Code

在包含下载文件的文件夹中打开终端并运行：

**Ubuntu 或 Debian：**

```bash
sudo apt install ./code_*.deb
```

**Fedora 或 RHEL：**

```bash
sudo dnf install ./code-*.rpm
```

然后要打开，前往你的应用启动器，搜索 **Visual Studio Code**，并启动它。
{% endstep %}
{% endstepper %}
{% endtab %}
{% endtabs %}

### ⚡ 快速开始

安装 VS Code 后，我们需要安装 [Unsloth Desktop](/docs/zh/desktop.md) ，以便让 VS Code 能够提供本地模型并进行推理。

{% stepper %}
{% step %}

#### 下载 Unsloth

最简单的入门方式是安装 Unsloth Desktop 应用。它支持 [macOS](/docs/zh/kuai-su-kai-shi/install/mac.md)、Linux、 [Windows](/docs/zh/kuai-su-kai-shi/install/windows-installation.md), [NVIDIA](/docs/zh/kuai-su-kai-shi/install/pip-install.md), [AMD](/docs/zh/kuai-su-kai-shi/install/amd.md)、Intel 和 CPU 配置。

<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)

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

{% tabs %}
{% tab title="本地安装" %}
**MacOS、Linux、WSL：**

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

**Windows：**

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

{% endtab %}

{% tab title="Docker" %}
该 [Unsloth Docker 镜像](https://hub.docker.com/r/unsloth/unsloth) `unsloth/unsloth` 可在 Docker 上获取。 [阅读指南。](https://unsloth.ai/docs/get-started/install/docker)
{% endtab %}

{% tab title="Homebrew" %}
安装 Unsloth Desktop：

{% code collapsedlinecount="10" %}

```bash
brew install --cask unsloth
```

{% endcode %}

更新 Unsloth Desktop：

```bash
brew upgrade --cask unsloth
```

{% endtab %}

{% tab title="WinGet" %}
安装 Unsloth Desktop：

```powershell
winget install --id UnslothAI.Unsloth -e
```

更新 Unsloth Desktop：

```powershell
winget upgrade --id UnslothAI.Unsloth -e
```

{% endtab %}
{% endtabs %}
{% endstep %}

{% step %}

#### 安装

1. 打开 Unsloth 安装程序（`.dmg`, `.exe` 文件）
2. 在 Mac 上将 Unsloth 拖到应用程序，或者完成 Windows 的设置。
3. 启动应用并等待安装完成
   {% endstep %}

{% step %}

#### 选择模型

打开顶部的“选择模型”下拉菜单或“模型中心”选项卡，选择适合你设备的模型和量化方式，然后下载。完成后即可开始聊天——无需设置。

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FNCEVgKLJI0goPqjgcg9B%2Fmodel%20hub%20models.png?alt=media&amp;token=533b5e3c-a901-4b33-963e-4a703cc9d5a6" alt="" width="563"><figcaption></figcaption></figure>
{% endstep %}

{% step %}

#### Unsloth 现在已准备就绪

在 Unsloth 中加载好模型后，在终端中运行：

```bash
unsloth start vscode
```

打开 **Copilot Chat** 在 VS Code 中，并在下方选择你的模型 **Unsloth** 在模型选择器中。发送一条消息以检查连接。

在使用模型时保持 Unsloth 运行。

<figure><img src="https://2657992854-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxhOjnexMCB3dmuQFQ2Zq%2Fuploads%2FpAGvwjGD0iVMZKBoyu7m%2Fgreeennn.png?alt=media&amp;token=d17a5528-8375-444c-9aff-f9e9f7903bcd" alt="" width="563"><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

### 🔌 连接你的模型

在 Unsloth 中加载好模型后，打开终端并运行：

```bash
unsloth start vscode
```

这会把 Unsloth 当前提供服务的模型添加到 VS Code 的模型选择器中。它会配置连接；如果 VS Code 还未运行，请单独打开它。

你也可以用一条命令同时加载模型并配置 VS Code：

```bash
unsloth start vscode --model unsloth/Qwen3.8-27B-GGUF:UD-Q4_K_XL --context-length 32768
```

想用其他模型？将模型 ID 替换为你选择的模型。你也可以传入本地 GGUF 文件：

```bash
unsloth start vscode --model "/path/to/model.gguf" --context-length 32768
```

该命令会自动设置连接，保留你的其他模型，并备份你的 VS Code 模型设置。

它还会创建一个名为 **VS Code**的 API 密钥。若要撤销它，请打开 **设置** 中的 Unsloth，并选择 **API**.

### <i class="fa-vscode">:vscode:</i> 在 VS Code 中使用你的本地模型

在 VS Code 中打开一个项目文件夹，或者打开一个空文件夹来试试。

打开 **Copilot Chat**，点击聊天输入框下方的模型选择器，并在 **Unsloth**其中选择你的模型。选择 **代理** 以便让它创建和编辑文件，或者 **询问** 以围绕你的代码聊天。

<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%2Fdimfm9IrGcW4PK2OFNan%2Fimage.png?alt=media&amp;token=6ab59f12-9fdf-4e08-82fc-e52dbe70f375" alt="" width="563"><figcaption></figcaption></figure></div>

Agent 模式需要工具调用支持。我们建议至少 **32K 上下文**.

让我们构建一个简单的游戏。试试这个提示词：

{% code overflow="wrap" %}

```
创建一个可玩的贪吃蛇游戏，放在单个 index.html 文件中。

使用方向键移动，显示分数，并添加一个重新开始按钮。

使用浅色背景和亮绿色的蛇。使用 HTML、CSS 和 JavaScript，不要外部依赖。
```

{% endcode %}

{% columns %}
{% column %}
在批准任何工具权限之前，请先查看。一旦代理创建了 `index.html`，就在浏览器中打开它并游玩。

想要更改什么吗？让它添加难度等级或高分记录器。

在工作时保持模型已加载并让 Unsloth 服务器运行。
{% endcolumn %}

{% column %}

<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%2F7CYu4PotqktrbwiRXkPP%2Fwormgif.gif?alt=media&amp;token=08dbd04f-c6a4-48ea-986a-428131c8e970" alt="" width="375"><figcaption></figcaption></figure></div>

{% endcolumn %}
{% endcolumns %}

如果你的模型没有出现，请检查 **管理模型** 在模型选择器中。你也可以通过运行 `开发者：重新加载窗口` 从命令面板中。

#### 切换模型

在 Unsloth 中加载另一个模型，然后运行：

```bash
unsloth start vscode
```

在 Copilot Chat 中选择新模型，位于 **Unsloth** 中。

## 故障排除

**我的模型没有出现**

打开 **管理模型** 在模型选择器中查看并查找 **Unsloth**。如果它缺失，请检查 GitHub Copilot Chat 是否已启用，然后再次运行 `unsloth start vscode` 。

如果它仍然没有出现，打开命令面板并运行 **开发者：重新加载窗口**.

**我的模型在“询问”中出现，但在 Agent 模式中没有**

Agent 模式需要工具调用支持。请将 **询问** 与此模型一起使用，或者切换到其聊天模板支持工具的模型。

**我遇到了上下文长度错误**

Agent 指令和工具会占用模型上下文窗口的一部分。我们建议 Agent 模式至少使用 **32K 上下文** 。

将下面的路径替换为你的 GGUF 文件，然后运行：

{% code overflow="wrap" %}

```bash
unsloth start vscode --model "/path/to/model.gguf" --context-length 32768
```

{% endcode %}

如果模型详细信息尚未更新，请重新加载 VS Code。它可能会将 32,768 个 token 显示为 **33K**.

#### Unsloth 运行在远程机器上

在没有 VS Code 用户目录的 SSH 或容器会话中，该命令会打印要在本地添加的配置和连接说明。

按照打印出的说明使服务器可从你的电脑访问，然后将配置添加到你本地的 VS Code 安装中。

如果模型没有出现在 Remote-SSH、WSL 或开发容器窗口中，请尝试 **本地 VS Code 窗口** ，连接到远程的 Unsloth 服务器。

有关更多模型加载选项和远程连接设置，请参阅 [Unsloth Start 指南](https://unsloth.ai/docs/integrations/unsloth-start).


---

# 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/ru-he-zai-vs-code-zhong-yun-xing-ben-di-ai-mo-xing.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.
