2025-04-27 10:55:38 +08:00
2025-02-18 16:55:25 +08:00
2025-02-18 16:53:34 +08:00
2025-04-27 10:55:38 +08:00
2025-02-18 16:53:34 +08:00
2025-02-18 16:53:34 +08:00
2025-02-18 17:24:11 +08:00

ai-code-review

一个基于AI的代码审查工具支持多种Git平台和AI模型。

功能特点

  • 支持多个Git平台(GitLab、Gitee、Gogs等)
  • 支持多种AI模型(OpenAI、Ollama等)
  • 支持AI服务负载均衡
  • 提供Web界面进行配置管理
  • 支持自动禁用异常的AI服务

快速开始

  1. 下载并编译项目:
git clone https://github.com/your-username/ai-code-review.git
cd ai-code-review
go build
  1. 配置config.yaml:
port: 53321
admin_token: "your-admin-token" # 管理页面访问令牌
ais:
  - name: "your-ai"
    type: "ollama" # 或 "openai"
    api_key: ""
    url: "http://localhost:11434" # AI服务地址
    model: "your-model" # 使用的模型名称
    temperature: 0
    stream: false
    priority: 0    # 添加优先级配置
    system_msg: |
      你是一个代码审查员,你的职责是识别提交代码中的错误、性能问题和需要优化的地方。
      你还负责提供建设性的反馈,并建议最佳实践来提高代码的整体质量。

      在审查代码时:
      - 审查代码变更(差异)并提供反馈
      - 仔细检查是否真的存在错误或需要优化的空间,突出显示它们
      - 不要突出显示小问题和细节
      - 如果有多个评论,请使用要点符号
      - 你不需要解释代码的功能
      - 请使用中文给出反馈
      - 如果你认为不需要优化或修改,请只回复 666
    weight: 1
    enabled: true
    auto_disable: true  # 使用自己的自动禁用配置
    max_failures: 5     # 覆盖全局配置
    reset_after: 60     # 覆盖全局配置
git:
  - name: "your-git"
    type: "gitlab" # 或 "gitee", "gogs"
    token: "your-git-token"
    webhook_secret: "your-webhook-secret"
    api_base: "your-git-api-base"
    signature_header: X-Gitlab-Token
    event_header: X-Gitlab-Event
  1. 运行服务:
./ai-code-review
  1. 访问管理界面:
  • 打开浏览器访问 http://localhost:53321
  • 使用配置文件中的admin_token登录
  • 在Web界面中管理AI和Git平台配置
  1. 配置Git平台:
  • 在你的Git平台中添加Webhook
  • Webhook URL设置为: http://your-server:53321/api/webhook/git-name
  • 设置Webhook密钥与配置文件中的webhook_secret一致

注意事项

  • 请确保AI服务和Git平台的API地址可以正常访问
  • 妥善保管各类密钥和Token
  • 建议在生产环境中使用HTTPS
Description
No description provided
Readme 119 KiB
Languages
Go 65.6%
HTML 33.3%
Dockerfile 1.1%