Skip to main content

text-generation · function calling · WebGPU / WebAssembly · fp16 (~590.8 MB)

FunctionGemma 270M — On-device function calling in your browser

FunctionGemma 270M is Google's 270-million-parameter Gemma 3 checkpoint specialized for structured tool use. Feed it JSON tool schemas and a natural-language request, and it emits strict <start_function_call> tokens directly in a Web Worker — turning plain English into typed JavaScript calls with zero server round-trips and zero API keys.

Unlike general chat models, FunctionGemma uses a dedicated developer role, <start_function_declaration> schema blocks, and <escape>-delimited arguments. Because gemma3_text and its tool chat template require Transformers.js v4, this model's worker pins Transformers.js 4.3.0 locally (shared lib/webai.js remains on 3.7.5).

At a glance

FunctionGemma 270M technical specifications
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…

Tool pack presets

Edit the JSON schemas or switch presets above. Every tool is injected into the developer turn as a <start_function_declaration> block.

Example prompts

Decoding & developer-prompt controls

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.
Shows whether <start_function_call> wins the first decoding step.
Top-12 next-token probabilities appear here.

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.

Use cases

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>

References