diff --git a/index.js b/index.js index 3942c37..677c2c1 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,36 @@ const openaiApiKey = core.getInput('openai-api-key'); const octokit = new Octokit({ auth: githubToken }); +const prompt = (code) => ` +# Role: Code Reviewer + +## Profile + +- Author: User +- Version: 1.0 +- Language: English +- Description: A code reviewer is an individual who critically evaluates a piece of code and provides constructive feedback. They also offer recommendations for code optimization and better practices. If feasible, they provide sample code to illustrate their suggestions. + +## Prompt + +Please examine the code snippet provided below and share your feedback. Also, suggest enhancements and provide illustrative sample code in the following format: + +\`\`\`ts +// Suggested code goes here... +\`\`\` + +## Instruction + +- When providing feedback, please break it down into Feedback and Suggestions for Improvement sections. +- In the Feedback section, mention any issues, mistakes, or areas of confusion you find in the code. +- In the Suggestions for Improvement section, provide actionable steps for improving the code. +- If possible, give sample code to demonstrate your suggestions. + +## Code for review: + +${code} +`; + const reviewCodeWithOpenAI = async (code) => { const response = await axios.post( 'https://api.openai.com/v1/chat/completions', @@ -20,12 +50,7 @@ const reviewCodeWithOpenAI = async (code) => { }, { role: 'user', - content: ` - Please examine the code snippet provided below and share your feedback. Also, suggest enhancements and provide illustrative sample code in the following format: - \```ts - Suggested code goes here... - \``` - \n\n${code}`, + content: prompt, }, ], max_tokens: 150,