Built new version.

This commit is contained in:
Luke Hollenback 2024-04-02 15:22:50 -06:00
commit 573f4982a1
2 changed files with 12 additions and 6 deletions

16
dist/index.js vendored
View file

@ -85,14 +85,14 @@ function getDiff(owner, repo, pull_number) {
return response.data;
});
}
function analyzeCode(parsedDiff, prDetails) {
function analyzeCode(parsedDiff, prDetails, customPrompts) {
return __awaiter(this, void 0, void 0, function* () {
const comments = [];
for (const file of parsedDiff) {
if (file.to === "/dev/null")
continue; // Ignore deleted files
for (const chunk of file.chunks) {
const prompt = createPrompt(file, chunk, prDetails);
const prompt = createPrompt(file, chunk, prDetails, customPrompts);
const aiResponse = yield getAIResponse(prompt);
if (aiResponse) {
const newComments = createComment(file, chunk, aiResponse);
@ -105,7 +105,7 @@ function analyzeCode(parsedDiff, prDetails) {
return comments;
});
}
function createPrompt(file, chunk, prDetails) {
function createPrompt(file, chunk, prDetails, customPrompts) {
return `Your task is to review pull requests. Instructions:
- Provide the response in following JSON format: {"reviews": [{"lineNumber": <line_number>, "reviewComment": "<review comment>"}]}
- Do not give positive comments or compliments.
@ -113,6 +113,7 @@ function createPrompt(file, chunk, prDetails) {
- Write the comment in GitHub Markdown format.
- Use the given description only for the overall context and only comment the code.
- IMPORTANT: NEVER suggest adding comments to the code.
${customPrompts}
Review the following code diff in the file "${file.to}" and take the pull request title and description into account when writing the response.
@ -146,7 +147,7 @@ function getAIResponse(prompt) {
presence_penalty: 0,
};
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_API_MODEL === "gpt-4-turbo-preview" || OPENAI_API_MODEL === "gpt-4-turbo" || OPENAI_API_MODEL === "gpt-3.5-turbo" || OPENAI_API_MODEL === "gpt-4-0125-preview" || OPENAI_API_MODEL === "gpt-4-1106-preview" || OPENAI_API_MODEL === "gpt-3.5-turbo-0125" || OPENAI_API_MODEL === "gpt-3.5-turbo-1106"
? { response_format: { type: "json_object" } }
: {})), { messages: [
{
@ -154,7 +155,9 @@ function getAIResponse(prompt) {
content: prompt,
},
] }));
console.log(`Completions Response Object: ${response}`);
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(`Trimmed Response Message: ${res}`);
return JSON.parse(res).reviews;
}
catch (error) {
@ -225,7 +228,10 @@ function main() {
const filteredDiff = parsedDiff.filter((file) => {
return !excludePatterns.some((pattern) => { var _a; return (0, minimatch_1.default)((_a = file.to) !== null && _a !== void 0 ? _a : "", pattern); });
});
const comments = yield analyzeCode(filteredDiff, prDetails);
const customPrompts = core.getMultilineInput("custom_prompts")
.map(customPrompt => `- ${customPrompt}`)
.join("\n");
const comments = yield analyzeCode(filteredDiff, prDetails, customPrompts);
if (comments.length > 0) {
yield createReviewComment(prDetails.owner, prDetails.repo, prDetails.pull_number, comments);
}

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long