mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-04-19 17:16:48 +00:00
Update the package correctly
This commit is contained in:
parent
6d9b91bb76
commit
d1491f0083
3 changed files with 1304 additions and 1310 deletions
6
dist/index.js
vendored
6
dist/index.js
vendored
|
@ -51,6 +51,7 @@ const minimatch_1 = __importDefault(__nccwpck_require__(2002));
|
||||||
const GITHUB_TOKEN = core.getInput("GITHUB_TOKEN");
|
const GITHUB_TOKEN = core.getInput("GITHUB_TOKEN");
|
||||||
const OPENAI_API_KEY = core.getInput("OPENAI_API_KEY");
|
const OPENAI_API_KEY = core.getInput("OPENAI_API_KEY");
|
||||||
const OPENAI_API_MODEL = core.getInput("OPENAI_API_MODEL");
|
const OPENAI_API_MODEL = core.getInput("OPENAI_API_MODEL");
|
||||||
|
const OPENAI_JSON_MODE = core.getInput("OPENAI_JSON_MODE");
|
||||||
const octokit = new rest_1.Octokit({ auth: GITHUB_TOKEN });
|
const octokit = new rest_1.Octokit({ auth: GITHUB_TOKEN });
|
||||||
const openai = new openai_1.default({
|
const openai = new openai_1.default({
|
||||||
apiKey: OPENAI_API_KEY,
|
apiKey: OPENAI_API_KEY,
|
||||||
|
@ -107,7 +108,7 @@ function analyzeCode(parsedDiff, prDetails) {
|
||||||
}
|
}
|
||||||
function createPrompt(file, chunk, prDetails) {
|
function createPrompt(file, chunk, prDetails) {
|
||||||
return `Your task is to review pull requests. Instructions:
|
return `Your task is to review pull requests. Instructions:
|
||||||
- Provide the response in following JSON format: {"reviews": [{"lineNumber": <line_number>, "reviewComment": "<review comment>"}]}
|
- Reply in the JSON format without triple backticks: {"reviews": [{"lineNumber": <line_number>, "reviewComment": "<review comment>"}]}
|
||||||
- Do not give positive comments or compliments.
|
- Do not give positive comments or compliments.
|
||||||
- Provide comments and suggestions ONLY if there is something to improve, otherwise "reviews" should be an empty array.
|
- Provide comments and suggestions ONLY if there is something to improve, otherwise "reviews" should be an empty array.
|
||||||
- Write the comment in GitHub Markdown format.
|
- Write the comment in GitHub Markdown format.
|
||||||
|
@ -146,7 +147,7 @@ function getAIResponse(prompt) {
|
||||||
presence_penalty: 0,
|
presence_penalty: 0,
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const response = yield openai.chat.completions.create(Object.assign(Object.assign(Object.assign({}, queryConfig), (OPENAI_API_MODEL === "gpt-4-1106-preview"
|
const response = yield openai.chat.completions.create(Object.assign(Object.assign(Object.assign({}, queryConfig), (OPENAI_JSON_MODE === "true"
|
||||||
? { response_format: { type: "json_object" } }
|
? { response_format: { type: "json_object" } }
|
||||||
: {})), { messages: [
|
: {})), { messages: [
|
||||||
{
|
{
|
||||||
|
@ -155,6 +156,7 @@ function getAIResponse(prompt) {
|
||||||
},
|
},
|
||||||
] }));
|
] }));
|
||||||
const res = ((_b = (_a = response.choices[0].message) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.trim()) || "{}";
|
const res = ((_b = (_a = response.choices[0].message) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.trim()) || "{}";
|
||||||
|
console.log("AI Response:", res);
|
||||||
return JSON.parse(res).reviews;
|
return JSON.parse(res).reviews;
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
|
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
12
src/main.ts
12
src/main.ts
|
@ -140,16 +140,8 @@ async function getAIResponse(prompt: string): Promise<Array<{
|
||||||
});
|
});
|
||||||
|
|
||||||
const res = response.choices[0].message?.content?.trim() || "{}";
|
const res = response.choices[0].message?.content?.trim() || "{}";
|
||||||
// Remove lines ```json and ``` from the response
|
console.log("AI Response:", res);
|
||||||
const jsonStart = res.indexOf("{");
|
return JSON.parse(res).reviews;
|
||||||
const jsonEnd = res.lastIndexOf("}");
|
|
||||||
if (jsonStart === -1 || jsonEnd === -1) {
|
|
||||||
console.error("Error: JSON not found in response: " + res);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const jsonRes = res.substring(jsonStart, jsonEnd + 1);
|
|
||||||
console.log("AI Response:", jsonRes);
|
|
||||||
return JSON.parse(jsonRes).reviews;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error:", error);
|
console.error("Error:", error);
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue