Skip to content

The language model ​

llm.ask — the platform's model, the same one that answers in the AI answer block («Ответ ИИ»).

mzs
include bot
include llm
bot.say(llm.ask("Translate into Spanish: ${$message}"))
text
¡Hola! ¿Dónde está mi pedido 10452?
FunctionWhat it does
llm.ask(prompt)the model's answer — a string with no spaces at the ends
llm.ask(prompt, opts)the same with options; with json: true — a dict or an array
Option
systeman instruction for the model: role, tone, format
max_tokensthe answer length, an integer 1–2000, default 500
temperature0–2: low for facts and classification, higher for free text
jsontrue — a JSON answer, parsed into a dict or an array

Any other option, an empty prompt or a non-string prompt is an error.

With an instruction ​

Rules go in system, the visitor's words go in the prompt as data: a visitor may write "forget your instructions".

mzs
include bot
include llm
answer = llm.ask("Customer question: ${$message}", {
  system: "You are a shop assistant. Answer briefly, in English, and don't make things up.",
  max_tokens: 200,
  temperature: 0.3,
})
bot.say(answer)
text
Order 10452 is already on its way: delivery usually takes 1–2 days.

JSON: classification and extraction ​

With json: true the model turns on JSON mode, and a ```json wrapper is stripped. Describe the shape of the answer in the prompt.

mzs
include bot
include llm
r = llm.ask(
  "Message: ${$message}\nReturn {\"intent\": \"order_status\" | \"price\" | \"other\", \"order_id\": string or null}",
  {system: "You classify customer requests.", json: true, temperature: 0, max_tokens: 100},
)
r["intent"]  # → "order_status"
r["order_id"]  # → "10452"
bot.set("order_id", r["order_id"] ?? "")
bot.exit(r["intent"] == "order_status" ? "status" : "next")

The model's answer is outside data: a field may be missing, a value may differ. Check it and convert types ((r["n"] ?? 0).int).

Errors ​

llm.ask fails rather than returning nothing: the owner is out of energy, the model didn't answer, a json: true answer isn't JSON, a limit. Without try the block leaves by «ошибка» (error).

mzs
include bot
include llm
answer = try llm.ask($message, {max_tokens: 200}) else nil
if answer == nil {
  bot.say("I can't answer right now — please write later.")
  exit()
}
bot.say(answer)
text
Order 10452 is already on its way: delivery usually takes 1–2 days.
mzs
include llm
llm.ask("Hello", {model: "gpt"})
text
llm.ask: unknown option "model"

Cost and limits ​

Each call spends the owner's energy, like an AI answer — in the studio's trial run too. A bot with no energy gets an error before the model is called.

Limit
calls per run5
prompt + system16 KB together
max_tokens1–2000
timecounts toward the run's 10 s; out of time is a time limit, try doesn't catch it

One short call per run is normal. A long max_tokens costs both time and money.