Archive for 1337

Context-Aware AI Conversations in Smalltalk

Posted in Appsterdam, Caffeine, consulting, Context, livecoding, Smalltalk, SqueakJS with tags , , , , , , , , , , on 3 December 2024 by Craig Latta
There’s a lot of Smalltalk knowledge in the pre-training data of most LLMs.

I’ve been stumbling toward a “good enough” understanding of Smalltalk by an AI large language model, and Smalltalk tools for integrating conversations into the workflow. So far, I’ve been doing this through model fine-tuning with English system prompts, without resorting to code at all. I’ve been impressed with the results. It seems the pre-training that the OpenAI gpt-4o model has about Smalltalk and Squeak is a decent basis for further training. I evolve the prompts in response to chat completion quality (usually by applying more constraints, like “When writing code, don’t send a message to access an object when you can access it directly with an instance variable.”).

I wanted to converse with the language model from any text pane in Squeak, via the classic “do it”, “print it”, and “inspect it” we’re used to using with Smalltalk code. I changed Compiler>>evaluateCue:ifFail: to handle UndeclaredVariable exceptions, by delegating to the model object underlying the text pane in use. (It’s usually an UndeclaredVariable exception that happens first when one attempts to evaluate an English phrase. For example, “What” in “What went wrong?” is unbound.) That model object, in turn, handles the exception by interpreting the next chat completion from the language model.

The model objects I’ve focused on so far are instances of Debugger and Inspector. One cute thing about this approach is that it records do-its for English prompts just like it does for Smalltalk code, in the changes log. Each model can supply its own system prompts to orient conversations, and can interpret chat completions in a variety of ways (like running Smalltalk code written by the language model). Each model object also keeps a reference to its most recent chat completion, so that successive prompts are submitted to the language model in the context of the complete conversation so far.

With all this in place, evaluating “What went wrong?” in a debugger text pane gives surprisingly correct, detailed, and useful answers. Running the code answered to “Write code for selecting the most recent context with a BlockClosure receiver.” manipulates the debugger correctly.

Next, I’m experimenting with prompts for describing an application’s domain, purpose, and user interface. I’m eager to see where this leads. :)

the smallest object memory so far

Posted in Appsterdam, consulting, Smalltalk, Spoon with tags , , , , , on 21 October 2012 by Craig Latta

The smallest object memory snapshot I’ve made so far is 1,337 bytes long, on 19 January 2006. You can get the bits (also see my notes about the visualization tools). It adds 3 and 4, then quits.

I created it with a new version of the Squeak system tracer that I wrote. This tracer is implemented as a feature of the Squeak virtual machine simulator. It keeps track of all the objects that are touched during a particular duration of operation, then uses that information to guide a final garbage collection and snapshot.

When you run the snapshot, the virtual machine gets the object address (“oop”) for the special-objects array from the snapshot header. Note that the snapshot header doesn’t appear in this picture. The visualization is of the object memory bytes after they’ve been read from the snapshot file, not the snapshot file itself. The header is the only use of bytes in the snapshot file other than the object memory bytes.

Indirectly from the special-objects array (through the Processor and its active process) the virtual machine finds the active context and continues execution. The instructions executed come from a method used by the context. The instructions are: push (3), push (4), add, send (#quitPrimitive). The send invokes >>quitPrimitive, another method. That method terminates the virtual machine via a primitive. The virtual machine needs to look up >>quitPrimitive in the method dictionary of the class of Smalltalk, a literal association in the literal frame of the initial context.

In the above, we’ve touched the following objects from the snapshot file, in the following order:

  1. the special-objects array
  2. the global Processor association
  3. the Processor
  4. the active Process
  5. the active Process’s suspended context
  6. the now-active context’s method
  7. the symbol #quitPrimitive from the context’s literal frame
  8. the global Smalltalk association
  9. the system dictionary (Smalltalk)
  10. class SystemDictionary
  11. SystemDictionary’s method dictionary
  12. SystemDictionary’s method dictionary’s association array
  13. nil (touched during method lookup)
  14. that array’s association for key #quitPrimitive
  15. the value for key #quitPrimitive (the second method)

The method dictionary of the first method is in there also, as is true and false, making 18 objects. (The numbers 3 and 4 are immediates in the first method’s literal frame.) I could kill those last three, but I declared victory when I got the thing under 1,337 bytes. :)