Labeling by GPT
Tags: githubhack23, github, opensource, showdev
Published: 2023-05-21 16:17:24

--- 
title: Labeling by GPT
published: true 
description: Choose and puts suitable labels to an issue automatically with AI power! This is my submission to the GitHub + DEV Hackathon 2023! 
tags: githubhack23, github, opensource, showdev
--- 

## What I built 

I developed a GitHub Action that chooses suitable labels for an opened/edited issue and puts the labels to the issue automatically without predefined rules.

### Category Submission: 

Maintainer Must-Haves

### App Link

[Labeling by GPT · Actions · GitHub Marketplace](https://github.com/marketplace/actions/labeling-by-gpt)

### Screenshots 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s5zjsafnn61edoygeycs.png)

You can see [this issue](https://github.com/satoryu/labeling-by-gpt/issues/3) and try it by opening new issue!

### Description 

When an issue is opened/edited, this action reads its title and description, choose suitable labels in the repository and  add those labels to the issue. 

You don't need to define rules which issue should should have which labels in advance. 

### Link to Source Code 

{% embed https://github.com/satoryu/labeling-by-gpt %}

### Permissive License 

MIT License

## Background

In maintaining OSS projects, triage is an important activity. GitHub provides 'labeling issues' feature to help maintainers triage their repositories' issues. But triage is boring! As new issue is opened, maintainers have to read its title and description then choose suitable labels and add the labels to it. As issues in a repository increases, the workload of triage increases too. If there were few maintainers of the repo, triage would be impossible. 
GitHub Action has the possibility to reduce this workload. But maintainers would define rules　in advance in which condition and labels the action should choose and add to an issue. 

On the other hand, NLP is getting popular by ChatGPT, OpenAI APIs. OpenAI completion API processes several tasks to a given text 'prompt'. I came up with the idea that this API would help maintainers triage their issues. 

This is my motivation to develop this GitHub action. 

### How I built it

First, I had to confirm that OpenAI completion API works as I want: choose suitable labels from available labels in a repository. 
In order to do it, I used ChatGPT:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xrc5xxp1gukq30yvm71m.png)

Next, I implemented and test it on its repository. 
This is quite simple and easy: define a YAML file under `.github/workflows`. 

```yaml
on:
  issues:
    types: [opened, edited]

jobs:
  test:
    name: test
    runs-on: ubuntu-latest

    steps:
      - uses: satoryu/labeling-by-gpt@main
        with:
          openai-api-key: ${{ secrets.OPENAI_API_KEY }}
```

Specifying the main branch like `satoryu/labeling-by-gpt@main` not version (e.g. v0.0.1) always refers to the latest version of this action. This configuration is good for testing on GitHub. 

### Additional Resources/Info

- [About custom actions - GitHub Docs](https://docs.github.com/en/actions/creating-actions/about-custom-actions)
  - This doc gave me the basics how to implement an action in JavaScript.
- [hwchase17/langchain: ⚡ Building applications with LLMs through composability ⚡](https://github.com/hwchase17/langchain)
  - I've read some prompts in this code. The prompts give me some hints to implement a prompt of my github action.