Using structured outputs

Structured Outputs allow for providing a JSON schema for the outputs that the model has to adhere to in its responses.

First, we need to develop a schema that we want the responses to follow.

format := {'type' -> 'object'.
		'properties'
			-> {'min' -> {'type' -> 'number'} asDictionary.
					'max' -> {'type' -> 'number'} asDictionary.
					'unit' -> {'type' -> 'string'} asDictionary} asDictionary.
		'required'
			-> {'min'.
					'max'.
					'unit'}} asDictionary.
responseFormat := GtLResponseJsonSchemaFormat new 
	name: 'Body Temperature';
	schemaDictionary: format.
  

We can then provide it to a chat and interact with it.

model := GtLModelFactory new ollama_completions: 'llama3.2'.
chat := GtLChat new provider: model provider.
chat addResponseFormat: responseFormat.
chat sendString: 'Hello Llama! What is the normal temperature range of the human body?'.