# Aider AI 编码

Aider 是一个基于终端的 AI 编码助手，拥有超过 39K 的 GitHub 星标。它直接在你的仓库中编辑文件，自动创建 Git 提交，并支持云 API（OpenAI、Anthropic）以及通过 Ollama 完全本地的模型。在 Clore.ai GPU 上，你可以在自己的硬件上完整运行诸如 DeepSeek-R1 32B 或 Qwen2.5-Coder-32B 等大型编码模型——私有、快速且具有成本效益。

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

## 主要特性

* **终端原生** — 可通过 SSH 使用，非常适合无头的 Clore.ai 服务器
* **支持 Git** — 每次更改自动提交并附带描述性消息，便于审查和回滚
* **多文件编辑** — 将多个文件添加到上下文并同时编辑它们
* **本地模型支持** — 连接到 Ollama 以实现完全私有、无 API 成本的编码
* **架构师模式** — 使用强推理模型进行规划，然后用快速模型实现
* **仓库地图** — 自动为你的代码库建立索引，以便进行上下文感知的编辑
* **Lint 与测试** — 每次编辑后运行 linter/测试，自动修复失败项
* **语音输入** — 可通过麦克风口述编码指令

## 要求

| 组件     | 最低             | 推荐             |
| ------ | -------------- | -------------- |
| GPU    | RTX 3060 12 GB | RTX 4090 24 GB |
| 显存     | 12 GB          | 24 GB          |
| 内存     | 16 GB          | 32 GB          |
| 磁盘     | 30 GB          | 60 GB          |
| Python | 3.9            | 3.11           |

**Clore.ai 价格：** RTX 4090 约 $0.5–2/天 · RTX 3090 约 $0.3–1/天 · RTX 3060 约 $0.15–0.3/天

对于仅云模型（无本地推理），不需要 GPU —— 但 Clore.ai 的 GPU 允许你本地运行 Ollama 模型以实现完全私有化。

## 快速开始

### 1. 安装 Aider

```bash
pip install aider-chat
```

### 2. 为本地模型设置 Ollama

```bash
# 安装 Ollama
curl -fsSL https://ollama.com/install.sh | sh

# 拉取一个编码模型
ollama pull deepseek-r1:32b

# 或者为更低显存使用较小的模型
ollama pull qwen2.5-coder:7b
```

### 3. 使用本地模型启动 Aider

```bash
cd /workspace/your-project

# 通过 Ollama 使用 DeepSeek-R1 32B（大约需要 ~20 GB 显存）
aider --model ollama/deepseek-r1:32b

# 或在 RTX 3060 上使用更小的模型
aider --model ollama/qwen2.5-coder:7b
```

### 4. 开始编码

在 Aider REPL 内：

```
> /add src/main.py src/utils.py
> 为 parse_config 函数添加错误处理并为其编写单元测试
```

Aider 将会：

1. 读取这些文件并理解代码库
2. 以 diff 的形式提出更改建议
3. 将更改应用到磁盘
4. 创建带有描述性消息的 Git 提交

## 使用示例

### 架构师模式（双模型设置）

使用一个强大的模型进行推理，另一个快速模型生成代码：

```bash
# 云端架构师 + 本地编辑器
aider --architect --model ollama/deepseek-r1:32b --editor-model ollama/qwen2.5-coder:7b
```

架构师模型负责规划更改，编辑器模型负责实际编写代码——将高质量的推理与快速的实现相结合。

### 添加文件并编辑

```bash
# 将特定文件添加到聊天上下文
> /add src/api/routes.py src/models/user.py

# 请求更改
> 将用户注册端点重构为使用 async/await 并添加使用 Pydantic 的输入验证

# 添加整个目录
> /add src/tests/

# 在编辑后运行测试
> /test pytest src/tests/ -v
```

### 与云 API 一起使用

```bash
# OpenAI
export OPENAI_API_KEY=sk-...
aider --model gpt-4o

# Anthropic
export ANTHROPIC_API_KEY=sk-ant-...
aider --model claude-sonnet-4-20250514
```

### Git 集成

```bash
# 每次更改都会自动创建一个提交
git log --oneline -5
# a1b2c3d aider: 为 parse_config 添加错误处理
# d4e5f6g aider: 为 parse_config 编写单元测试
# h7i8j9k aider: 重构用户注册端点

# 撤销上一次 aider 更改
aider --undo
```

### Lint 与自动修复

```bash
# 配置 linter
aider --lint-cmd "ruff check --fix" --auto-lint

# Aider 在每次编辑后运行 linter 并自动修复问题
```

### 非交互式（脚本化）模式

```bash
# 运行单个指令并退出
aider --model ollama/deepseek-r1:32b \
  --message "为 src/utils.py 中的所有函数添加类型提示" \
  --yes  # 自动接受更改
```

## 模型推荐

| A100                  | 显存      | 性能 | 质量 | 最适合           |
| --------------------- | ------- | -- | -- | ------------- |
| deepseek-r1:32b       | \~20 GB | 中等 | 高  | 复杂重构          |
| qwen2.5-coder:32b     | \~20 GB | 中等 | 高  | 代码生成          |
| qwen2.5-coder:7b      | \~5 GB  | 快速 | 良好 | 快速编辑，RTX 3060 |
| codellama:34b         | \~20 GB | 中等 | 良好 | 遗留代码，C/C++    |
| deepseek-coder-v2:16b | \~10 GB | 快速 | 良好 | 平衡性能          |

## 提示

* **使用 `/add` 有选择地** — 仅添加 Aider 需要查看的文件。文件过多会浪费上下文 token
* **架构师模式** 对于复杂更改非常强大 — 推理模型能捕捉到编辑模型可能遗漏的边缘情况
* **`/undo`** 通过 Git 干净地还原上一次更改 — 可放心试验
* **`/diff`** 在应用前显示建议更改 — 用于审查
* **设置 `--auto-commits`** （默认）记录每次 AI 更改的完整 Git 历史
* **使用 `.aiderignore`** 用于从仓库地图中排除文件（node\_modules、.venv 等）
* **对于大型仓库**，Aider 的仓库地图可帮助模型理解代码结构 — 首次加载时让它运行
* **在编辑后运行测试** — `/test pytest` 能立即捕捉回归

## # 使用固定种子以获得一致结果

| 问题                                     | 解决方案                                                      |
| -------------------------------------- | --------------------------------------------------------- |
| Ollama 模型太慢                            | 使用更小的量化（q4\_0）或更小的模型                                      |
| `CUDA 内存不足（out of memory）` 与 Ollama 一起 | 拉取更小的模型变体或使用 `OLLAMA_NUM_GPU=0` 用于 CPU                    |
| Git 提交错误                               | 确保已安装 `git config user.email` 和 `user.name` 已设置           |
| Aider 忽略我的文件                           | 使用 `/add filename.py` 明确添加 — Aider 只会编辑已添加的文件             |
| 模型产生不佳的修改                              | 尝试更强的模型，或使用架构师模式                                          |
| 连接被拒绝（Ollama）                          | 确保 Ollama 正在运行： `ollama serve` 或 `systemctl start ollama` |
| 上下文窗口超出限制                              | 使用以下命令移除文件 `/drop`，仅保留相关文件                                |

## 资源

* [Aider GitHub](https://github.com/Aider-AI/aider)
* [Aider 文档](https://aider.chat)
* [Ollama 模型库](https://ollama.com/library)
* [CLORE.AI 市场](https://clore.ai/marketplace)


---

# Agent Instructions: 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:

```
GET https://docs.clore.ai/guides/guides_v2-zh/ai-bian-ma-gong-ju/aider.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
