• Stars
    star
    199
  • Rank 196,105 (Top 4 %)
  • Language
    C++
  • License
    GNU General Publi...
  • Created over 1 year ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A proof-of-concept ChatGPT and Hugging Face client for DOS with text-to-speech for Sound Blaster compatible systems.

doschgpt

A proof-of-concept ChatGPT and Hugging Face client for DOS.

Photos of the client running on my 1984 IBM 5155 Portable PC with a 4.77Mhz Intel 8088 CPU with MS-DOS 6.22.

As there are no native HTTPS APIs for DOS, a HTTP-to-HTTPS proxy like this I've written running on a modern machine is needed.

This program is heavily based on sample code in the DOS networking MTCP library. The program also requires a DOS Packet Driver to be loaded and MTCP to be set for the machine/VM.

Using the Text-to-speech feature requires a Sound Blaster-compatible card and 8Mhz CPU.

To reduce coding complexity and memory usage, the app only sends the previous request/reply set together with the current request to provide the conversational context to the model instead of the entire conversation history. Do notify me if you believe this is an issue for you and you prefer more history to be sent.

This program was written in a short time as a toy project. It has not been vigorously tested thus is NOT meant for "production" use.

Using the application

Application binary can be found in the releases directory or Github Releases section but do the following first.

  1. Both OpenAI and Hugging Face requires an API key/token to use their APIs. Follow the instructions on OpenAI or Hugging Face websites to obtain this key before proceeding. A read token for Hugging Face is sufficient.

  2. Download and start up http-to-https-proxy on a modern machine/SBC.

  3. The application requires a config file. By default it will use the filename doschgpt.ini but you can specify another path with the -c argument. Modify the configuration file to suit your needs in this order. A sample file can be found with the binary.

  • API key: Place your key without quotes (API key in this sample file has been revoked)
  • Model: Language model to use such as but not limited to. gpt-3.5-turbo for ChatGPT. facebook/blenderbot-400M-distill or microsoft/DialoGPT-large for Hugging Face. More details and models for Hugging Face can be found here.
  • Request Temperature: How random the completion will be. More OpenAI details and Hugging Face details
  • Proxy hostname: Hostname IP of the proxy
  • Proxy port: Proxy Port
  • Outgoing start port: Start of a range of randomly selected outgoing port
  • Outgoing end port: End of a range of randomly selected outgoing port
  • Socket connect timeout (ms): How long to wait when attempting to connect to proxy
  • Socket response timeout (ms): How long to wait for OpenAI's servers to reply
  1. Ensure that your DOS environment has loaded the following:
  • Packet Driver
  • MTCP Config Environment variable MTCPCFG
  • MTCP Config file configured by DHCP
  • Text-to-speech feature requires the BLASTER variable such as SET BLASTER=A220 I5 T1 D1 T4 to be set.
  1. Just launch doschgpt.exe in your machine and fire away. Press the ESC key to quit the application. You may use the following optional command line arguments.
  • -hf: To use Hugging Face instead of ChatGPT
  • -cdoschgpt.ini: Replace doschgpt.ini with any other config filepath you desire. There is no space between the -c and the filepath.
  • -dri: Print the outgoing port, number of prompt and completion tokens used after each request. Tokens are only provided by ChatGPT.
  • -drr: Display the raw server return headers and json reply
  • -drt: Display the timestamp of the latest request/reply
  • -cp737: Supports Greek Code Page 737. Ensure code page is loaded before starting the program.
  • -fhistory.txt: Append conversation history to new/existing text file. File will also include debug messages if specified. Replace history.txt with any other filepath you desire. There is no space between the -f and the filepath.
  • -sbtts: Able to read server reply using a text-to-speech driver used by Dr. Sbaitso.

Example usage:

# Connects to ChatGPT using config file at doschgpt.ini
doschgpt.exe

# Connects to Hugging Face using config file at hf.ini with timestamps after each request and reply
doschgpt.exe -hf -chf.ini -drt

Parsed options will be displayed.

Release details

  • doschgpt.exe: Main binary
  • doschgpt.ini: Sample configuration file for ChatGPT
  • hf.ini: Sample configuration file for Hugging Face
  • Sbtalker.exe: Smoothtalker by First Byte text-to-speech engine that loads as a TSR (This is called by the client on start)
  • Blaster.drv: Used by Smoothtalker to talk to a Sound Blaster card
  • Remove.exe: Unloads the Smoothtalker TSR (This is called by the client on end)
  • Read.exe: Reads its command line arguments to the Smoothtalker TSR

Compilation

To compile this application, you have to use Open Watcom 2.0 beta which you can download from here. Open Watcom 2.0 for 64-bit Windows which was released on 2023-04-01 02:52:44 is used. The v1.9 version seems to create binaries with issues on some platforms.

During installation, Open Watcom may prompt to install the environment variables. I chose to not do that to avoid having those variables being permanent. Instead I use a batch file to set the variables whenever I need to compile.

The program is compiled via a Makefile that is referenced from MTCP.

# Open cmd.exe
cd doschgpt-code

# If using Open Watcom v2.0 beta installed to C:\WATCOM2
20setenv.bat

# If using Open Watcom v1.9 installed to C:\WATCOM (Not recommended)
19setenv.bat

# To compile
wmake

#  Only if using Open Watcom 1.9. To patch the Open Watcom runtime to support Compaq Portable. Not needed for Open Watcom 2.0 beta.
PTACH.exe doschgpt.exe doschgpt.map -ml

# To clean
wmake clean

This application compiles against the MTCP library. I have unzipped the latest version mTCP-src_2023-03-31.zip at the time of development to the mtcpsrc directory. When Brutman updates this library again in future, simply replace the contents of the mtcpsrc directory with the new library.

PTACH.exe is a Win NT program compiled from MTCP sources.

Development

I use Visual Studio Code text editor to code for ease of use. For ease of testing, I used a virtual machine to run the application as 16-bit DOS applications and the MTCP network stack cannot run on modern Windows.

More details of my setup can be found here.

To easily transfer the binary, I used Python to host my build directory as a temporary webserver. Then use the MTCP tool htget to fetch the binary.

# On modern machine with binary
python3 -m http.server 8000

# Run on DOS machine/VM
htget -o doschgpt.exe http://X.X.X.X:8000/doschgpt.exe

Mock proxy

OpenAI implements rate limits on their API hence we should minimise calling their API repeatedly.

To avoid calling the OpenAI's servers during testing, we can mock the server's using this mockprox.goGo program that will replay the contents of reply.txt whenever the API call is received.

cp correct.txt reply.txt
go build mockprox.go
mockprox.exe

APIs

# Test API directly
curl https://api.openai.com/v1/chat/completions -H "Content-Type: application/json" -H "Authorization: Bearer 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" -d '{ "model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "What is MS-DOS?"}], "temperature": 0.7 }'

# Call through the https proxy for testing
curl --proxy "http://192.168.1.144:8080" https://api.openai.com/v1/chat/completions -H "Content-Type: application/json" -H "Authorization: Bearer sk-EhmTsEsKyH4qHZL2mr3hT3BlbkFJd6AcfdBrujJsBBGPRcQ" -d '{ "model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "What is MS-DOS?"}], "temperature": 0.7 }'

# Hugging Face API
curl https://api-inference.huggingface.co/models/facebook/blenderbot-400M-distill -X POST -H "Authorization: Bearer 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" -d '{"inputs": {"text":"What is retro-computing?"}, "parameters": { "temperature": 1.0 } }'

# Hugging Face API with history
curl https://api-inference.huggingface.co/models/facebook/blenderbot-400M-distill -X POST -H "Authorization: Bearer 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" -d '{"inputs": {"past_user_inputs": ["What is retrocomputing?"], "generated_responses": ["A retro computer is a type of computer that was invented in the 1950s."], "text": "I want one", "parameters": { "temperature": 1.0 } }'

Changelog

Go to CHANGELOG.md.

Third party sources

  1. MTCP TCP stack by Michael Brutman
  2. Text to speech from SmoothTalker by First Byte and Creative Text-to-Speech Reader downloaded from Winworld

More Repositories

1

docs-to-pdf-converter

A standalone Java library/command line tool that converts DOC, DOCX, PPT, PPTX and ODT documents to PDF files.
Java
590
star
2

w31slack

A proof-of-concept Slack client for Windows for Workgroups 3.11 with tests.
C
219
star
3

SwiftSerial

A Swift Linux and Mac library for reading and writing to serial ports.
Swift
137
star
4

http-to-https-proxy

A proxy that upgrades HTTP connections to HTTPS for systems which cannot make HTTPS requests.
Go
83
star
5

gentoo-on-486

Instructions on how to install modern Gentoo Linux on ancient 486-based PCs.
67
star
6

programming-win31

The sample codes provided in the floppy disk of Charles Petzold's book Programming Windows 3.1.
C
49
star
7

ndp2019-wristband-teardown

Tear-down effort of the Pixmob wristband used in NDP2019.
47
star
8

retro-configs

Collection of my DOS configurations and drivers of my retro machines
Assembly
31
star
9

reverse-engineering-ndp2016-wristband

Schematics of the reverse engineered Pixmob wristband used in NDP2016. Sample IR brute-force code is available but has not been fully tested in practice.
KiCad Layout
25
star
10

covox-music-player

A Linux program that plays MP3 or WAV files to the Covox Speech Thing or its clones via a native parallel port.
C
18
star
11

nus-soc-print

An Android application that prints office documents and PDF files to Unix printers in NUS School Of Computing via SSH
Java
16
star
12

reflections-on-trusting-trust

A talk (including sample code) about the Turing award lecture "Reflections on Trusting Trust" originally given by Ken Thompson.
C
16
star
13

pcb-covox-amp

A tiny sound card based on the Covox Speech Thing design which includes an LM386 amplifier.
15
star
14

coders-dvorak-regular-keypad

Programmer Dvorak layout with the typical keypad layout instead of the modified one by Roland Kaufmann.
15
star
15

distance-machine-locker

A system that locks your computer the moment you move away from it.
Swift
14
star
16

ssim

Program to measure the similarity between two videos using the OpenCV library and the structural similarity algorithm (SSIM). This is modified from the video-input-psnr-ssim tutorial of OpenCV.
C++
13
star
17

intro-to-ble

A talk about basic Bluetooth Low Energy concepts followed by code explanations.
Java
11
star
18

ne2000plus-collection

Collection of NE2000+ software obtained from various sources
Assembly
11
star
19

pcb-covox

A tiny sound card based on the Covox Speech Thing design.
9
star
20

pi-radio

Raspberry Pi internet radio streamer for Singapore. Can be modified to stream other internet radio stations.
Python
9
star
21

nus-soc-print-ios

An iOS Application that prints office documents and PDF files to Unix printers in NUS School Of Computing.
Swift
8
star
22

ssim-cuda

CUDA Program to measure the similarity between two videos using the OpenCV library and the structural similarity algorithm (SSIM). This is modified from the video-input-psnr-ssim tutorial of OpenCV
C++
7
star
23

ble-localiser

This talk is about how I manage to do localisation using 3 Raspberry Pis(RPis) as beacons.
Swift
7
star
24

iot-esp32-mcu-workshop

This is an introductory IoT ESP32 Microcontroller workshop to get acquainted with microcontroller programming and simple electronics.
C++
6
star
25

dvfs

A C++ native Android program that does dynamic frequency scaling to achieve a target frames-per-second (FPS).
C++
5
star
26

reflections-on-trusting-trust-go

A talk (including sample Golang code) about the Turing award lecture "Reflections on Trusting Trust" originally given by Ken Thompson.
Go
5
star
27

SwiftLinuxSerial

A Swift 3 Linux-only library for reading and writing to serial ports. (Deprecated for SwiftSerial)
Swift
4
star
28

ht107e-socket-tester-teardown

4
star
29

intro-to-pcb-design-eagle

A class to introduce students to designing Printed Circuit Boards (PCBs) using the Eagle software.
Eagle
4
star
30

pcb-usb-ft245r-parallel-adapter

A USB to parallel adapter using the FTDI FT245R chip. This is not a IEEE 1284 compliant parallel port. Just using the DB25 connector to access the data pins.
KiCad Layout
3
star
31

pcb-name-card

My business card that is on a Printed Circuit Board (PCB). Comes with an white LED, UV LED, ruler and QR code.
Eagle
3
star
32

getting-started-with-rpi

A talk about introducing the audience to setting up the Raspberry Pi as well as basic Python coding on the GPIO pins.
Python
3
star
33

intro-to-rpi

A short introductory course I conducted for people new to Raspberry Pis and Linux.
Python
3
star
34

odroid-power-measure

A Java program that dynamically shows FPS, CPU/GPU frequency and power of Odroid-XU.
Java
2
star
35

pcb-breakout-ltc3625-tps63031

Pin breakout of the LTC3625 supercapacitor charger with TPS63031 3.3V regulator to through-hole pin headers for prototyping
2
star
36

pcb-covox-amp-v2

A tiny sound card based on the Covox Speech Thing design which includes an LM386 amplifier and FT245RL chip to receive data via USB. This project is a combination of my 2 earlier projects pcb-covox-amp and pcb-usb-ft245r-parallel-adapter
KiCad Layout
2
star
37

mov-is-turing-complete

A talk about the academic paper "mov is Turing-complete" written by Stephan Dolan". Practical examples from movcc compiler by Chris Domas.
C
2
star
38

sensor_clock_2

A clock composed of an Arduino, temperature and humidity sensors. Includes integrated charger.
Arduino
2
star
39

vibrate_alarm_clock_2

An vibrating alarm clock based on Microview.
Arduino
1
star
40

start-sslstrip-on-boot

Scripts to to start SSLStrip on boot for Arch Linux ARM on Raspberry Pi
Shell
1
star
41

power_measure_tool

An Arduino setup to measure the voltage and current of a load.
C++
1
star
42

retro-configs-apple

Collection of my setup configurations and disc locations of my retro Apple machines
1
star
43

cs5272-project

A group project done in NUS CS5272 module in AY2014-2015 Sem 2.
C
1
star
44

yeokm1.github.io-hugo

Hugo source files for my site at http://yeokhengmeng.com.
JavaScript
1
star
45

yeokm1.github.io

Hugo compiled frontend files for my site at http://yeokhengmeng.com.
HTML
1
star
46

pcb-bme280-breakout

Pin breakout of the Bosch BME280 sensor to through-hole pin headers for prototyping
Eagle
1
star
47

dvfsapp

An app front end that does dynamic frequency scaling to achieve a target frames-per-second (FPS).
Java
1
star
48

vibrate_alarm_clock

An alarm clock with vibration capabilities.
Arduino
1
star
49

auto-rotate-screen

A program that auto rotates the screen when the Thinkpad is rotated.
C++
1
star
50

fpsmeasure

Java
1
star