Instructions to use tpls/gemma4-tool-shim with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tpls/gemma4-tool-shim with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="tpls/gemma4-tool-shim")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("tpls/gemma4-tool-shim", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use tpls/gemma4-tool-shim with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tpls/gemma4-tool-shim" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tpls/gemma4-tool-shim", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/tpls/gemma4-tool-shim
- SGLang
How to use tpls/gemma4-tool-shim with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "tpls/gemma4-tool-shim" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tpls/gemma4-tool-shim", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "tpls/gemma4-tool-shim" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tpls/gemma4-tool-shim", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use tpls/gemma4-tool-shim with Docker Model Runner:
docker model run hf.co/tpls/gemma4-tool-shim
Gemma-4 Coder β tool-call recovery shim
A tiny, framework-free post-processor that recovers structured tool_calls from
gemma-4 12B coder GGUFs served on llama.cpp.
Why you need it
llama.cpp --jinja does not recognise gemma-4's native tool-call format, so the bare
parser under-reports tool calls. The model is fine β the parser is blind to the
format. The model emits a call as text in content:
<|tool_call>call:get_weather{"city": "Paris", "units": "celsius"}
This shim re-parses that (and the leaked variants different builds produce β
<|tool>NAME{β¦}, <call:NAME{β¦}>, NAME(k=v)<|/tool|>) back into the OpenAI shape
your client expects. It never touches the weights and adds nothing beyond a regex
scan.
Files
| File | What |
|---|---|
gemma_tool_parse.py |
the pure-stdlib core: call detection, tolerant arg parsing, content cleanup, and the serve-side tools-in-prompt block. No dependencies. |
standalone.py |
use it without any framework β call recovered_tool_calls(text) on a completion. Runnable demo. |
litellm_shim.py |
a drop-in litellm CustomLogger callback (pre-call folds tool defs + stop-strings; post-call recovers tool_calls). |
The algorithm (re-implement in any language)
- Scan the assistant
contentfor the native marker<|tool_call>and the leaked text forms (<|tool>NAME{β¦},<call:NAME{β¦}>, a bareNAME{β¦}/NAME(k=v)anchored on a tool marker). Names may be dotted (weather.get_weather). - Extract per match the tool name and the arguments object (balanced-brace
scan from the first
{; tolerate trailing prose, fancy quotes, bare keys,=or:). - Coerce scalar arg values (
"3"β3,"true"βtrue) so the downstream tool validates; leave unknown fields untouched. - Emit OpenAI
tool_calls[{"id","type":"function","function":{"name","arguments":<json-string>}}], setfinish_reason: "tool_calls", and strip the recovered markup fromcontent. - Pass through unchanged when no marker is found (plain answers are unaffected).
A second concern, also handled: the model was fine-tuned with tool definitions folded
into the prompt, so it only behaves if it sees the same block at serve time. Call
fold_tools_prompt(messages, tools) (in gemma_tool_parse.py) before sending.
Usage
Standalone (no litellm)
from standalone import recovered_tool_calls
tool_calls, content = recovered_tool_calls(assistant_text)
litellm
# config.yaml
litellm_settings:
callbacks: ["litellm_shim.shim"]
Set GEMMA_SHIM_MODELS=my-deploy-name to gate the shim to specific deployments
(default: all). litellm hook signatures vary across releases β litellm_shim.py is a
reference adapter; adjust the method names to your version if needed.
Models that use this
tpls/gemma-4-12B-coder-fable5-composer2.5-v1-abliterated-GGUFtpls/gemma-4-12B-coder-fable5-composer2.5-v1-sft-v5-GGUFtpls/Huihui-gemma-4-12B-coder-fable5-composer2.5-v1-abliterated-GGUF
Apache-2.0 β use it freely.