Use Responses API for reviews

This commit is contained in:
lezi-fun committed 2026-05-12 22:23:19 +08:00
1 parent 42853077c7
commit 363b218b0e
7 files changed
+54 -22

No files matched your search

+6
View File
@@ -7,7 +7,11 @@ const configSchema = z.object({
githubAppId: z.coerce.number().int().positive(),
githubPrivateKey: z.string().min(1).transform((value) => value.replace(/\\n/g, "\n")),
openAiApiKey: z.string().min(1),
openAiBaseUrl: z.string().url().optional(),
openAiModel: z.string().min(1).default("gpt-4.1"),
openAiReasoningEffort: z.enum(["default", "low", "medium", "high"]).optional().transform((value) => {
return value === "default" ? undefined : value;
}),
botName: z.string().min(1).default("ghbot"),
lenientApprovalUser: z.string().min(1).default("lezi-fun"),
autoMerge: z.coerce.boolean().default(false),
@@ -22,7 +26,9 @@ export const config = configSchema.parse({
githubAppId: process.env.GITHUB_APP_ID,
githubPrivateKey: process.env.GITHUB_PRIVATE_KEY,
openAiApiKey: process.env.OPENAI_API_KEY,
openAiBaseUrl: process.env.OPENAI_BASE_URL,
openAiModel: process.env.OPENAI_MODEL,
openAiReasoningEffort: process.env.OPENAI_REASONING_EFFORT,
botName: process.env.BOT_NAME,
lenientApprovalUser: process.env.LENIENT_APPROVAL_USER,
autoMerge: process.env.AUTO_MERGE,
+12 -11
View File
@@ -20,7 +20,10 @@ const reviewDecisionSchema = z.object({
});
export class OpenAiReviewer {
private readonly client = new OpenAI({ apiKey: config.openAiApiKey });
private readonly client = new OpenAI({
apiKey: config.openAiApiKey,
baseURL: config.openAiBaseUrl
});
async review(input: {
title: string;
@@ -28,13 +31,14 @@ export class OpenAiReviewer {
files: PullRequestFile[];
mode: ReviewMode;
}): Promise<ReviewDecision> {
const response = await this.client.chat.completions.create({
const response = await this.client.responses.create({
model: config.openAiModel,
temperature: 0.1,
response_format: {
type: "json_schema",
json_schema: {
...(config.openAiReasoningEffort ? { reasoning: { effort: config.openAiReasoningEffort } } : {}),
text: {
format: {
name: "pull_request_review",
type: "json_schema",
strict: true,
schema: {
type: "object",
@@ -64,11 +68,8 @@ export class OpenAiReviewer {
}
}
},
messages: [
{
role: "system",
content: buildSystemPrompt(input.mode)
},
instructions: buildSystemPrompt(input.mode),
input: [
{
role: "user",
content: JSON.stringify({
@@ -88,7 +89,7 @@ export class OpenAiReviewer {
]
});
const raw = response.choices[0]?.message.content;
const raw = response.output_text;
if (!raw) {
throw new Error("OpenAI returned an empty review response.");
}