本文将介绍如何利用さくら互联网提供的「さくらのAI Engine」构建PR-Agent。作为さくら互联网的一员,选择不使用这项技术是不可能的。
さくら的AI Engine是什么
さくら的生成AI平台「さくらのAI Engine」是一个服务,可以利用さくら互联网提供的生成AI模型。
「さくら的AI Engine」是一个按需计费的基础平台服务,可以使用各种生成AI模型。
所有支持的LLM模型都由さくら互联网进行托管,因此数据仅在客户与さくら互联网之间进行通信,
用于聊天补全等的数据不会用于LLM模型的学习,提供高数据安全性的服务。
因此,由于由国内企业提供服务,用户可以放心使用,而无需担心数据被发送至海外。
PR-Agent是什么
PR-Agent是一个工具,利用LLM(大规模语言模型)自动审查GitHub的拉取请求(PR)。PR-Agent可以理解代码的变更,指出潜在的问题和改进点。通过这个工具,开发者可以减轻代码审查的负担,更加专注于提高代码质量。
在さくら的AI Engine中使用PR-Agent
根据手册,获取さくらのAI Engine的账户令牌。
在使用PR-Agent的仓库中设置TOKEN
前往GitHub仓库的Settings > Secrets and variables > Actions,添加名为SAKURA_AI_ENGINE_API_KEY的秘密。
GitHub Actions的设置
PR-Agent通过GitHub Actions运行。在仓库的.github/workflows目录下创建以下YAML文件。
这次,我们使用Qwen3-Coder-480B-A35B-Instruct-FP8作为模型。
name: PR-Agent
on:
pull_request:
types: [opened, reopened, synchronize, ready_for_review]
issue_comment:
types: [created, edited]
workflow_dispatch:
permissions:
issues: write
pull-requests: write
contents: write
jobs:
pr_agent_job:
runs-on: ubuntu-latest
name: 在每个拉取请求上运行pr代理
steps:
- name: PR Agent action step
id: pragent
uses: qodo-ai/pr-agent@main
env:
OPENAI_KEY: ${{ secrets.SAKURA_AI_ENGINE_API_KEY }}
OPENAI__API_BASE: https://api.ai.sakura.ad.jp/v1
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
github_action_config.auto_review: "true"
github_action_config.auto_describe: "true"
github_action_config.auto_improve: "true"
config.model: "openai/Qwen3-Coder-480B-A35B-Instruct-FP8"
config.custom_model_max_tokens: "100000"
config.fallback_models: '[ "openai/Qwen3-Coder-480B-A35B-Instruct-FP8" ]'
pr_reviewer.extra_instructions: >-
请用中文回答。
pr_description.extra_instructions: >-
请用中文回答。
pr_code_suggestions.extra_instructions: >-
请用中文回答。
pr_code_suggestions.num_code_suggestions: "2"
注意:不在模型名称前添加openai/作为前缀的话,PR-Agent将无法识别。
实际操作
PR-Agent的GitHub Actions会被触发,自动为拉取请求添加审查评论。接着,我们创建一个main.go文件并生成PR,以便看看效果。
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
func handler(w http.ResponseWriter, r *http.Request) {
name := r.URL.Query().Get("name")
if name == "" {
name = "World"
}
body, err := ioutil.ReadAll(r.Body)
if err != nil {
http.Error(w, "无法读取请求体", http.StatusBadRequest)
return
}
r.Body.Close()
fmt.Fprintf(w, "你好, %s!", name)
fmt.Fprintf(w, "\n你发送的内容: %s", string(body))
}
func calculate(x int, y int) int {
result := x + y
return result
}
func processData(data []string) {
for _, item := range data {
fmt.Println(item)
}
}
创建PR后,PR-Agent的CI将运行。
过一会儿,PR的描述和审查评论将被添加。
总结
- 测试仓库
- 通通过PR-Agent与さくら的AI Engine实现了代码审查的自动化
- さくら的AI Engine是一个国内的生成AI平台,具有高数据安全性
- 相较于使用OpenAI的API,不会有数据发送到国外的风险(从心理上也更为安心)




