Playing with LLMs
To explore the scripts below you need a connection to an LLM. Find more details at: How to setup LLM connections.
Chat with markdown input:
chat := GtLChat new. chat sendMarkdown: 'Write a script for adding 2 and 40 in Smalltalk'.
Chat with markdown input and markdown output:
chat := GtLChat new markdownResponse. chat sendMarkdown: 'Write a script for adding 2 and 40 in Smalltalk. And a short poem about it.'
Specifying code transformations as output:
chat := GtLChat new markdownResponse; addResponseFormatForMagrite: GtLCodeTransformations named: 'CodeTransformations'; sendMarkdown: 'Create a class for a Person with a first and last name. Create a printing method. Use CodeTransformations to express the changes.'
Specifying instructions through Lepiter pages:
chat := GtLChat new markdownResponse; gtPageExplanation: 'Rewriting Pharo code by example'; addResponseFormatForMagrite: GtLRewriteRule named: 'RewriteRule'; sendMarkdown: 'Provide the rewrite rule for removing all `self halt` statements from methods.'
Providing tools to search through Lepiter:
chat := GtLChat new markdownResponse; tools: GtLTools leSearch; sendMarkdown: 'Provide the rewrite rule for removing all `self halt` statements from methods. Document yourself by reading relevant Lepiter pages.'
Getting the result as a dedicated pharo script:
chat := GtLChat new
markdownResponse;
addResponseFormatForMagrite: GtLPharoScript named: 'PharoScript';
gtPageExplanation: 'Querying with GT search filters by example';
sendMarkdown: 'Provide a PharoScript with a search for methods that are in {{gtClass:BlElement}} and also refer to `assert:description:`.'
Wrapping a chat in a tool:
chat := GtLChat new
markdownResponse;
tools: (GtLTools withAll: {GtLToolForChatMethodSearch new});
sendMarkdown: 'What are a few references of {{gtClass:BlElement}} that also refer to `assert:description:`.'
Providing pictures as input:
fileReference := BlExporter png
element: (GtWorldElement allInstances
detect: [ :aWorldElement | aWorldElement space isFocused ]);
export.
chat := GtLChat new
markdownResponse;
sendWith: [ :m |
m
markdown: 'What do you see in the picture?';
images: {fileReference} ]
Using tools that return pictures:
chat := GtLChat new
markdownResponse;
tools: (GtLTools withAll: {GtLToolForWorldScreenshot new});
sendMarkdown: 'Take a screenshot and describe what you see'
Allowing the LLM to change code and run examples:
chat := GtLChat new markdownResponse; tools: GtLTools gt; gtPageExplanation: 'Examples by example'; sendMarkdown: 'Create a BubbleSorter class that implements bubblesort. Create examples for it. Ensure that the examples are green.'
Change the resulting BubbleSorter class for example, by changing the comparison sign. And make it fix the examples.
chat sendMarkdown: 'Check the examples about {{gtClass:BubbleSorter}}. If they are red, make them green.'
Creating parsers:
Create a PetitParser2 parser:
chat := GtLChat new
markdownResponse;
tools: GtLTools gt, {GtLToolForSmalltalkCodeEvaluation new};
gtPageExplanation: 'Parsing with PetitParser2';
addResponseFormatForMagrite: GtLPharoScript named: 'PharoScript';
sendMarkdown: 'Create a script with a PetitParser2 parser for this ripgrep output format:
```console
./some/path/to/file.txt:43:1232:Bla
```
Try the script and ensure it works before proposing it.
'
Create a SmaCC parser:
smaccModel := GtLSmaCCModel new. chat := GtLChat new markdownResponse; tools: GtLTools gt , (GtLSmaCCTool allSubclasses collect: [ :each | each new model: smaccModel ]); gtPageExplanation: 'SmaCC grammar'; sendWith: [ :m | m markdown: 'Create a SmaCC parser to parse and evaluate simple math expressions. The class should be named `SampleExpressionParser` and be in the package `TempParsers`. Ensure you get no error in the parser. Compile the parser. Build the abstract syntax tree. Test it with a simple script and once it''s working provide the script' ]