SanthoshSiddegowda/kaavhi-core

GitHub: SanthoshSiddegowda/kaavhi-core

Kaavhi-core是一个基于FastAPI和Google Gemini的开源AI代码审查后端,通过分析diff文件提供结构化的代码审查意见和PR摘要。

Stars: 0 | Forks: 0

# Kaavhi AI 代码审查后端 [![Protected by Gitleaks](https://img.shields.io/badge/protected%20by-gitleaks-blue)](https://github.com/gitleaks/gitleaks) [![Tests](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/2289518415191424.svg)](https://github.com/SanthoshSiddegowda/kaavhi-core/actions/workflows/tests.yml) 本仓库包含 [Kaavhi](https://kaavhi.com/) 的开源核心,这是一款 AI 驱动的代码审查助手。我们的使命是帮助开发者编写更好、更安全、更整洁的代码,同时不牺牲控制权或数据隐私。 作为我们对透明度和信任承诺的一部分,我们的核心审查逻辑是开源的。您可以检查代码,以验证我们绝不存储您的代码并安全地处理您的数据。 ## 工作原理 1. **接收 diff**:API 接受统一 diff 作为**上传文件** (`multipart/form-data`)。 2. **AI 分析**:通过官方 [`google-genai`](https://googleapis.github.io/python-genai/) SDK(异步)将 diff 发送到 **Google Gemini**。模型返回由 Pydantic schemas 约束的 **结构化 JSON**:包含 **AI Pull Request 摘要**以及**行级评论**。 3. **返回 JSON**:响应包含 `summary`(概述、关键更改、审查重点)和 `comments`(问题及建议,包含严重性、置信度和代码建议)。 默认模型 ID 配置在 `app/integrations/gemini.py` 中(当前为 `gemini-3-flash-preview`)。您可以在那里更改它以匹配您的 API 访问权限。 ## 快速开始 ### 前置条件 - Python 3.9+ - 一个 [Gemini API key](https://ai.google.dev/gemini-api/docs/api-key) ### 安装 1. **克隆仓库:** git clone git@github.com:SanthoshSiddegowda/kaavhi-core.git cd kaavhi-core 2. **创建虚拟环境并安装依赖:** python -m venv venv source venv/bin/activate pip install -r requirements.txt 3. **设置环境变量** 在项目根目录创建一个 `.env` 文件: GEMINI_API_KEY="your-gemini-api-key" ### 运行服务器 ``` uvicorn app.main:app --reload ``` 服务器监听地址为 `http://localhost:8000`。 ## API 使用 ### POST /review/diff 接受一个包含 diff 文本的 **file** 字段(而非 JSON 主体)。 | 项目 | 值 | |------|--------| | Method | `POST` | | Content-Type | `multipart/form-data` | | Field | `file` — `.diff` / patch 文件 | **示例 (curl):** ``` curl -X POST "http://localhost:8000/review/diff" \ -F "file=@./my-changes.diff" ``` **成功响应 (`200 OK`)** ``` { "comments": [ { "id": "1", "type": "suggestion", "severity": "low", "line": 3, "code": "+ const newVar = 2;", "comment": "Variable renamed; ensure all references are updated.", "suggestion": "const newVar = 2;", "confidence": 90, "filePath": "src/file.js" } ], "summary": { "overview": "Short plain-language description of what the PR changes and why it matters.", "keyChanges": [ "Renamed a variable in `src/file.js` for clarity." ], "focus": [ "Double-check all imports and references to the old name." ] } } ``` - **`summary.overview`** — 面向审查者的简单 PR 级上下文(特别是在没有 PR 描述时)。 - **`summary.keyChanges`** — 关于更改内容的事实性要点。 - **`summary.focus`** — 值得深入审查的领域(风险、契约、复杂逻辑等)。 每条评论的 **`filePath`** 应相对于仓库,取自 diff 中的 `+++ b/path/to/file` 头部(即 `b/` 之后的路径)。 ### GET / 健康检查 — 返回 `{ "status": "ok" }`。 ## CORS 自定义 CORS 中间件允许: - `http://localhost:8080`(本地前端) - `kaavhi.com` 及其子域名上的 `https://` 和 `http://` 源 请参阅 `app/middleware/cors.py` 以调整允许的源。 ## 贡献 我们欢迎贡献。请参阅 [CONTRIBUTING.md](CONTRIBUTING.md)。 ## 许可证 MIT — 请参阅 [LICENSE](LICENSE)。 ## 项目结构 - `app/main.py` — FastAPI 应用,CORS,路由挂载 - `app/api/v1/review.py` — `/review/diff` 端点 - `app/integrations/gemini.py` — Gemini 客户端,提示词,结构化输出 - `app/models/review.py` — Pydantic 模型(`ReviewResponse`, `PullRequestSummary`, `ReviewComment`) - `app/services/review_service.py` — 审查编排 - `app/middleware/` — CORS 中间件 - `app/config/` — 设置(例如 `GEMINI_API_KEY`) - `requirements.txt` — 依赖项(`fastapi`, `google-genai`, `python-multipart` 等) - `tests/` — `pytest` 套件 ## 发布 请参阅 [GitHub Releases](https://github.com/SanthoshSiddegowda/kaavhi-core/releases) 获取版本说明(例如 **v1.2.0**:摘要 + 重点、结构化 Gemini 输出、中间件布局)。
标签:API, AV绕过, FastAPI, Gemini API, Pydantic, Python, REST API, SOC Prime, 云安全监控, 人工智能, 代码安全, 代码审查, 代码建议, 助手, 大模型, 安全规则引擎, 开发工具, 开源, 无后门, 漏洞枚举, 用户模式Hook绕过, 网络安全, 自动化代码分析, 逆向工具, 隐私保护, 静态分析