LLM-powered Method Resolution with Synonllm
This week on ‘Works on My Machine,’ I demo Synonllm, a module I originally built as a part of my RubyConf2024 talk Going Postel.
The initial goal was to make it easier to use AI-generated code ‘as-is’ by being flexible about what you get back from the LLM. A lot of the time generated code has slight inconsistencies like being snake_cased instead of camelCased or using slightly wrong method names, but usually the intent is there, so like Jon Postel suggested: be flexible in what you accept as long as the intent is clear.
This module came to mind again because I was recently a guest on The Ruby AI Podcast and we got onto the topic of leaning in to the discomfort you can feel when working with LLMs as an experienced software engineer. They’re going to do things a lot different from what you’re used to, but that doesn’t have to be a bad thing.
Synonllm is a Ruby module that combines method_missing
with an LLM to provide AI-powered synonym matching for method calls. Here’s the breakdown from the video:
In the demo, you’ll see this work with a Date
object (correctly mapping day_of_week to wday) and then with a FileHandler class. For the FileHandler, we use much more natural language-like calls (f.read file, 4
or even f.read
file without specifying the number of lines) and Synonllm
figures out the correct, more verbose, underlying method to call.
While this might seem like a small convenience, or an unconventional use of AI, I think this hints at a few interesting ideas for where things could go in the future:
What other things can we do with programming languages when the system understands your intent, not just exact syntax?
The code for synonllm is available on GitHub. You can find the main module and the example code from the video in the sublayerapp/synonllm_demo repository.
To try it out, you’ll need to clone the repository and have an environment variable of GEMINI_API_KEY
set with a valid API key (Optionally you can change the generator code to use OpenAI or Claude, setting OPENAI_API_KEY
and ANTHROPIC_API_KE
Y respectively).
If this experiment sparks any thoughts or questions, or you end up using it please let me know!