At a glance
| Model | onnx-community/functiongemma-270m-it-ONNX (ONNX build of google/functiongemma-270m-it) |
|---|---|
| Task | text-generation (specialized single/multi-turn function calling) |
| Architecture |
Gemma3ForCausalLM (model_type: gemma3_text), 270M params,
18 layers (5:1 sliding/full attention), 262,144 vocab, 32K context
|
| Dtype & backend |
WebGPU (when shader-f16 is available) or universal
WebAssembly (CPU) fallback — both load fp16
(onnx/model_fp16.onnx + sidecar). Verified empirically: 4-bit exports
(q4f16/q4) degrade 270M function-call syntax, whereas
fp16 emits exact canonical tool calls on both WebGPU and WASM at a
smaller footprint than q4 (590.8 MB vs. 821.9 MB).
|
| Download size |
590.8 MB decimal (onnx/model_fp16.onnx 0.62 MB +
model_fp16.onnx_data 569.86 MB + tokenizer/configs 20.35 MB; cached
after first download)
|
| Runtime |
Transformers.js 4.3.0, pinned locally in
models/functiongemma-270m/worker.js
|
| Special tokens |
<start_function_declaration>,
<end_function_declaration>,
<start_function_call>,
<end_function_call>,
<escape>,
<start_function_response>
|
| License |
gemma —
Gemma Terms of Use
(public ONNX repo, not gated)
|
| Web APIs | WebAssembly, Web Workers, ES module imports, Cache Storage (WebGPU optional) |
Run it — Function Calling Playground
Probing your browser's backend to show the exact download size…
Parsed tool invocation
Download or wait for the cached model to initialise, then submit a request to see
the parsed { name, arguments } tool call.
See inside — special tokens, prompt template & logits
FunctionGemma never relies on fragile regex over markdown JSON. Its tokenizer reserves
dedicated control tokens (<start_function_declaration>,
<start_function_call>, <escape>,
<end_function_call>). Below you can inspect the exact rendered prompt
sent into the 18-layer Gemma 3 decoder, the raw unstripped token stream, the structured
JSON call tree, and — from one real forward pass — the actual top-12 next-token
probabilities before decoding begins.
Raw generated tokens (special tokens preserved)
Run a prompt above to inspect raw special tokens.
Parsed JSON call tree
Structured { name, arguments } output appears here.
Exact developer + tools chat template
The exact string produced by tokenizer.apply_chat_template(messages, { tools }) appears here on run or logit peek.
<start_function_call> wins the first decoding step.
Why it matters
Most browser AI demos stop at free-form text chat. FunctionGemma 270M unlocks local browser agents: natural language that deterministically invokes real JavaScript functions in your page — filtering tables, drawing on canvas, controlling audio, or orchestrating local APIs — without shipping user data to a cloud endpoint.
- Strict grammar in 270M parameters — dedicated special tokens eliminate markdown fence drift and make client-side parsing deterministic.
- Private by architecture — personal schedules, expense tables, and browser actions never leave the user's device.
-
Runs with or without WebGPU — loads the same
fp16(590.8 MB) checkpoint on WebGPU (fast path) and WebAssembly CPU (universal fallback) without 4-bit tool-syntax degradation. - Composable with guard models — pair it with a tiny NLI guard in a second worker to screen untrusted prompts before executing tools.
Use cases
Basics — Tool Router & Argument Extractor
Switch across 4 real tool suites (Weather, Calendar, Smart Home, Calculator), inspect typed argument extraction, and execute the matched JS function live.
Practical — Natural-Language UI Controller
Drive a live expense table, SVG category chart, and budget controls with plain English — FunctionGemma mutates real DOM state with zero backend.
Wild — Natural-Language Canvas & Synth Studio
Paint geometric art on an HTML canvas and synthesize real Web Audio chords using structured FunctionGemma tool calls.
Multi-model — Two-Stage Safe Local Agent
Stage 1 (MobileBERT-MNLI) screens prompts for injection attacks before Stage 2 (FunctionGemma 270M) executes local vault tools.
How the API works
Pass your tool schemas to tokenizer.apply_chat_template(messages, { tools })
with a developer message, generate via model.generate(), and
decode with skip_special_tokens: false so
<start_function_call> and <escape> survive for
parsing:
import { pipeline, TextStreamer } from "@huggingface/transformers"; // v4.3.0+
const pipe = await pipeline(
"text-generation",
"onnx-community/functiongemma-270m-it-ONNX",
{ device: "wasm", dtype: "fp16" }, // or { device: "webgpu", dtype: "fp16" }
);
const tools = [{
type: "function",
function: {
name: "get_current_temperature",
description: "Gets the current temperature for a given location.",
parameters: {
type: "object",
properties: {
location: { type: "string", description: "City name, e.g. Tokyo" },
},
required: ["location"],
},
},
}];
const messages = [
{ role: "developer", content: "You are a model that can do function calling with the following functions" },
{ role: "user", content: "What's the temperature in Tokyo?" },
];
const inputs = pipe.tokenizer.apply_chat_template(messages, {
tools, tokenize: true, add_generation_prompt: true, return_dict: true,
});
const out = await pipe.model.generate({ ...inputs, max_new_tokens: 128, do_sample: false });
const raw = pipe.tokenizer.decode(
out.slice(0, [inputs.input_ids.dims[1], null]),
{ skip_special_tokens: false },
);
// → <start_function_call>call:get_current_temperature{location:<escape>Tokyo<escape>}<end_function_call>