Coder Social home page Coder Social logo

jschmid1 / chatgpt-action Goto Github PK

View Code? Open in Web Editor NEW

This project forked from unsafecoerce/chatgpt-action

0.0 0.0 0.0 5.2 MB

A collection of ChatGPT assistants, e.g., pull request scoring, code view, labeler, assigner, etc.

Home Page: https://github.com/marketplace/actions/chatgpt-action

License: Other

JavaScript 1.85% TypeScript 98.15%

chatgpt-action's Introduction

ChatGPT actions

A collection of ChatGPT assistants, e.g., code viewer, labeler, assigner, etc.

Overview

Why reinvent the wheel?

There're already many chatgpt-actions, why we need to reinvent the wheel?

  • Leave too much comments on Github pull requests

    Some of existing actions send each hunks in a pull request diff to ChatGPT, and yields a comment (or comment snippet) for each hunk. That makes them in practically unusable, as receiving 20+ email notification after submitting a pull request is not a good experience. For the reviewer's perspective, we usually just focus on the hunks that are "too good" or "too bad".

    This actions take such experience into consideration, and only leave comments for the hunks that are not "LGTM". (We do have an option to leave comments for good hunks as well).

  • Lack of customization of the prompt

    All of existing actions hard-coded the prompt template inside the source code and there's no chance to customize the prompt. When the built-in prompt is not good enough, ChatGPT responses with useless comments.

    At the same time, someone may have good prompt ideas, he/she want to try using ChatGPT as an AI assistant for code quality evaluation and review, but he/she needs to reinvent the wheel for a new action to play on Github.

    This action makes the prompt template configurable. With a set of variables like $title, $description, $filename, $patch, you can customize the message sent to ChatGPT for better experience.

    Prompt engineering is an art to make ChatGPT success, we encourage the community to try discovering new, novel, and insightful prompts to make ChatGPT do code review job better, without reinventing the wheel for another chatgpt-action.

    ANY SUGGESTIONS AND IMPROVEMENTS ARE HIGHLY APPRECIATED!!!

Features

  • Code review your pull requests

        - uses: jschmid1/chatgpt-action@main
          env:
            GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
            OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
          with:
            debug: false
            action: review
            review_comment_lgtm: true
  • Customizable prompt templates

        - uses: jschmid1/chatgpt-action@main
          env:
            GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
            OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
          with:
            debug: false
            action: review
            review_patch: |
              Hi ChatGPT, I have a pull request with title "$title" and the description is as follows,
    
              > $description
    
              This is the patch
    
              > $patch
    
              and here are the filenames:
    
              > $filename
    
              Do something custom with these

Usage

name: Code Review

permissions:
  contents: read
  pull-requests: write

on:
  pull_request:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          repository: ${{github.event.pull_request.head.repo.full_name}}
          ref: ${{github.event.pull_request.head.ref}}
          submodules: false

      - uses: jschmid1/chatgpt-action@main
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
        with:
          debug: false
          action: review
          review_comment_lgtm: true

Configuration

See also: ./action.yml

Environment variables

  • GITHUB_TOKEN
  • OPENAI_API_KEY: use this to authenticate with OpenAI API, official ChatGPT's API.

Inputs

  • action: The action to run, currently can be review
  • debug: Enable debug mode, will show messages and responses between ChatGPT server in CI logs.
  • review_comment_lgtm: Leave comments even the patch is LGTM
  • path_filters: Rules to filter files to be reviewed.

Prompt templates:

See also: ./action.yml

  • review_beginning: The beginning prompt of a code review dialog
  • review_patch: The prompt for each chunks/patches

Variables available in prompt templates

  • code review (action: review):

    • $title: Title of the pull requests.
    • $description: The description of the pull request.
    • $filename: Filename of the file being viewed.
    • $patch: The diff contents of the patch being viewed.

Any suggestions or pull requests for improving the prompts are highly appreciated.

Developing

First, you'll need to have a reasonably modern version of node handy, tested with node 16.

Install the dependencies

$ npm install

Build the typescript and package it for distribution

$ npm run build && npm run package

FAQs

Review pull request from forks

Github Actions limits the access of secrets from forked repositories. To enable this feature, you need to use the pull_request_target event instead of pull_request in your workflow file. Note that with pull_request_target, you need extra configuration to ensure checking out the right commit:

name: Code Review

permissions:
  contents: read
  pull-requests: write

on:
  pull_request_target:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          repository: ${{github.event.pull_request.head.repo.full_name}}
          ref: ${{github.event.pull_request.head.ref}}
          submodules: false

      - uses: jschmid1/chatgpt-action@main
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
        with:
          debug: false
          action: review
          review_comment_lgtm: true

Inspect the messages between ChatGPT server

Set debug: true in the workflow file to enable debug mode, which will show the messages

License

The MIT License (MIT), Courtesy to Tao He for most of the base code and the inspiration.

chatgpt-action's People

Contributors

sighingnow avatar dependabot[bot] avatar jschmid1 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.