Skip to content

Commit

Permalink
feat: improve prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
fiqryq committed May 19, 2024
1 parent 1423fb6 commit 5fea0cd
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
Expand Down

0 comments on commit 5fea0cd

Please sign in to comment.