Spaces:
Sleeping
Sleeping
| title: LFM2.5 Tool Use | |
| emoji: π οΈ | |
| colorFrom: blue | |
| colorTo: purple | |
| sdk: gradio | |
| sdk_version: 5.49.1 | |
| app_file: app.py | |
| pinned: false | |
| tags: | |
| - tool-use | |
| - liquid | |
| - lfm2.5 | |
| - zerogpu | |
| # LFM2.5-1.2B-Thinking Tool-Calling Demo | |
| A Hugging Face **ZeroGPU** Space that runs LiquidAI's [LFM2.5-1.2B-Thinking](https://huggingface.co/LiquidAI/LFM2.5-1.2B-Thinking) **in-process with `transformers`** and shows it performing tool (function) calling in a Gradio chat UI. | |
| > **Hardware:** set this Space to **ZeroGPU** in *Settings β Hardware* (then Restart). The `respond` handler is decorated with `@spaces.GPU`, so the model loads in `bfloat16` on an attached GPU per request. | |
| The model can call two mocked tools: | |
| - `web_search(query)` β returns canned search results | |
| - `send_email(to, subject, body)` β pretends to send an email | |
| ## How it works | |
| LFM2.5 emits tool calls in its native *Pythonic* format, wrapped in special tokens: | |
| ``` | |
| <|tool_call_start|>[web_search(query="liquid ai lfm")]<|tool_call_end|> | |
| ``` | |
| `app.py` parses that with the `ast` module, executes the matching tool, feeds the JSON result back as a `tool`-role message, and lets the model produce a final answer β looping up to 5 turns. Tokens stream into the UI as they generate. | |
| > Note: the LFM2.5-1.2B chat template has a known bug where a structured `tool_calls` field is dropped on re-render, which breaks multi-turn tool calling. To avoid it we store the raw assistant text (special tokens intact) in the conversation history instead of relying on `tool_calls`. | |
| ## ZeroGPU & bfloat16 | |
| The Space runs on **ZeroGPU** (shared GPU allocated per request). The model is loaded in `bfloat16` onto the attached GPU inside the `@spaces.GPU`-decorated handler β ~2.4 GB, well within a T4's 16 GB. Generation streams into the UI; the whole multi-turn loop runs within one `@spaces.GPU(duration=180)` call. | |
| ## Run locally | |
| ```bash | |
| pip install -r requirements.txt | |
| python app.py | |
| ``` | |
| Adapted from the original Ollama-based `main.py`. Tool-calling reference: [Liquid docs](https://docs.liquid.ai/lfm/key-concepts/tool-use). |