mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-06-29 12:24:16 +00:00
chore: fix formatting issues in main.ts file
This commit is contained in:
parent
271056abf4
commit
977935fd5e
1 changed files with 53 additions and 54 deletions
27
src/main.ts
27
src/main.ts
|
@ -1,8 +1,8 @@
|
|||
import { readFileSync } from "fs";
|
||||
import {readFileSync} from "fs";
|
||||
import * as core from "@actions/core";
|
||||
import OpenAI from "openai";
|
||||
import { Octokit } from "@octokit/rest";
|
||||
import parseDiff, { Chunk, File } from "parse-diff";
|
||||
import {Octokit} from "@octokit/rest";
|
||||
import parseDiff, {Chunk, File} from "parse-diff";
|
||||
import minimatch from "minimatch";
|
||||
import {parseJsonForChatGPTResponse} from "./parseJsonForChatGPTResponse";
|
||||
|
||||
|
@ -10,11 +10,11 @@ const GITHUB_TOKEN: string = core.getInput("GITHUB_TOKEN");
|
|||
const OPENAI_API_KEY: string = core.getInput("OPENAI_API_KEY");
|
||||
const OPENAI_API_MODEL: string = core.getInput("OPENAI_API_MODEL");
|
||||
|
||||
const octokit = new Octokit({ auth: GITHUB_TOKEN });
|
||||
const octokit = new Octokit({auth: GITHUB_TOKEN});
|
||||
|
||||
const openai = new OpenAI({
|
||||
apiKey: OPENAI_API_KEY,
|
||||
});
|
||||
});
|
||||
|
||||
interface PRDetails {
|
||||
owner: string;
|
||||
|
@ -25,7 +25,7 @@ interface PRDetails {
|
|||
}
|
||||
|
||||
async function getPRDetails(): Promise<PRDetails> {
|
||||
const { repository, number } = JSON.parse(
|
||||
const {repository, number} = JSON.parse(
|
||||
readFileSync(process.env.GITHUB_EVENT_PATH || "", "utf8")
|
||||
);
|
||||
const prResponse = await octokit.pulls.get({
|
||||
|
@ -51,7 +51,7 @@ async function getDiff(
|
|||
owner,
|
||||
repo,
|
||||
pull_number,
|
||||
mediaType: { format: "diff" },
|
||||
mediaType: {format: "diff"},
|
||||
});
|
||||
// @ts-expect-error - response.data is a string
|
||||
return response.data;
|
||||
|
@ -128,12 +128,13 @@ async function getAIResponse(prompt: string): Promise<Array<{
|
|||
presence_penalty: 0,
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await openai.chat.completions.create({
|
||||
const response =
|
||||
await openai.chat.completions.create(
|
||||
{
|
||||
...queryConfig,
|
||||
// return JSON if the model supports it:
|
||||
...(OPENAI_API_MODEL === "gpt-4-1106-preview"
|
||||
? { response_format: { type: "json_object" } }
|
||||
? {response_format: {type: "json_object"}}
|
||||
: {}),
|
||||
messages: [
|
||||
{
|
||||
|
@ -144,11 +145,9 @@ async function getAIResponse(prompt: string): Promise<Array<{
|
|||
});
|
||||
|
||||
const res = response.choices[0].message?.content?.trim() || "{}";
|
||||
console.log("GPT response:")
|
||||
console.log(res);
|
||||
return parseJsonForChatGPTResponse(res).reviews;
|
||||
} catch (error) {
|
||||
console.error("Error:", error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function createComment(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue