diff --git a/package.json b/package.json index 824e761b..5ec57c86 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "@actions/core": "^1.10.0", "@octokit/rest": "^19.0.7", "minimatch": "^7.4.2", - "openai": "^3.2.1", + "openai": "^4.20.1", "parse-diff": "^0.11.1", "ts-node": "^10.9.1" }, diff --git a/src/main.ts b/src/main.ts index 474d6981..3f55d58b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,6 @@ import { readFileSync } from "fs"; import * as core from "@actions/core"; -import { Configuration, OpenAIApi } from "openai"; +import OpenAI from "openai"; import { Octokit } from "@octokit/rest"; import parseDiff, { Chunk, File } from "parse-diff"; import minimatch from "minimatch"; @@ -11,12 +11,10 @@ const OPENAI_API_MODEL: string = core.getInput("OPENAI_API_MODEL"); const octokit = new Octokit({ auth: GITHUB_TOKEN }); -const configuration = new Configuration({ +const openai = new OpenAI({ apiKey: OPENAI_API_KEY, }); -const openai = new OpenAIApi(configuration); - interface PRDetails { owner: string; repo: string; @@ -98,7 +96,7 @@ async function getBaseAndHeadShas( function createPrompt(file: File, chunk: Chunk, prDetails: PRDetails): string { return `Your task is to review pull requests. Instructions: -- Provide the response in following JSON format: [{"lineNumber": , "reviewComment": ""}] +- Provide the response in following JSON format: {"reviews": [{"lineNumber": , "reviewComment": ""}]} - Do not give positive comments or compliments. - Provide comments and suggestions ONLY if there is something to improve, otherwise return an empty array. - Write the comment in GitHub Markdown format. @@ -142,8 +140,12 @@ async function getAIResponse(prompt: string): Promise