call_me_maybe - README

call_me_maybe

Python project · featured · LLM, constrained decoding

Turns a sentence into a JSON function call with a 0.6B model using constrained decoding — parseable by construction, not by luck.

The problem

Turn a sentence like "What is the sum of 40 and 2?" into a function call in JSON, using Qwen3-0.6B: a model so small that asking it nicely for JSON only works some of the time.

What I built

The hard part

The first version forbade tokens that spanned two grammar segments. It looked harmless, but a byte-level vocabulary holds "}} as one token, so the model had no natural way to close a string and started rambling. Letting a token cross into the text that follows fixed it: the score went from 15/22 to 17/22 and the run time from 51 s to 25 s. It also made the anti-rambling hacks I had added unnecessary, so I removed them.

What it looks like

$ uv run python -m src --verbose
[1/11] {"name": "fn_add_numbers", "parameters": {"a": 2, "b": 3}}  (6 chosen + 18 forced tokens)
[3/11] {"name": "fn_greet", "parameters": {"name": "shrek"}}  (6 chosen + 13 forced tokens)
11/11 calls generated in 27.0s (98 tokens chosen by the model, 198 filled in by the grammar)

Built with

More projects