Created
November 21, 2024 09:55
-
-
Save nige123/2191a6b3bef1ddb66abe1c9834fea5ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# WAT will LLMs give you for Christmas? | | |
Programming for a living used to be an active conversation between yourself, the computer, and your colleagues. | |
This Christmas, a new guest is joining the programming party: the LLM. Large Language Models (LLMs) can talk a lot | |
and just like your crazy Uncle occasionally blurt out something bonkers. But do we want to invite LLMs to the | |
programming party, and where should they sit? How can they help things flow? | |
Finding flow while programming is the art of staying in the Goldilocks zone - working on challenges that are not | |
too hard and not too easy. Raku and Perl are both super-expressive languages with rich operators. Their low and | |
long learning curves enable programmers to pick a place that matches their current skill level and stay in flow. | |
There is a potential downside, however, for a language like Raku that is [optimized for (O)fun](https://perl6advent.wordpress.com/2015/12/20/perl-6-christmas-have-an-appropriate-amount-of-fun/). Sometimes new | |
programmers encounter code too far along their learning curve, way outside their Goldilocks zone. For them, fear | |
is a flow stopper. Worse than that, as Master Yoda put it, "Fear leads to anger. Anger leads to hate. Hate leads | |
to suffering." The [mindshare of expressive languages](https://raku-advent.blog/2020/12/02/day-1-perl-is-dead-long-live-perl-and-raku/) has suffered enough. | |
Fortunately, Santa is smiling more than ever this Christmas! LLMs are a gift that can help lift more programmers up the learning curve and into the Goldilocks zone: less fear, more flow. | |
Expressive languages, like Raku, can offer LLM-powered utilities as part of their tooling to help new | |
programmers up the learning curve. Here's a simple example. | |
### Remember Your First Regular Expression Encounter? | |
```regex | |
[12]\d{3}-[01]\d-[0-3]\d ([^ \[]*?)\[([^\]]*?)\]:.* | |
``` | |
Now instead of wailing "WAT?!" Just use the Raku "wat" utility to help explain it. | |
```bash | |
shell> wat "[12]\d{3}-[01]\d-[0-3]\d ([^ \[]*?)\[([^\]]*?)\]:.*" | |
``` | |
Output: | |
> This code extracts log entries in the format "timestamp [source]: message". Use it to parse log files and extract specific information. | |
`wat` works with code snippets or can explain entire programs for you. | |
```bash | |
shell> wat WAT/CLI.rakumod | |
``` | |
Output: | |
> This code summarizes code using the LLM::DWIM module. | |
> **To use:** | |
> - Run `wat <filename>` to summarize a program | |
> - Run `wat "$some-code.here();"` to explain code | |
> - Run `wat config` to change settings | |
> - Run `wat help` to show help | |
The `wat` module uses the following prompt: | |
```raku | |
# keeping the prompt short and sweet | |
my $prompt = q:to"PROMPT"; | |
You are an expert programmer. | |
Produce friendly, simple, structured output. | |
Summarize the following code for a new programmer. | |
Limit the response to less than $response-char-limit characters. | |
Highlight how to use this code: | |
PROMPT | |
``` | |
One programmer's WAT is another's DWIM (Do What I Mean). Under the hood, the `WAT::CLI` module relies on | |
the [`LLM::DWIM`]() module's `dwim` method to do all the LLM work. | |
```raku | |
say dwim $prompt ~ $program-content; | |
``` | |
### Context Matters | |
Current LLMs work best with sufficient context - so they can associate problems and solutions. Without context, | |
LLMs can stumble. Just try giving `wat` an empty context (`" "`) and it's like that crazy Uncle at Christmas after | |
one too many! | |
### Getting Started | |
To have a play with `wat` this Christmas, install it with Raku's package manager `zef`: | |
```bash | |
shell> zef install wat | |
``` | |
--- | |
## Build Your Own LLM-Powered Raku Tool | |
Here are some ideas for helping code to flow. | |
### Given the Source Code of a Program: | |
- **Comment Injector**: Inject useful comments | |
- **Comment Translator**: Translate comments into your spoken language | |
- **Reviewer**: Suggest potential improvements | |
- **Module Documentor**: Document a module with RakuDoc | |
- **Unit Test Maker**: Generate unit tests | |
- **CLI Maker**: Generate a command-line interface to a program | |
- **API Scaffolder**: Translate between OpenAPI spec β program | |
- **Code Translator**: Translate code from another language to Raku (e.g., Python β Raku) | |
- **SEO Docs**: Document the problems the program solves and generate HTML for SEO and ingestion by LLMs | |
### Given the Output of a Shell Command: | |
- **Git Log Summary**: Generate a stand-up report for your next Scrum meeting | |
- **Test Error Summary**: Summarize the output of many tests with next steps to fix | |
- **Ticket Subtasks**: Generate a set of subtasks required to close a ticket | |
--- | |
Merry Christmas, and happy coding with your new guest at the programming table! | |
π π»β¨ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment