KScript docs
EN

chat fields and methods

Conversations with a language model, from @chat().

A field is a plain fact about the value, read with a dot and no brackets: $value.name. A method takes arguments or does work, and is called with ->: $value->name(arguments), or with the value piped in: $value |> name(arguments).

Fields

FieldTypeDescription
.historylistThe conversation so far: a list of { role, text }.
.modelstringThe model the chat uses.
.systemstringThe system prompt, or null.

From KScript.AI

These need <import package="KScript.AI" />import KScript.AI. See KScript.AI.

#chat->ask(message, schema?) → any KScript.AI

Sends a message and returns the answer, keeping the history. With a schema the answer is a map.

Arguments can be named: ->ask(…, schema: …).

Example
<let name="chat" value="@chat('Answer in one word.')" />
<echo>{ $chat->ask('What colour is the sky?') }</echo>
<echo>{ $chat->ask('And grass?') }</echo>
<let name="rating" value="$chat->ask('Rate this review: Loved it!', schema: { stars: 'int 1-5' })" />
<echo>{ $rating.stars } stars</echo>
$chat = @chat('Answer in one word.')
echo $chat->ask('What colour is the sky?')
echo $chat->ask('And grass?')
$rating = $chat->ask('Rate this review: Loved it!', schema: { stars: 'int 1-5' })
echo "{ $rating.stars } stars"

#chat->reset() → chat KScript.AI

Forgets the conversation (keeps the system prompt).
Example
<let name="chat" value="@chat('You are a helpful assistant.')" />
<do>$chat->ask('Remember the number 7.')</do>
<do>$chat->reset()</do>
<echo>{ $chat.history->count() } messages</echo>
$chat = @chat('You are a helpful assistant.')
$chat->ask('Remember the number 7.')
$chat->reset()
echo "{ $chat.history->count() } messages"

Methods from any