mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-09-10 03:37:08 +00:00
add system prompt path injection
This commit is contained in:
parent
a9a064dfa1
commit
500d731062
3 changed files with 31 additions and 2 deletions
|
@ -15,6 +15,10 @@ inputs:
|
||||||
description: "Glob patterns to exclude files from the diff analysis"
|
description: "Glob patterns to exclude files from the diff analysis"
|
||||||
required: false
|
required: false
|
||||||
default: ""
|
default: ""
|
||||||
|
system_prompt_path:
|
||||||
|
description: "Path to a file in the repository containing additional system prompt instructions"
|
||||||
|
required: false
|
||||||
|
default: ""
|
||||||
runs:
|
runs:
|
||||||
using: "node16"
|
using: "node16"
|
||||||
main: "dist/index.js"
|
main: "dist/index.js"
|
||||||
|
|
|
@ -24,5 +24,6 @@
|
||||||
"@vercel/ncc": "^0.36.1",
|
"@vercel/ncc": "^0.36.1",
|
||||||
"prettier": "^2.8.6",
|
"prettier": "^2.8.6",
|
||||||
"typescript": "^5.0.2"
|
"typescript": "^5.0.2"
|
||||||
}
|
},
|
||||||
|
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
||||||
}
|
}
|
||||||
|
|
26
src/main.ts
26
src/main.ts
|
@ -1,4 +1,5 @@
|
||||||
import { readFileSync } from "fs";
|
import { readFileSync } from "fs";
|
||||||
|
import { existsSync } from "fs";
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import OpenAI from "openai";
|
import OpenAI from "openai";
|
||||||
import { Octokit } from "@octokit/rest";
|
import { Octokit } from "@octokit/rest";
|
||||||
|
@ -8,6 +9,7 @@ import minimatch from "minimatch";
|
||||||
const GITHUB_TOKEN: string = core.getInput("GITHUB_TOKEN");
|
const GITHUB_TOKEN: string = core.getInput("GITHUB_TOKEN");
|
||||||
const OPENAI_API_KEY: string = core.getInput("OPENAI_API_KEY");
|
const OPENAI_API_KEY: string = core.getInput("OPENAI_API_KEY");
|
||||||
const OPENAI_API_MODEL: string = core.getInput("OPENAI_API_MODEL");
|
const OPENAI_API_MODEL: string = core.getInput("OPENAI_API_MODEL");
|
||||||
|
const SYSTEM_PROMPT_PATH: string = core.getInput("system_prompt_path");
|
||||||
|
|
||||||
const octokit = new Octokit({ auth: GITHUB_TOKEN });
|
const octokit = new Octokit({ auth: GITHUB_TOKEN });
|
||||||
|
|
||||||
|
@ -56,6 +58,25 @@ async function getDiff(
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function readSystemPrompt(): string {
|
||||||
|
if (!SYSTEM_PROMPT_PATH) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (existsSync(SYSTEM_PROMPT_PATH)) {
|
||||||
|
const systemPrompt = readFileSync(SYSTEM_PROMPT_PATH, "utf8");
|
||||||
|
return systemPrompt.trim();
|
||||||
|
} else {
|
||||||
|
console.warn(`System prompt file not found: ${SYSTEM_PROMPT_PATH}`);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error reading system prompt file ${SYSTEM_PROMPT_PATH}:`, error);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function analyzeCode(
|
async function analyzeCode(
|
||||||
parsedDiff: File[],
|
parsedDiff: File[],
|
||||||
prDetails: PRDetails
|
prDetails: PRDetails
|
||||||
|
@ -79,13 +100,16 @@ async function analyzeCode(
|
||||||
}
|
}
|
||||||
|
|
||||||
function createPrompt(file: File, chunk: Chunk, prDetails: PRDetails): string {
|
function createPrompt(file: File, chunk: Chunk, prDetails: PRDetails): string {
|
||||||
|
const systemPrompt = readSystemPrompt();
|
||||||
|
const additionalInstructions = systemPrompt ? `\n\nAdditional instructions from repository:\n${systemPrompt}\n` : "";
|
||||||
|
|
||||||
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>"}]}
|
- Provide the response in following JSON format: {"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.
|
||||||
- Use the given description only for the overall context and only comment the code.
|
- Use the given description only for the overall context and only comment the code.
|
||||||
- IMPORTANT: NEVER suggest adding comments to the code.
|
- IMPORTANT: NEVER suggest adding comments to the code.${additionalInstructions}
|
||||||
|
|
||||||
Review the following code diff in the file "${
|
Review the following code diff in the file "${
|
||||||
file.to
|
file.to
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue