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
479 stars 439 forks source link

Added custom prompt support. #59

Open lukehollenback opened 3 months ago

lukehollenback commented 3 months ago

This pull request adds custom command support to the prompt passed to the LLM when asking it to review files.

In a repository's workflow configuration file for AI Code Reviewer, one can use multiline YAML to specify said custom commands in the custom_prompt input. For example, see the bottom of →

name: Code Review with OpenAI
on:
  pull_request:
    types:
      - opened
      - synchronize
      - ready_for_review
permissions: write-all
jobs:
  code_review:
    if: '! github.event.pull_request.draft'
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
      - name: Code Review
        uses: lukehollenback/ai-codereviewer@main-luke
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
          OPENAI_API_MODEL: "gpt-4-turbo-preview"
          exclude: "yarn.lock, dist/**, **/*.json, **/*.md, **/*.yaml, **/*.xml"
          custom_prompts: |
            Do not worry about the verbosity of variable names, as long as they are somewhat descriptive.
            Be sure to call out potential null pointer exceptions.

Tested over in https://github.com/lukehollenback/ai-codereviewer/pull/4 — see executed checks.