Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the ai output #5

Merged
merged 4 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/code_review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3
- name: Code Review
uses: freeedcom/ai-codereviewer@main
uses: freeedcom/ai-codereviewer@improve-the-AI-output

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a specific version or commit hash instead of the branch name improve-the-AI-output to ensure stability and reproducibility of the workflow.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider pinning the action version to a specific release or commit instead of using the branch name improve-the-AI-output. This ensures stability and prevents unexpected behavior changes in the future.

with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
Expand Down
11 changes: 7 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ function analyzeCode(parsedDiff, prDetails) {
}
function createPrompt(file, chunk, prDetails) {
return `- Provide the response in following JSON format: [{"lineNumber": <line_number>, "reviewComment": "<review comment>"}]
- Do not give positive comments or compliments.
- Do not suggest commenting on the code.
- Provide comments and suggestions ONLY if there is something to improve, otherwise return an empty array.
- Write the comment in GitHub markdown.
- Don't give positive comments.
- Use the given description only for the overall context and only comment the code.
- Calculate the line number from \`@@ -WW,XX +YY,ZZ @@\` using following formula: \`YY + L = line_number\`, where \`YY\` is the starting line number from the diff hunk, and \`L\` is the number of lines (including unchanged lines) from the starting line until the line you want to comment on. Pay special attention to this instruction and ensure that you count lines accurately.


Review the following code diff in the file "${file.to}" and take the pull request title and description into account when writing the response.

Pull request title: ${prDetails.title}
Expand All @@ -124,7 +124,10 @@ Git diff to review:

\`\`\`diff
${chunk.content}
${chunk.changes.map((c) => c.content).join("\n")}
${chunk.changes
// @ts-expect-error - ln and ln2 exists where needed
.map((c) => `${c.ln ? `${c.ln} ` : `${c.ln2} `}${c.content}`)
.join("\n")}
\`\`\`
`;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ async function analyzeCode(

function createPrompt(file: File, chunk: Chunk, prDetails: PRDetails): string {
return `- Provide the response in following JSON format: [{"lineNumber": <line_number>, "reviewComment": "<review comment>"}]
- Do not give positive comments or compliments.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider rephrasing this line to: - Avoid providing positive comments or compliments. for better clarity.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider rephrasing this line to: - Avoid giving positive comments or compliments. for better clarity.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider rephrasing the sentence to avoid using a double negative: 'Avoid giving positive comments or compliments.'

- Do not suggest commenting on the code.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider rephrasing this line to: - Refrain from suggesting to comment on the code. for better clarity.

- Provide comments and suggestions ONLY if there is something to improve, otherwise return an empty array.
- Write the comment in GitHub markdown.
- Don't give positive comments.
- Use the given description only for the overall context and only comment the code.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line seems to be removed, but it contains important information about calculating line numbers. Consider adding it back or incorporating the information into another part of the instructions.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line seems to be removed, but it contains important information about calculating the line number. Consider adding it back or incorporating the information in another part of the instructions.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line seems to be removed, but it contains important information about calculating line numbers. Consider keeping this instruction or incorporating it into another part of the prompt.

- Calculate the line number from \`@@ -WW,XX +YY,ZZ @@\` using following formula: \`YY + L = line_number\`, where \`YY\` is the starting line number from the diff hunk, and \`L\` is the number of lines (including unchanged lines) from the starting line until the line you want to comment on. Pay special attention to this instruction and ensure that you count lines accurately.


Review the following code diff in the file "${
file.to
}" and take the pull request title and description into account when writing the response.
Expand All @@ -101,7 +101,10 @@ Git diff to review:

\`\`\`diff
${chunk.content}
${chunk.changes.map((c) => c.content).join("\n")}
${chunk.changes
// @ts-expect-error - ln and ln2 exists where needed
.map((c) => `${c.ln ? `${c.ln} ` : `${c.ln2} `}${c.content}`)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a comment to explain the purpose of the @ts-expect-error directive and why it's necessary in this case.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a ternary operator instead of two separate string templates for better readability: ${c.ln ? c.ln : c.ln2} ${c.content}.

.join("\n")}
\`\`\`
`;
}
Expand Down