Hobbyist builds ChatGPT client for MS-DOS
On Sunday, Singapore-based retrocomputing enthusiast Yeo Kheng Meng released a ChatGPT client for MS-DOS that can run on a 4.77 MHz IBM PC from 1981, providing a unique way to converse with the popular OpenAI language model.
Vintage computer development projects come naturally to Yeo, who created a Slack client for Windows 3.1 in 2019. “I thought to try something different this time and develop for an even older platform as a challenge,” he writes on his blog. In this case, he turned his attention to MS-DOS, a text-only operating system first released in 1981, and ChatGPT, an AI-powered large language model (LLM) released by OpenAI in November.
As a conversational AI model, ChatGPT draws on knowledge scraped from the Internet to answer questions and generate text. Thanks to an API that launched his month, anyone with the programming chops can interface ChatGPT with their own custom application.
Thanks to his new app, which can run on MS-DOS, Yeo can use a vintage IBM PC-compatible computer to chat with ChatGPT over the Internet. It’s a similar back-and-forth conversation as the traditional ChatGPT web interface, albeit as a text-only, full-screen application running on the antique machine.
MS-DOS posed a particularly challenging platform for a ChatGPT client, lacking native networking abilities. In addition, Yeo targeted a computer with very limited processing power: a 1984 IBM 5155 Portable PC, which includes an Intel 8088 4.77 MHz CPU, 640KB conventional memory, CGA ISA graphics, and MS-DOS 6.22.
To create the client, Yeo used Open Watcom C/C++, a modern compiler running on Windows 11 that can target 16-bit DOS platforms. For testing purposes, he used a VirtualBox virtual machine running DOS 6.22 to streamline the development process, then he transferred the compiled binary to the target IBM DOS PC for testing.
To handle networking on the IBM PC, Yeo needed to weave his way through several layers. First, Yeo utilized a “Packet Driver API” standard invented in 1983. He integrated the open source MTCP library by Michael B. Brutman into the application to communicate with the Packet Driver, enabling networking capabilities for the client.
For the ChatGPT API, Yeo used OpenAI’s Chat Completion API, constructing the POST request (and parsing the JSON-formatted response) manually in C.
However, Yeo hit a major snag: the ChatGPT APIs require encrypted HTTPS connections. Since there are no native HTTPS libraries for MS-DOS, Yeo created an HTTP-to-HTTPS proxy that can run on a modern computer and translate the requests and responses between the MS-DOS client and ChatGPT’s secure API, acting as a transparent middleman in the communication process.
Yeo says that reading and writing input to the console presented another challenge due to the single-threaded nature of DOS applications. He devised a method to check and receive keypresses without pausing the program using the MTCP page and online samples as a reference.
In the end, the client works better than Yeo expected, and he looks forward to more retro challenges in the future: “After experiencing this, I will definitely be writing more retro-software in future,” he writes in a blog post that describes his development process in more detail.
Yeo released his code (called “doschgpt”) on GitHub if others want to run it—or perhaps improve or extend the code in the future. With a little creativity, the latest tech in AI language models need not be limited to cutting-edge machines.