ChatGPT has to be one of the hottest buzz words right now. It seems to constantly be in the news as well as gaining more attention and users by the day. In addition, OpenAI has also released APIs allowing developers to integrate chatbots into their applications. The most recent example of this comes from Yeo Kheng Meng, a programmer and retro computing enthusiast. He undertook the challenge of getting ChatGPT to run on the oldest piece of hardware he owns, a 1984 IBM 5155 Portable PC.
Due to the integrated floppy drives and monitor, the 5155 was considered a portable device at the time. Although by today’s standards it would be far from ideal. The IBM PC features an Intel 8088 2.77MHz CPU, 640KB of memory, CGA ISA graphics, a NE2000-compatible ISA ethernet adapter, and MS-DOS 6.22. One of the first challenges Yeo was presented with was determining how to develop for the machine. A compiler that can target the machine was found in the Open Watcom C/C++ compiler. It is an open source compiler that can generate executable code to and from DOS, OS/2, Windows, and Linux systems. In addition, a virtual machine running DOS was also used to avoid having to continually port the binaries over to the IBM PC.
The next challenge to overcome was developing network capabilities for the device. However, a low level API developed in 1983 exists called Packet Driver API which allows developers to talk to network cards. In addition, an open source networking library called mTCP DHCP is available that allows machines running DOS to acquire IP addresses using DHCP. DHCP is very common on modern computers and allows machines to automatically get IP addresses and the necessary configuration information from routers on local networks. With the method of communication for networking established, the code was able to be developed for the network stack.
The next steps included communicating directly with ChatGPT. This is possible using one of the APIs released by OpenAI. Specifically, the Chat Completion API was used in this instance. Using C programming language, a POST request is written to send messages to ChatGPT. On the other hand, the API will return information in a JSON format. Knowing the format of the JSON information returned and which data needs to be extracted, a C function was written to look for the specific key in the returned content and extract the desired data (ChatGPT responses in this case).
The final steps involved printing the collected output to the screen as well as accumulating new user input. Printing data to the screen is as straight forward as one would think, simply using the standard prinf() C function would suffice. On the other hand, extracting user input proved a bit more tricky. The standard C function scanf() could not be used since it would stop the program while waiting for user input. This would also pause the networking communications as well since the CPU does not have the luxury of multi-threading like modern processors. To successfully check for user input without pausing the program a BIOS keyboard interrupt was used that allows a key press to be stored in a local buffer while the program continues to execute.
Overall, Yeo successfully wrote an application on the IBM PC running DOS to host a ChatGPT client. He also notes he was impressed with the performance of the old machine. Upon completing the project, he asked ChatGPT if it could write him a DOS ChatGPT client. Its response included, “Keep in mind that creating a DOS ChatGPT client may be challenging, as DOS is an outdated operating system and may not have the necessary tools and resources to develop modern applications.”