Lurker News
Hey HN, I didn't want my Gateway 4DX2-66 from 1993 to be left out of the AI revolution, so I built an AI Assistant for Windows 3.1, based on the OpenAI API.

The most interesting parts of building this were:
- Getting TLS 1.2 and 1.3 working on Windows 3.1 so that WinGPT could directly connect to OpenAI's server without relying on a modern machine for TLS termination.
- Learning about the memory segmentation architecture on 16-bit Windows, including the difference between far and near pointers.
- Building the UI in plain C code with the Windows API and limited selection of controls in Windows 3.1.
You can check it out here and learn more about what it was like to build it: https://www.dialup.net/wingpt/

Comments (90) 29 threads

ineedasername3 replies#
Maybe you could incorporate it into a version of ms office from that era as well. You could even give it an anthropomorphised personality embodied by a skeuomorphic element of irl office supplies more common in that era, like a rubber band… or… a… paperclip…
brtknr1 reply#
Bob looks an awful lot like Bill Gates.
blackoil#
Melinda Gates was marketing manager, so maybe it was intentional.
dialupdotnet1 reply#
Good idea :) Clippy is Office 97 and later though, so I'll need to make a version that fits in with the Windows 95/98 (or even Windows Me) look!
juliangoldsmith#
MS Agent would be a perfect fit for that. It's basically Clippy as a Windows API. It even includes speech synthesis.

IIRC it ships with Windows 2000, but works on Windows 95 too.

quickthrower2#
Full circle AI from paperclip to paperclip maximizer!
userbinator2 replies#
Getting TLS 1.2 and 1.3 working on Windows 3.1 so that WinGPT could directly connect to OpenAI's server without relying on a modern machine for TLS termination.

That's in a separate page here: https://www.dialup.net/wingpt/tls.html
...and is well worth reading. I'm surprised you had trouble getting a TLS implementation to fit in 64k of code and data, since a lot of deeply-embedded stuff (some even using 8-bit CPUs with bankswitching) for IoT and similar applications support TLS 1.2.

fouc#
So glad to see someone working on TLS 1.3 for Windows 3.1.

It's a sad day when slightly older operating systems have trouble accessing the internet.

kazinator#
Maybe some of those chips have some hardware support for crypto?
blackhaz2 replies#
Really miss Windows 3.1, 95 and 98 era. Interfaces have only gone worse since then. Every time I crank up my 386 or Pentium I am completely blown away by how clean and stress-free the GUI was. Really tired of this Apple/Google low-contrast pop-up hell.
achr2#
This is an amazing reference, thanks.
izacus2 replies#
Remember how you could actually RESIZE things in that era? Sidebars, toolbars, etc.?

Now half of my UIs have "Tap to...." labels when localized. So many amazing modern UI tools and the rockstar developers wielding them can't even make a draggable sidebar.

InCityDreams#
One man's rockstar developer is another man's script kiddie.

I do, however have considerably more time for script kiddies.

haspok1 reply#
Good luck resizing a typical modal window though. Also good luck with high-DPI...

Even resizing regular windows was not always an option, and if it was, it was very rarely thought through by the developers. I vividly remember that the Swing framework for Java was very special just because of this, as in you couldn't really specify it in pixels where your components would be placed, you'd have all sorts of strategies to divide and position them. (Not saying it was any good, but certainly a notable effort.)

pjc501 reply#
This was grey-downvoted, but it's correct: Win16/32 MessageBox() modals are not resizeable.

Not only that, but window resizing was something that had to be implemented for each window, so lots of applications had unresizeable dialogs and only the "document" area was resizeable.
Even worse, the use of pixel positioning meant that nothing was scaleable. High-DPI display? Choose (a) not being able to read anything or (b) bad linear rescale by a limited number of scales.
I too am a fan of the simplicity and clarity of the old Windows UI, and Microsoft haven't really managed to improve on it, but let's not pretend it doesn't have serious limitations.

Continue this thread — 1 reply

ashleyn1 reply#
> Memory is quite limited on Windows 3.1 machines, so I tried to reduce the amount of memory needed for WinGPT, especially in sending and receiving the query and response from the OpenAI API. The JSON responses of modern APIs aren't especially optimized for size, and OpenAI's API is no exception. I've asked the model to be brief in an effort to keep responses as small as possible. I've also chosen not to send the text of previous turns in the API calls, even though this means that the bot won't be able to use prior conversation context.

You can trade space for CPU time using SAX-style parsing[1]. SAX-style parsing visits each node of a tree from top to bottom, firing events for each node visited. The amount of memory required compared to fully parsing JSON is negligible, and writing a custom SAX-style parser for JSON shouldn't be too difficult. There are existing SAX-style JSON parsers you can examine as well.[2]
[1]: https://en.wikipedia.org/wiki/Simple_API_for_XML [2]: https://rapidjson.org/md_doc_sax.html

dialupdotnet#
Yep! I'm using JSMN (https://github.com/zserge/jsmn), which is a streaming parser that visits each token sequentially, so there's only one copy of each JSON response in memory. I also avoid allocating new intermediate memory whenever possible; for example, to unescape backslashes in the JSON strings, I use a destructive loop that moves the non-backslash characters forward in memory, and truncates the string by moving the null terminator earlier in the string. Not something I'd imagine doing in most environments today, but as you said, it saves a bit of space at the expense of CPU time :)

  void DestructivelyUnescapeStr(LPSTR lpInput) {
    int offset = 0;
    int i = 0;
    while (lpInput[i] != '\0') {
      if (lpInput[i] == '\\') {
        offset++;
      } else {
        lpInput[i - offset] = lpInput[i];
      }
      i++;
    }
    lpInput[i - offset] = '\0';
  }

Load more comments