freeedcom / ai-codereviewer

AI Code Reviewer: Enhance your GitHub workflow with AI-powered code review! Get intelligent feedback and suggestions on pull requests using OpenAI's GPT-4 API, improving code quality and saving developers time.
MIT License
643 stars 606 forks source link

Proposal: Batch AI Requests for Multiple Diffs in a Single File #98

Open drakejin opened 1 week ago

drakejin commented 1 week ago

@villesau @lfsevergnini

Proposal

Batch AI Requests for Multiple Diffs in a Single File

Description

I’ve developed code that allows us to send a single AI request for multiple diffs occurring within the same file, instead of making a separate request to ChatGPT for each diff. This should improve efficiency and reduce the number of API calls.

If you’re interested, I can create a PR to suggest this change.

check my prompt

function createPrompt(file: File, prDetails: PRDetails): string {
  return `

# Pull Request Details
### Pull Request Info
- title
  > ${prDetails.title}
- description
  > ${prDetails.description}

### Code for Review
- file
  > ${file.to}

- changes
  \`\`\`
   ${file.chunks.map((chunk) => chunk.content).join("\n")}
  \`\`\`

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

# Reviewing Guide

### Answer Role: Reviewer
You are the team leader of a development team. Your role is to review the code written by team members.

### Requirements, Reviewing Guide, Pull Request on GitHub
- For each code review, consider the title and description of the Pull Request.
- Include only severe code smells, security risks, potential bugs, and inefficient code.
- Write comments using GitHub Markdown format.
- Include only comments related to the code.
- Clearly state the rationale for your review.

### Don't Include
- Do not include vague statements like "considerations" or "points to review."
- Do not provide code reviews with a suggestive tone.
- Do not include positive comments or compliments about the code.
- Do not suggest adding comments to the code.

### Additional Requirements

${process.env.ADDITIONAL_REQUIREMENTS}

### Output Format
- Provide the response message in the following JSON format: {"reviews": [{"lineNumber": "<line_number>", "reviewComment": "<review_comment>"}]}
    - <line_number>
      - <line_number> means the code line number.
      - Refer to each code line number in '### Code for Review'.
      - If the line numbers are consecutive, indicate as a range. Example: "1-3"
      - If you cannot specify the code line number, exclude that review.
    - <review_comment>
      - <review_comment> means the review comment.
      - If <review_comment> is ambiguous, exclude that review.
- If there are no reviews for the code, set "reviews" as an empty array.
- The content of <review_comment> should be output in Korean.
`;
}
drakejin commented 1 week ago

Related issues:

https://github.com/freeedcom/ai-codereviewer/issues/70

drakejin commented 1 week ago

It appears that this project is no longer being actively maintained. I’d like to help keep it alive by forking the repository and continuing development, possibly releasing it as a GitHub Action. @villesau

I will, of course, adhere to the MIT License as specified.

Please let me know if you’re okay with this.

PS. I refered to Your linkedin and freeedcom SNS.

lfsevergnini commented 1 week ago

Hello @drakejin,

Yes. Please check out my fork: https://github.com/lfsevergnini/ai-codereviewer.

Your change is very welcome but would be great if you could rebase to my version because it has had some updates.

Let me know that you think. Feel free to fork it too, totally fine by me.

Edit: I'm not part of the team, but as you I wanted to do some updates.

drakejin commented 1 week ago

Oh, yours is much better! I’ll rebase my repository on yours and make a pull request. Was that your intention?

drakejin commented 1 week ago

How about this repo? Is this project stopped maintian?

lfsevergnini commented 1 week ago

Oh, yours is much better! I’ll rebase my repository on yours and make a pull request. Was that your intention?

Yep.

How about this repo? Is this project stopped maintian?

I don't know, it hasn't been responsive for months. It's been abandoned it seems.

I'll keep maintaining mine. I intend to add support to Claude soon and also code review in a single comment instead of in-line. Another thing in my radar is to leverage the big context windows and pass the files optionally, for better reviews.

drakejin commented 1 week ago

Great. I also need this. So I want to commit your ai-codereviewer project by PR. See you soon.