Skip to main content
Zai provides methods for generating and transforming text. Each method handles prompting and output formatting.

Generate text

zai.text() generates content from a prompt:
import { adk } from "@botpress/runtime"

const intro = await adk.zai.text(
  "Write a brief introduction about AI in customer service",
  { length: 200 }
)
OptionTypeDescription
lengthnumberTarget length in tokens

Rewrite text

zai.rewrite() transforms text based on instructions:
const formal = await adk.zai.rewrite(
  "hey, the meeting is tmrw at 3",
  "Make this professional and formal"
)
// "The meeting has been scheduled for tomorrow at 3:00 PM."
OptionTypeDescription
lengthnumberMax tokens to generate
examplesArray<{input, output, instructions?}>Few-shot examples to guide the rewriting

Summarize

zai.summarize() condenses long content. It handles documents from a few paragraphs up to entire books by chunking and merging automatically:
const summary = await adk.zai.summarize(longArticle, {
  length: 100,
  prompt: "Focus on key findings and conclusions",
})
OptionTypeDescription
lengthnumberTarget summary length in tokens
promptstringInstructions for what to focus on
formatstringHow to format the output (e.g. “bullet points with clear sections”)
intermediateFactornumberHow many times longer intermediate summaries are than the final length (used for very large documents)
maxIterationsnumberMax refinement passes
sliding{ window, overlap }Override the default chunk size and overlap

Answer with citations

zai.answer() answers a question from a set of documents and tells you which documents backed the answer. It doesn’t always return a direct answer: if the question is ambiguous, off-topic, or the documents don’t cover it, the result carries that information instead.
const faq = [
  "Orders ship within 2 business days. Standard shipping takes 3-5 business days; expedited takes 1-2.",
  "Returns are accepted within 30 days of delivery. Items must be unused and in original packaging.",
  "Our warranty covers manufacturing defects for 1 year from purchase. Wear and tear is not covered.",
]

const result = await adk.zai.answer(faq, "How long do I have to return something?")

if (result.type === "answer") {
  console.log(result.answer)     // "Returns are accepted within 30 days of delivery..."
  console.log(result.citations)  // Points back to the returns policy entry
}
Branch on result.type to handle the other cases (ambiguous questions, off-topic, etc.):
TypeFieldsWhen it’s returned
answeranswer, citationsThe documents support a clear answer
ambiguousambiguity, follow_up, answersThe question has multiple valid interpretations
out_of_topicreasonThe question isn’t covered by the documents’ topic
invalid_questionreasonThe question is malformed or nonsensical
missing_knowledgereasonThe topic is relevant but the documents don’t cover it

Patch files

zai.patch() makes surgical edits to code or text files based on natural language instructions. It produces minimal diffs rather than regenerating entire files:
const files = [{
  path: "src/utils.ts",
  name: "utils.ts",
  content: 'export function add(a: number, b: number) {\n  return a + b\n}',
}]

const patched = await adk.zai.patch(
  files,
  "Add JSDoc comments to all exported functions"
)
Last modified on April 24, 2026