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';
		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 gtSearch , GtLTools gtExamplesRun , GtLTools leSearch
				, GtLTools gtCodeChange;
		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 from {{gtClass:BubbleSorter}}. If they are red, make them green.'
  

Other examples of using tools:

chat := GtLChat new
		markdownResponse;
		tools: GtLTools gtSearch , GtLTools leSearch;
		gtPageExplanation: 'Examples by example';
		sendMarkdown: 'Explain the {{gtClass:BlElement}} class. Look for examples. Pick an interesing example and explain it.'
  
chat := GtLChat new
		markdownResponse;
		tools: GtLTools gtSearch , GtLTools leSearch;
		sendMarkdown: 'What Lepiter pages are relevant for learning about examples?'