> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-zh/ai-bian-cheng-gong-ju/tabby.md).

# TabbyML 代码补全

在 Clore.ai 上自托管 TabbyML，作为私有的 GitHub Copilot 替代方案

TabbyML 是一个自托管的 AI 代码补全服务器——可直接替代 GitHub Copilot，并将你的代码完全保留在你自己的基础设施上。它采用 Apache 2.0 许可，可在 Clore.ai 的 GPU 上运行，并通过官方扩展连接到 VS Code、JetBrains 和 Vim/Neovim。模型范围从 StarCoder2-1B（可在 4 GB VRAM 上运行）到 StarCoder2-15B 和 DeepSeek-Coder，以获得最高质量。

{% hint style="success" %}
所有示例都运行在通过以下方式租用的 GPU 服务器上： [CLORE.AI 市场](https://clore.ai/marketplace).
{% endhint %}

## 主要特性

* **自托管的 Copilot 替代方案** — 你的代码永远不会离开你的服务器
* **Apache 2.0 许可证** — 可用于商业用途，无限制
* **IDE 扩展** — VS Code、JetBrains（IntelliJ、PyCharm、WebStorm）、Vim/Neovim
* **多种模型** — StarCoder2（1B/3B/7B/15B）、DeepSeek-Coder、CodeLlama
* **仓库上下文** — 基于 RAG 的代码检索，为感知项目的补全提供支持
* **Docker 部署** — 一条命令即可启动并启用 GPU 支持
* **管理控制台** — 使用分析、模型管理、用户管理
* **聊天界面** — 提问编程问题，超越自动补全

## 需求

| 组件   | 最低             | 推荐              |
| ---- | -------------- | --------------- |
| GPU  | RTX 3060 12 GB | RTX 3080 10 GB+ |
| 显存   | 4 GB           | 10 GB           |
| 内存   | 8 GB           | 16 GB           |
| 磁盘   | 20 GB          | 50 GB           |
| CUDA | 12.8+          | 12.8+           |

**Clore.ai 价格：** RTX 3080 ≈ $0.05–0.19/小时 · RTX 3060 ≈ $0.03–0.07/小时

TabbyML 很轻量——即使是 RTX 3060 也能以快速推理运行 StarCoder2-7B。

## 快速开始

### 1. 使用 Docker 部署

```bash
# GPU 上的 StarCoder2-7B（推荐的质量与速度平衡）
docker run -d \\
  --name tabby \\
  --gpus all \\
  -p 8080:8080 \\
  -v /workspace/tabby-data:/data \\
  tabbyml/tabby \\
  serve \\
  --model StarCoder2-7B \\
  --device cuda

# 验证它正在运行
curl http://localhost:8080/v1/health
```

### 2. 选择模型

| 模型                  | 显存      | 速度 | 质量 | 最适合                  |
| ------------------- | ------- | -- | -- | -------------------- |
| StarCoder2-1B       | \~3 GB  | 最快 | 基础 | RTX 3060，快速草稿        |
| StarCoder2-3B       | \~5 GB  | 快  | 好  | 通用开发                 |
| StarCoder2-7B       | \~8 GB  | 中等 | 高  | 推荐默认                 |
| StarCoder2-15B      | \~16 GB | 较慢 | 最佳 | 复杂代码库                |
| DeepSeek-Coder-6.7B | \~8 GB  | 中等 | 高  | Python、JS、TypeScript |
| CodeLlama-7B        | \~8 GB  | 中等 | 好  | 通用                   |

通过更改以下内容切换模型： `--model` 标志：

```bash
# 更轻量的模型，适用于更低 VRAM
docker run -d --gpus all -p 8080:8080 \\
  -v /workspace/tabby-data:/data \\
  tabbyml/tabby serve --model StarCoder2-3B --device cuda

# 适用于最佳质量的最大模型
docker run -d --gpus all -p 8080:8080 \\
  -v /workspace/tabby-data:/data \\
  tabbyml/tabby serve --model StarCoder2-15B --device cuda
```

### 3. 安装 IDE 扩展

**VS Code：**

1. 打开扩展（Ctrl+Shift+X）
2. 搜索“Tabby”并安装官方扩展
3. 打开设置 → 搜索“Tabby”
4. 设置服务器端点： `http://<your-clore-ip>:8080`

**JetBrains（IntelliJ、PyCharm、WebStorm）：**

1. 设置 → 插件 → 市场
2. 搜索“Tabby”并安装
3. 设置 → 工具 → Tabby → 服务器端点： `http://<your-clore-ip>:8080`

**Vim/Neovim：**

```vim
" 使用 vim-plug
Plug 'TabbyML/vim-tabby'

" 在 init.vim / .vimrc 中配置
let g:tabby_server_url = 'http://<your-clore-ip>:8080'
```

### 4. 访问管理控制台

打开 `http://<your-clore-ip>:8080` 在浏览器中。控制台提供：

* 补全使用统计
* 模型状态和性能指标
* 用户和 API 令牌管理
* 仓库索引配置

## 使用示例

### 添加仓库上下文（RAG）

为你的仓库建立索引，以获得项目感知的补全：

```bash
# 通过管理 API
curl -X POST http://localhost:8080/v1beta/repositories \\
  -H "Content-Type: application/json" \\
  -d '{
    "name": "my-project",
    "git_url": "file:///workspace/my-project"
  }'

# Tabby 会索引仓库，并将其用于上下文感知补全
```

### 使用聊天 API

```bash
curl http://localhost:8080/v1/chat/completions \\
  -H "Content-Type: application/json" \\
  -d '{
    "messages": [
      {"role": "user", "content": "Write a Python function to parse CSV files with error handling"}
    ]
  }'
```

### 使用身份验证运行

```bash
# 通过管理控制台生成身份验证令牌，然后：
docker run -d --gpus all -p 8080:8080 \\
  -v /workspace/tabby-data:/data \\
  tabbyml/tabby serve \\
  --model StarCoder2-7B \\
  --device cuda

# 在你的 IDE 扩展设置中设置该令牌
# 或者使用 Authorization 请求头：
curl -H "Authorization: Bearer <token>" http://localhost:8080/v1/health
```

### 无需 Docker 运行（直接安装）

```bash
# 通过 Homebrew 安装（Linux）
curl -fsSL https://raw.githubusercontent.com/TabbyML/tabby/main/install.sh | bash

# 或使用 cargo install
cargo install tabby

# 直接运行
tabby serve --model StarCoder2-7B --device cuda --port 8080
```

## 成本对比

| 解决方案                | 月成本        | 隐私    | 延迟       |
| ------------------- | ---------- | ----- | -------- |
| GitHub Copilot      | $19/用户     | ❌ 云端  | \~200 毫秒 |
| RTX 3060 上的 TabbyML | \~$5–9/月   | ✅ 自托管 | \~50 毫秒  |
| RTX 3080 上的 TabbyML | \~$9–30/月  | ✅ 自托管 | \~30 毫秒  |
| RTX 4090 上的 TabbyML | \~$15–60/月 | ✅ 自托管 | \~15 毫秒  |

对于一个小团队（3–5 名开发者）来说，Clore.ai 上的一块 RTX 3080 就能以极低的成本替代多份 Copilot 订阅。

## 提示

* **StarCoder2-7B 是最佳平衡点** — 对大多数团队来说，它在质量与 VRAM 占用之间的比例最佳
* **启用仓库上下文** — RAG 索引可显著提升大型代码库的补全相关性
* **安全地暴露 8080 端口** — 在生产部署中使用 SSH 隧道或带 TLS 的反向代理
* **监控 VRAM 使用情况** — `nvidia-smi` 以确保模型能够运行，并为推理批处理留出余量
* **使用补全 API** 用于 CI/CD 集成——自动化代码审查建议
* **Tabby 支持多用户** — 管理控制台允许你为每位开发者创建 API 令牌
* **延迟很重要** — 选择一台在地理位置上离你的团队更近的 Clore.ai 服务器，以获得最快的补全速度

## 故障排查

| 问题            | 解决方案                                                    |
| ------------- | ------------------------------------------------------- |
| Docker 容器立即退出 | 检查日志： `docker logs tabby`. 可能是 VRAM 不足以运行该模型            |
| IDE 扩展无法连接    | 验证端点 URL，并检查 Clore.ai 上的防火墙/端口转发                        |
| 补全速度慢         | 使用更小的模型，或确保 GPU 未与其他任务共享                                |
| `CUDA 内存不足`   | 切换到更小的模型（StarCoder2-3B 或 1B）                            |
| 仓库索引卡住        | 检查磁盘空间，并确保 git 仓库可访问                                    |
| 身份验证令牌被拒绝     | 在管理控制台重新生成令牌，并更新 IDE 扩展                                 |
| 远程 IDE 延迟高    | 使用 SSH 隧道： `ssh -L 8080:localhost:8080 root@<clore-ip>` |

## 资源

* [TabbyML GitHub](https://github.com/TabbyML/tabby)
* [TabbyML 文档](https://tabby.tabbyml.com)
* [VS Code 扩展](https://marketplace.visualstudio.com/items?itemName=TabbyML.vscode-tabby)
* [CLORE.AI 市场](https://clore.ai/marketplace)


---

# 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://docs.clore.ai/guides/guides_v2-zh/ai-bian-cheng-gong-ju/tabby.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.
