// Development source runtime with the optional native LLM engine required.
// Replace the path with an admitted single-file llama/qwen2 chat GGUF.
// Host RAM must accommodate the weights, context, workspace and operating system.
import aner.llm
import aner.api

let base = llm.load("models/local-instruct-q4.gguf", context: 2048,
    device: "cpu", kv_cache_type: "f16", flash_attention: "auto")
let tuned = base.with_optimizer(
    threads: 4, prefill_threads: 4,
    batch_tokens: 128, micro_batch_tokens: 32,
    prefix_cache_entries: 0, prefix_cache_tokens: 1024,
    speculative_tokens: 0)
// One shared scheduler context. Named conversation sessions are unavailable.
let serving = tuned.with_batching(max_sequences: 1)
tuned.close()
base.close()

// Exercise context/workspace allocation before binding the server socket.
let warmup = serving.generate("Say hello.", max_tokens: 1)
print(warmup.text())
print(serving.load_summary())
print(serving.memory_summary())

let app = api.app("Aner CPU chat").llm(path: "/chat", model: serving)
    .bind(host: "127.0.0.1", port: 11435)
    .limits(max_rows: 64, timeout_ms: 120000)
    .output_limit(max_tokens: 128)
app.serve()
serving.close()
