/*
  Example 28: Streaming AI Responses

Demonstrates:
   1. Configuring model calls for streaming output.
   2. Handling real-time token stream chunks with callback functions.
*/

fn handleChunk(chunk: string) -> string {
  // This callback is executed in real-time as chunks arrive from the model
  show "Chunk:" chunk
  return chunk
}

show "=== Streaming to stdout (stream: true) ==="
// Using stream: true will write chunks directly to standard output
let res1 = model("gemini-3.5-flash-lite") {stream: true} {"Write a very short one-sentence welcome message for a Sesi developer."}
show ""
show "Final accumulated response:" res1
show ""

show "=== Streaming with callback function (stream: callback) ==="
// Using a function reference allows custom processing of incoming chunks
let res2 = model("gemini-3.5-flash-lite") {stream: handleChunk} {"Give a one-sentence tip on writing clean code."}
show ""
show "Final accumulated response:" res2