index.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <!doctype html>
  2. <html lang="en-nz">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <title>Vallama — Astrologue Developer</title>
  7. <meta name="description" content="Vallama is a high-level Vala library for running LLM inference with llama.cpp, with native tool calling driven by grammar-constrained decoding: chat sessions, embeddings, tokenizers and tools — on your own hardware. Free software, LGPL-3.0-or-later.">
  8. <meta name="color-scheme" content="light dark">
  9. <meta name="theme-color" content="#f2ebda" media="(prefers-color-scheme: light)">
  10. <meta name="theme-color" content="#0a0a12" media="(prefers-color-scheme: dark)">
  11. <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Ccircle cx='32' cy='32' r='27' fill='none' stroke='%23a8801f' stroke-width='4'/%3E%3Cpath d='M32 8l6 18 18 6-18 6-6 18-6-18-18-6 18-6z' fill='%23a8801f'/%3E%3Ccircle cx='32' cy='32' r='4' fill='%23003078'/%3E%3C/svg%3E">
  12. <meta property="og:title" content="Vallama — Astrologue Developer">
  13. <meta property="og:description" content="High-level Vala bindings for llama.cpp inference: chat sessions, grammar-constrained tool calling, embeddings and tokenizers — running on your own hardware.">
  14. <meta property="og:type" content="website">
  15. <link rel="stylesheet" href="../../assets/css/style.css">
  16. </head>
  17. <body>
  18. <a class="skip-link" href="#main">Skip to content</a>
  19. <header class="masthead">
  20. <div class="container masthead__inner">
  21. <a class="brand" href="../../">
  22. <img class="brand__logo brand__logo--light" src="../../assets/img/astrologue-light.png" width="392" height="89" alt="Astrologue">
  23. <img class="brand__logo brand__logo--dark" src="../../assets/img/astrologue-dark.png" width="392" height="89" alt="Astrologue">
  24. </a>
  25. <nav class="site-nav" aria-label="Primary">
  26. <ul class="site-nav__list">
  27. <li><a href="../../">Home</a></li>
  28. <li><a href="../../#news">News</a></li>
  29. <li><a href="../../#download">Download</a></li>
  30. <li><a href="../" aria-current="page">Developer</a></li>
  31. <li><a class="nav-cta" href="../../#download">Get Astrologue</a></li>
  32. </ul>
  33. </nav>
  34. </div>
  35. </header>
  36. <main id="main">
  37. <nav class="breadcrumb" aria-label="Breadcrumb">
  38. <div class="container">
  39. <ol>
  40. <li><a href="../../">Astrologue</a></li>
  41. <li><a href="../">Developer</a></li>
  42. <li aria-current="page">Vallama</li>
  43. </ol>
  44. </div>
  45. </nav>
  46. <section class="docs-header">
  47. <div class="container">
  48. <p class="kicker"><span>Intelligence · Language models, locally</span></p>
  49. <h1>Vallama</h1>
  50. <p class="lede">High-level Vala bindings for llama.cpp LLM inference: chat sessions, grammar-constrained tool calling, embeddings and tokenizers — running on your own hardware, with no cloud in sight.</p>
  51. <dl class="docs-facts">
  52. <div><dt>Version</dt> <dd><code>0.1.0</code></dd></div>
  53. <div><dt>Licence</dt> <dd>LGPL-3.0-or-later</dd></div>
  54. <div><dt>Package</dt> <dd><code>usm&nbsp;install&nbsp;vallama</code></dd></div>
  55. <div><dt>Language</dt> <dd>Vala</dd></div>
  56. </dl>
  57. </div>
  58. </section>
  59. <section class="band band--plain" id="docs">
  60. <div class="container docs-layout">
  61. <nav class="docs-toc" aria-label="On this page">
  62. <h2>On this page</h2>
  63. <ul>
  64. <li><a href="#overview">Overview</a></li>
  65. <li><a href="#features">Features</a></li>
  66. <li><a href="#installation">Installation</a></li>
  67. <li><a href="#usage">Usage &amp; documentation</a></li>
  68. <li><a href="#package">Package &amp; source</a></li>
  69. </ul>
  70. </nav>
  71. <div class="docs-prose">
  72. <header class="section-head" id="overview">
  73. <p class="kicker"><span>Overview</span></p>
  74. <h2>Why it exists</h2>
  75. </header>
  76. <p>Vallama is a high-level Vala library for running LLM inference with llama.cpp, with native tool calling. It wraps the model, context, sampler and tokenizer objects of the C API into a small set of Vala classes — <code>Model</code>, <code>Context</code>, <code>Sampler</code>, <code>Generator</code>, <code>ChatSession</code>, <code>Embedder</code> — and takes care of the parts of llama.cpp that bite: chat templates, grammar ordering, streaming callbacks, and the context parameters that are fixed at creation.</p>
  77. <p>It is built the way the rest of the stack is built: the collections underneath are <a href="../invercargill/">Invercargill</a>, so transcripts and tool lists are <code>Enumerable</code> sequences rather than bare arrays, and the examples that ship in <code>examples/</code> are the runnable versions of every idiom on this page.</p>
  78. <p>Because the model file is a local GGUF and the inference is local compute, an application built on Vallama depends on no cloud service, sends nothing anywhere, and keeps working when the network does not — the same decentralised stance the rest of Astrologue takes.</p>
  79. <header class="section-head" id="features">
  80. <p class="kicker"><span>Features</span></p>
  81. <h2>What it hands you</h2>
  82. </header>
  83. <ul class="docs-features">
  84. <li><strong>Native tool calling.</strong> OpenAI-style tool calling driven by grammar-constrained decoding: when tools are registered, the assistant turn is generated under a GBNF grammar compiled from the tool schemas, so the model can only emit a valid tool-call envelope.</li>
  85. <li><strong>Chat sessions.</strong> <code>ChatSession</code> wraps Model + Context + Sampler, keeps the transcript, formats prompts, runs constrained turns, and offers <code>run_with_tools</code> to drive the whole loop via a callback.</li>
  86. <li><strong>Streaming generation.</strong> <code>generate_stream</code> and <code>respond_stream</code> hand each decoded piece to a callback, so interfaces can print as the model thinks.</li>
  87. <li><strong>KV-cache priming.</strong> <code>prime()</code> pre-evaluates a long system prompt once; <code>save()</code>/<code>load()</code> persist the resulting KV state to a file so later runs skip the expensive evaluation and start generating immediately.</li>
  88. <li><strong>Embeddings.</strong> A high-level text-embedding API on llama.cpp's sequence pooling: CLS, MEAN and LAST_TOKEN pooling, L2-normalised vectors, and batched <code>embed_all</code> over independent sequences.</li>
  89. <li><strong>Tokenizers.</strong> Exposed directly for piece-level work, with the grammar sampler attachable to any chain.</li>
  90. <li><strong>Chat templates handled.</strong> The model's template when it expands, an exact ChatML fallback otherwise, and a hand-rolled ChatML renderer whenever tool turns are in the transcript.</li>
  91. </ul>
  92. <header class="section-head" id="installation">
  93. <p class="kicker"><span>Installation</span></p>
  94. <h2>Getting the library</h2>
  95. </header>
  96. <p>With USM on your machine, one command acquires, builds and installs the library with its headers, Vala bindings and introspection:</p>
  97. <figure class="code-plate">
  98. <pre><code>usm install vallama</code></pre>
  99. <figcaption>USM resolves <code>invercargill-1</code> and llama.cpp itself.</figcaption>
  100. </figure>
  101. <p>From source, the stack's one-build discipline:</p>
  102. <figure class="code-plate">
  103. <pre><code>git clone &lt;the Vallama repository&gt;
  104. cd Vallama
  105. meson setup build
  106. ninja -C build
  107. ninja -C build install</code></pre>
  108. <figcaption>Needs llama.cpp (with <code>llama.pc</code>), GLib and <code>invercargill-1</code> — the version this page documents is verified against llama.cpp b6153.</figcaption>
  109. </figure>
  110. <p>Then compile against it with Vala's usual package mechanism:</p>
  111. <figure class="code-plate">
  112. <pre><code>valac --pkg vallama-0.1 my-program.vala</code></pre>
  113. <figcaption>The binding pulls in its <code>.deps</code> chain — GLib, GObject and Invercargill — automatically.</figcaption>
  114. </figure>
  115. <header class="section-head" id="usage">
  116. <p class="kicker"><span>Usage &amp; documentation</span></p>
  117. <h2>From the README and examples</h2>
  118. </header>
  119. <p>Generation streams piece by piece, with model, context and sampler split the way llama.cpp splits them:</p>
  120. <figure class="code-plate">
  121. <pre><code>Vallama.init();
  122. var model = new Model (model_path, ModelOptions.defaults ());
  123. var ctx_opts = ContextOptions.defaults ();
  124. ctx_opts.n_ctx = 2048;
  125. ctx_opts.n_threads = 8;
  126. var ctx = new Context (model, ctx_opts);
  127. var sampler = new Sampler (SamplerOptions.defaults ());
  128. var generator = new Generator (ctx, sampler);
  129. generator.generate_stream (prompt, max_tokens, (piece, token, is_final) =&gt; {
  130. print ("%s", piece);
  131. return true; // false stops generation
  132. });</code></pre>
  133. <figcaption>Condensed from <code>examples/simple.vala</code> — load a GGUF and generate.</figcaption>
  134. </figure>
  135. <h3>Tool calling, the headline feature</h3>
  136. <p>Tools are declared with a small JSON-schema-ish API, compiled into a grammar that only accepts a valid call envelope (or a <code>respond</code> envelope carrying plain language):</p>
  137. <figure class="code-plate">
  138. <pre><code>var city = new ToolParam ("city", ToolParamType.STRING, true, "City name");
  139. var tool = new ToolSpec ("get_weather", "Get current weather", params);</code></pre>
  140. <figcaption>From the README. The envelope: <code>{"name": "get_weather", "arguments": {"city": "Paris", "unit": "celsius"}}</code>.</figcaption>
  141. </figure>
  142. <p><code>ChatSession</code> keeps the transcript and runs the constrained loop:</p>
  143. <figure class="code-plate">
  144. <pre><code>var session = new ChatSession (model, ctx, sampler);
  145. session.add_tools (tools);
  146. session.add_message (new ChatMessage (ChatRole.SYSTEM, system_prompt));
  147. if (session.chat ("Weather in Paris?") == ChatTurnResult.TOOL_CALL) {
  148. var call = session.last_tool_call;
  149. string result = execute (call); // your code
  150. session.append_tool_result (call, result);
  151. session.chat (null); // final prose turn
  152. print ("%s\n", session.last_message_text ());
  153. }</code></pre>
  154. <figcaption>Verbatim from the README. <code>run_with_tools (message, executor)</code> drives the whole loop via a callback.</figcaption>
  155. </figure>
  156. <p>The whole assistant turn stays inside one JSON envelope on purpose: GBNF cannot express "any text OR this JSON", so the <code>respond</code> pseudo-tool gives the model a clean escape hatch while every turn stays parseable. The parser accepts both the bare envelope and Qwen2.5-style <code>&lt;tool_call&gt;</code> markup.</p>
  157. <h3>Caching the system prompt</h3>
  158. <p>Pre-evaluate a long system prompt once and reuse the KV state — across turns in one run, or from a file in the next:</p>
  159. <figure class="code-plate">
  160. <pre><code>generator.prime (SYSTEM_PROMPT); // evaluate once, keep KV state
  161. generator.save ("/path/to/cache.bin"); // persist it
  162. // a later run:
  163. generator.load ("/path/to/cache.bin"); // skip prompt evaluation,
  164. generator.respond ("Why is the sky blue?");</code></pre>
  165. <figcaption><code>examples/cache.vala</code> primes, saves, restores and measures the speed-up end to end.</figcaption>
  166. </figure>
  167. <h3>Embeddings</h3>
  168. <p>One text or many, L2-normalised, with the pooling mode the model wants:</p>
  169. <figure class="code-plate">
  170. <pre><code>var model = new Vallama.Model ("/path/Qwen3-Embedding-0.6B-Q8_0.gguf");
  171. var embedder = new Vallama.Embedder (model, Vallama.Pooling.LAST_TOKEN, ctx_opts);
  172. int dimensions = embedder.dimensions; // model n_embd, e.g. 1024
  173. float[] query = embedder.embed ("Query: a city at the bottom of New Zealand");
  174. var texts = new Invercargill.DataStructures.Vector&lt;string&gt; ();
  175. texts.add ("Invercargill is the southernmost city in New Zealand.");
  176. float[] docs = embedder.embed_all (texts); // flat row-major
  177. float[] doc0 = embedder.vector_at (docs, 0); // slice row 0</code></pre>
  178. <figcaption>From the README. Cosine similarity of two vectors is their dot product — every vector comes back normalised.</figcaption>
  179. </figure>
  180. <p>The test suite runs offline — <code>meson test</code> needs no model file: it pins the pooling mapping, normalisation maths, ChatML round-trips, envelope parsing (including malformed input) and template fallback selection, and validates the GBNF compiler's output through llama.cpp's own grammar parser. Live-model runs gate on <code>VALLAMA_TEST_MODEL=/path/to/model.gguf</code>; without the variable the examples print their API surface and exit cleanly.</p>
  181. <header class="section-head" id="package">
  182. <p class="kicker"><span>Package &amp; source</span></p>
  183. <h2>The ledger</h2>
  184. </header>
  185. <dl class="docs-package">
  186. <div><dt>Version</dt><dd><code>0.1.0</code> (from <code>MANIFEST.usm</code>)</dd></div>
  187. <div><dt>Licence</dt><dd>LGPL-3.0-or-later — free to run, study, share and improve; the LGPL keeps it free to link from any program.</dd></div>
  188. <div><dt>Package</dt><dd><code>usm install vallama</code></dd></div>
  189. <div><dt>Provides</dt><dd><code>libvallama-0.1.so</code>, <code>vallama-0.1.h</code> and <code>vallama-llama-shim.h</code>, <code>vallama-0.1.vapi</code> + <code>.deps</code> plus the <code>llama.vapi</code> binding in <code>share/vala/vapi</code>, <code>Vallama-0.1.gir</code>, <code>vallama-0.1.pc</code></dd></div>
  190. <div><dt>Needs at runtime</dt><dd>GLib, GObject, <code>libinvercargill-1.so</code>, <code>libjson-glib-1.0.so</code>, and llama.cpp's <code>libllama.so</code>. A GGUF model file of your choosing.</dd></div>
  191. <div><dt>Source</dt><dd>The repository <code>clanker/Vallama</code> on the Astrologue forge (git over ssh, port 222). Free software: the licence guarantees your right to the source.</dd></div>
  192. </dl>
  193. <nav class="docs-siblings" aria-label="Related in the catalogue">
  194. <p>Its neighbours:</p>
  195. <ul>
  196. <li><a href="../invercargill/">Invercargill</a></li>
  197. <li><a href="../locksmith/">Locksmith</a></li>
  198. <li><a href="../usm/">USM</a></li>
  199. </ul>
  200. </nav>
  201. <nav class="docs-pager" aria-label="Project pages">
  202. <a class="docs-pager__link docs-pager__link--prev" href="../locksmith/">
  203. <span>Previous</span>
  204. <strong>Locksmith</strong>
  205. </a>
  206. <p class="docs-pager__up"><a href="../">All eleven</a></p>
  207. <a class="docs-pager__link docs-pager__link--next" href="../usm/">
  208. <span>Next in the catalogue</span>
  209. <strong>USM</strong>
  210. </a>
  211. </nav>
  212. </div>
  213. </div>
  214. </section>
  215. </main>
  216. <footer class="site-footer">
  217. <div class="container">
  218. <div class="footer-grid">
  219. <div class="foot-brand">
  220. <img class="brand__logo brand__logo--dark" src="../../assets/img/astrologue-dark.png" width="392" height="89" alt="Astrologue">
  221. <p>An operating system for change — kept for self sufficiency, resilience, and software freedom, so regular people can hold the power of general purpose computers in their own hands.</p>
  222. </div>
  223. <nav aria-label="The four freedoms">
  224. <p class="foot-title">The Four Freedoms</p>
  225. <ol class="freedoms">
  226. <li><strong>Run</strong> the software as you wish, for any purpose.</li>
  227. <li><strong>Study</strong> the source and change it to do your computing as you wish.</li>
  228. <li><strong>Share</strong> copies so you can help others.</li>
  229. <li><strong>Modify</strong> and publish your versions so everyone benefits.</li>
  230. </ol>
  231. </nav>
  232. <nav aria-label="Site">
  233. <p class="foot-title">Site</p>
  234. <ul class="foot-list">
  235. <li><a href="../../">Home</a></li>
  236. <li><a href="../../#news">News</a></li>
  237. <li><a href="../../#download">Download</a></li>
  238. <li><a href="../">Developer</a></li>
  239. </ul>
  240. </nav>
  241. </div>
  242. <p class="colophon">Set in Cinzel and EB Garamond (SIL Open Font License). Astrologue is free software, licensed GPL-3.0-or-later: take it, tend it, pass it on. The libraries are LGPL-3.0-or-later, so they remain free to link.</p>
  243. </div>
  244. </footer>
  245. </body>
  246. </html>