Training an AI Community Manager using ChatGPT & OpenAI API
Published: 2023-03-04 17:59:58


## Introduction

AI has become a buzzword these days, with everyone trying to capitalize on its potential. But let's be honest, AI is still in its early stages and has a long way to go before it can match human intelligence. Nevertheless, it has already demonstrated its ability to revolutionize various industries and transform the way we interact with technology. In this article, we'll explore how we can use the power of OpenAI API and ChatGPT to train an AI community manager.

## OpenAI API

The OpenAI API has made AI accessible to everyone by providing access to pre-trained models like GPT-3. Developers can fine-tune these models for their specific needs and easily integrate them into their applications. This has enabled small startups and individual developers to leverage AI's power to create innovative products and services.

## Custom models in OpenAI (Fine-tuning)

While GPT-3 is a general-purpose solution for text tasks, it's not perfect for every use case. That's where custom models come in. OpenAI has launched a new API that allows you to fine-tune GPT-3 for your specific task. Fine-tuning GPT-3 requires a dataset in JSONL format, which is a simple way to store data.

For instance, suppose we want to train a custom model for a chatbot that can comprehend a user's mood. We can create a dataset in JSONL format like this:

```json
{"prompt": "User: Hello, how are you?\nBot:", "completion": " mood=good\n"}
{"prompt": "User: I'm feeling sad\nBot:", "completion": " mood=bad\n"}
{"prompt": "User: I'm feeling happy\nBot:", "completion": " mood=good\n"}
{"prompt": "User: I'm feeling angry\nBot:", "completion": " mood=bad\n"}
```

It's advisable to add whitespace at the beginning of the completion, as recommended in OpenAI documentation. Additionally, the completion must end with a newline, or else the model will generate an infinite stream of text that never ends.

## Generating a dataset for an Artificial Community Manager using ChatGPT

Our goal is to organize user messages in a parsable format. We need to determine if the user is asking a question and, if so, what type of question it is (e.g., `release_date`, `roadmap`, `token_address`, etc.). We can use ChatGPT to generate a dataset for custom OpenAI models.

We can show ChatGPT an example of a dataset and ask it to generate a new one. We can also give it detailed requests to help it understand our requirements. For example, we can show ChatGPT this request:

![image](https://raw.githubusercontent.com/bytesbay/articles/main/resources/5-2.jpg?v=2)

Here is ChatGPT's response:

![image](https://raw.githubusercontent.com/bytesbay/articles/main/resources/5-3.jpg?v=2)

After each ChatGPT response, we can ask it to generate a new one by simply typing "More" and it will generate additional variations. We can then save the generated dataset to `train.jsonl`.

Now let's save the generated dataset to `train.jsonl`:

## Training a model with a Python CLI

To train a model, we need to use Python with the OpenAI CLI. We can install it using pip:

```bash
pip install --upgrade openai
# for mac users
# sudo -H pip3 install openai
export OPENAI_API_KEY="<OPENAI_API_KEY>"
```

Now we can train a model using the dataset we just created. We won't use the `davinci` model since it's overkill for our task. We'll use a simpler `curie` model, which is sufficient for our structuring task:

```bash
openai api fine_tunes.create -t ./train.jsonl -m curie
```

We have to wait until the model is trained, which can take anywhere from 5 minutes to a couple of hours, depending on our luck (from my observations). Once the model is successfully trained, we'll see something like this:

```bash
[2023-03-03 17:21:12] Created fine-tune: ft-MuO9i1TAnKHkNLOoUNmmfSrc
[2023-03-03 17:29:23] Fine-tune costs $0.00
[2023-03-03 17:29:24] Fine-tune enqueued. Queue number: 0
[2023-03-03 17:29:25] Fine-tune started
[2023-03-03 17:30:27] Completed epoch 1/4
[2023-03-03 17:30:29] Completed epoch 2/4
[2023-03-03 17:30:31] Completed epoch 3/4
[2023-03-03 17:30:33] Completed epoch 4/4
[2023-03-03 17:30:56] Uploaded model: curie:ft-miro-2023-03-03-15-30-56
[2023-03-03 17:30:57] Uploaded result file: file-4mtjZQX9QavHpVQwZHZ2M3fc
[2023-03-03 17:30:57] Fine-tune succeeded

Job complete! Status: succeeded 🎉
```

## Testing the model

Now let's head to the OpenAI Playground to test our model. In the playground sidebar, select the model we just trained (e.g., `curie:ft-miro-2023-03-03-15-30-56`). Finally, let's enter a prompt in the textarea and hit the Submit button:

![image](https://raw.githubusercontent.com/bytesbay/articles/main/resources/5-4.jpg?v=2)

Voila! The completion is exactly what we were expecting.

## Conclusion

With a little bit of creativity, ChatGPT can help us move closer to a full AI singularity. By training an AI community manager, we can automate some of the more routine tasks associated with managing a community, such as answering frequently asked questions. However, it's crucial to be mindful of the potential limitations and ethical concerns when using AI to manage a community. Nevertheless, the potential benefits are enormous, and the future of AI is bright. So let's continue exploring the possibilities of AI and see where it takes us.

*With the new ChatGPT API, it's possible to fully automate the process of creating training datasets.