Skip to content
aperture

GitHub Action

OpenAI Chat on Issues

v1.1.1 Latest version

OpenAI Chat on Issues

aperture

OpenAI Chat on Issues

This is a GitHub Actions for running OpenAI's chat on GitHub Issues

Installation

Copy and paste the following snippet into your .yml file.

              

- name: OpenAI Chat on Issues

uses: snnaplab/[email protected]

Learn more about this action in snnaplab/openai-chat-on-issues

Choose a version

OpenAI Chat on Issues

This is a GitHub Actions for running OpenAI's chat on GitHub Issues.

Usage

Basic usage

  1. Prepare a yaml file that describes the workflow below.
  2. Place it in the default branch.
name: OpenAI Chat

on:
  issues:
    types: [opened]
  issue_comment:
    types: [created]

jobs:
  chat:
    name: Chat
    runs-on: ubuntu-latest
    steps:
      - uses: snnaplab/openai-chat-on-issues@v1
        with:
          openai-key: ${{ secrets.OPENAI_KEY }}
          model: 'gpt-4' # option, default is 'gpt-3.5-turbo'
          system-prompt: | # option
            You are a helpful assistant.

Available models are listed in Model endpoint compatibility ( This action use /v1/chat/completions endpoint ). However, it may depend on the circumstances of the account that issued the key.

Cancel existing response on new comment

name: OpenAI Chat

on:
  issues:
    types: [opened]
  issue_comment:
    types: [created]

concurrency: # add these
  group: ${{ github.workflow }}-${{ github.event.issue.number || github.run_id }}
  cancel-in-progress: true

...

Respond only to mentions

name: OpenAI Chat

on:
  issues:
    types: [opened]
  issue_comment:
    types: [created]

jobs:
  chat:
    name: Chat
    if: startsWith(github.event.issue.body, '/openai ') || startsWith(github.event.comment.body, '/openai ') # add this
    runs-on: ubuntu-latest
    steps:
      - uses: snnaplab/openai-chat-on-issues@v1
...

Respond only to issues with a specific title

name: OpenAI Chat

on:
  issues:
    types: [opened]
  issue_comment:
    types: [created]

jobs:
  chat:
    name: Chat
    if: contains(github.event.issue.title, 'openai') # add this
    runs-on: ubuntu-latest
    steps:
      - uses: snnaplab/openai-chat-on-issues@v1
...

Respond only to issues with a specific label

name: OpenAI Chat

on:
  issues:
    types: [opened]
  issue_comment:
    types: [created]

jobs:
  chat:
    name: Chat
    if: contains(github.event.issue.labels.*.name, 'openai') # add this
    runs-on: ubuntu-latest
    steps:
      - uses: snnaplab/openai-chat-on-issues@v1
...

Exclude comments containing specific keywords

Conversations between users, or comments you don't want AI to refer to.

name: OpenAI Chat

on:
  issues:
    types: [opened]
  issue_comment:
    types: [created]

jobs:
  chat:
    name: Chat
    runs-on: ubuntu-latest
    steps:
      - uses: snnaplab/openai-chat-on-issues@v1
        with:
          openai-key: ${{ secrets.OPENAI_KEY }}
          ignore-keywords: | # add these
            AI bot ignore

Required permissions

issues: write permission is required. If necessary, specify in the workflow as follows.

name: OpenAI Chat

on:
  issues:
    types: [opened]
  issue_comment:
    types: [created]

permissions: # add these
  issues: write

...  

Tips

It is convenient to prepare frequently used prompts as custom templates for issues. ref: Configuring issue templates for your repository

Other topics

Prevent jobs from starting on pull request comments

The issue_comment trigger fires even on pull request comments. This action is passed through, so there is no problem, but to prevent extra jobs from starting, do the following:

name: OpenAI Chat

on:
  issues:
    types: [opened]
  issue_comment:
    types: [created]

jobs:
  chat:
    name: Chat
    if: github.event.issue.pull_request == null # add this
    runs-on: ubuntu-latest
    steps:
      - uses: snnaplab/openai-chat-on-issues@v1
...

Blog post