---
layout: single
title:  "CodeGate - 让 AI 编码助手更安全"
date:   2025-01-17 10:00:00 +0800
categories: [AI 与大模型, 容器与云原生]
tags: [CodeGate, AIGateway, LLM]
---

## 什么是 CodeGate
- [CodeGate](https://codegate.ai/)
- [CodeGate GitHub](https://github.com/stacklok/codegate)
- [CodeGate 文档](https://docs.codegate.ai/)

CodeGate 是位于 AI 编码助手和 LLM 之间的本地提示网关，用于增强隐私和安全性。
- 执行代码安全审查
- 识别包依赖项中的漏洞
- 防止敏感数据（如机密）与 AI 模型共享


## 工作原理

CodeGate 是位于 AI 编码助手和 LLM 之间的本地代理。CodeGate 会审查您的提示是否存在任何潜在的机密泄露 — 在机密离开您的桌面之前对其进行加密，并在响应中对其进行解密。CodeGate 使用 RAG 来更新任何 LLM 的知识库，并提供相关的风险洞察。

![](/images/2025/CodeGate/diagram.png)


## Continue 指南

### 启动 CodeGate 服务
```bash
docker pull ghcr.io/stacklok/codegate:latest
docker run --name codegate -d -p 8989:8989 -p 9090:9090 --restart unless-stopped ghcr.io/stacklok/codegate:latest
```

### 下载 Ollama 代码模型

```bash
ollama pull qwen2.5-coder:7b
ollama pull qwen2.5-coder:1.5b
```

### 配置 Continue 扩展

编辑配置文件：`~/.continue/config.json`

```json
{
  "models": [
    {
      "title": "Qwen2.5-Coder-7B",
      "provider": "ollama",
      "model": "qwen2.5-coder:7b",
      "apiBase": "http://localhost:8989/ollama"
    }
  ],
  "modelRoles": {
    "default": "Qwen2.5-Coder-7B",
    "summarize": "Qwen2.5-Coder-7B"
  },
  "tabAutocompleteModel": {
    "title": "Qwen2.5-Coder-1B",
    "provider": "ollama",
    "model": "qwen2.5-coder:1.5b",
    "apiBase": "http://localhost:8989/ollama"
  }
}
```

- [Quickstart guide - Continue](https://docs.codegate.ai/quickstart-continue)

### CodeGate Dashboard

![](/images/2025/CodeGate/dashboard.png)
