fortunai

I describe the process of using ChatGPT-3.5 to write a program that uses OpenAI's API. The program generates LLM fortunes a la the Unix command 'fortune'.

I wanted to play around with OpenAI’s API for ChatGPT, and I thought it would be fun to write a program to do so using ChatGPT. So ChatGPT and I wrote a program that generates ChatGPT fortunes—an LLM analog to the Unix fortune command.

In my mind, the most impressive thing was how general ChatGPT’s skills are. It interacted with me in plain English. It generated Python code and formatted it to PEP8 standards1. It generated Unix and git commands. It wrote a Markdown README, and in a section on configuration, it mentioned a file containing an API key—which was needed in the program. It correctly regurgitated and then re-formatted the MIT license. It proposed a “requirements.txt” file with the requests library after I incorrectly prompted it with the “response library”. It wrote the git commit message and GitHub project description. And it even named the program. On its second try, it came up with “fortunai”.

And of course, the program generated fortunes by pinging ChatGPT via its API. Here are two:

% fortunai
OpenAI: "Good things are coming your way. Stay positive and open to new opportunities.

% fortunai
OpenAI: You will soon receive unexpected good news.

These aren’t great, but the prompt to generate the fortunes was written by ChatGPT.

ChatGPT did struggle in two ways. First, it was not able to keep the entire program in its “working memory”. We wrote a complete and correct program together, but then I realized that it only worked in the Python file’s directory, since it used a relative path to load the file containing the API key. ChatGPT then wrote correct code to load the file using an absolute path, but it could not stitch this together with the previous version. It even started adding gibberish, such as importing the unnecessary openai_secret_manager. So the final version of the program required my intervention. I stitch together this new snippet with the original program.

And second, I tried to use ChatGPT to write this blog post, but the drafts it created were pretty bad. (I will continue to write my own posts, but here, I thought it would be fun if the entire process was done with ChatGPT’s help.) The drafts lacked detail about our conversation and sounded commerical, like a sales pitch. Here is an example:

In this project, I utilized ChatGPT, an advanced language model developed by OpenAI, to create Fortunai—a command-line fortune teller program. Leveraging Python, I collaborated with ChatGPT to implement a system that generates intriguing fortunes directly from the command line. By integrating the OpenAI API, I harnessed the model’s powerful language generation capabilities. Throughout the development process, ChatGPT provided invaluable guidance and code snippets, contributing to the refinement of the program. If you’re interested in exploring the captivating realm of Fortunai, you can find the complete code and resources on GitHub at [link-to-github].

On the one hand, the language is a bit much. Some words and phrases that jump out at me are “utilized”, “leveraging Python”, “harnessed”, “intriguing fortunes”, and “captivating realm”. On the other hand, this is impressive. A computer program writing in English to describe a computer program which it wrote in Python!

You can find the various assets (conversation log, code, README, etc.) in this GitHub repo.

The entire process took roughly an hour.

  1. I linted the program with flake8 and found that ChatGPT made one mistake, which was not using a variable it defined when catching an error.