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", device_map="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
| """Recover gemma-4 coder tool_calls WITHOUT litellm (or any framework). | |
| Call your llama.cpp / OpenAI-compatible endpoint however you like, then run | |
| `recovered_tool_calls()` on the assistant message text. The heavy lifting is in | |
| `gemma_tool_parse.py` (pure stdlib) — this file is just the thin OpenAI-shape glue. | |
| Run me directly for a demo: python standalone.py | |
| """ | |
| from __future__ import annotations | |
| import json | |
| from gemma_tool_parse import clean_content, find_tool_calls | |
| def recovered_tool_calls(completion_text: str) -> tuple[list[dict], str | None]: | |
| """Turn a raw gemma-4 completion into OpenAI-style tool_calls. | |
| Returns (tool_calls, leftover_content). When no call is present, tool_calls is | |
| empty and leftover_content is the cleaned text (or None if it was pure markup). | |
| """ | |
| calls, leftover = find_tool_calls(completion_text) | |
| if not calls: | |
| return [], (clean_content(completion_text) or None) | |
| tool_calls = [ | |
| { | |
| "id": f"call_{i}", | |
| "type": "function", | |
| "function": { | |
| "name": c["name"], | |
| "arguments": json.dumps(c["arguments"], ensure_ascii=False), | |
| }, | |
| } | |
| for i, c in enumerate(calls) | |
| ] | |
| return tool_calls, (leftover or None) | |
| if __name__ == "__main__": | |
| # The model leaks its call into `content` as native markup instead of structured | |
| # tool_calls; recover it into the shape an OpenAI client expects. | |
| demo = 'Sure! <|tool_call>call:get_weather{"city": "Paris", "units": "celsius"}' | |
| tcs, content = recovered_tool_calls(demo) | |
| print(json.dumps({"tool_calls": tcs, "content": content}, indent=2, ensure_ascii=False)) | |