Repository navigation
0.15.0
Tool calling, a camera and microphone that Python can ask for, and a WebGPU that falls back to WASM instead of failing. The embedding and classification options of LLM that 0.14.0 deprecated are removed.
Upgrading
LLMno longer embeds or classifies.LLM.create(embedding_model=...)andLLM.create(classification_model=...)now raise aTypeError, andllm.embed(),llm.classify()andllm.similarity_search()are gone. UseEmbedder.create(model)andClassifier.create(model); the 0.14.0 release notes show the one-for-one replacement. A model that was loaded together with a generator is now a second object with its owndispose().- Notebooks are renumbered again, to go from language models to pipelines to low-level material. Old notebook URLs (
?path=ch17_streaming.ipynband the others) no longer exist. The new order is: 01 to 05 unchanged; 06 tool calling, 07 streaming, 08 token probabilities; 09 embeddings, 10 classification, 11 orchestration; 12 tasks, 13 vision, 14 image outputs, 15 camera, 16 speech, 17 microphone; 18 tokenizers, 19 ONNX models, 20 text to image, 21 WebGPU;ch99is unchanged.
New
- WebGPU falls back to WASM. With
backend="webgpu", a browser with no WebGPU adapter, or a failure that is specific to WebGPU (a lost device, a shader or buffer limit, an operator or float16 the adapter lacks), now loads the model on WASM once and says why.llm.backend(andEmbedder,Classifier,Pipeline,OnnxModel) report the backend that ran, andbackend_fallback_reasonsays why it changed. Out-of-memory and fetch errors are not retried, since WASM would hit them too. Passbackend_fallback=Falseto fail instead. The default backend is still"wasm". Failures are recognised by their wording, so a runtime message outside the pattern is raised, not retried; software adapters are not detected. See #111 and "WebGPU fallback" in the parameters reference. ToolRunner: validated tool calling (ToolRunner,Tool,AgentResult,model_tool). A model replies with a JSON tool call or an answer; the tool name and arguments are checked against the registered tools and their schemas before anything runs, so an unknown tool or invalid arguments never execute. The refusal goes back to the model and uses a step. The loop stops on an answer, the step limit, a timeout or a cancel, andAgentResult.stepsrecords every reply and its outcome. After a tool has run, a reply with no JSON object in it is the answer. See #77.- A tool-calling notebook,
ch06_tool-calling. It runs Qwen2.5-0.5B-Instruct (q4, about 790 MB) throughToolRunneron WebGPU when the browser has a hardware adapter, on WASM otherwise, and shows with a scripted model what happens to an unknown tool, invalid arguments, non-JSON and the step limit. The model is small: in the measurements behind the notebook it chose the right tool for 5 of 8 questions, so treat that run as a demonstration. CameraCapture.request()andAudioRecorder.request()show a prompt in the widget and wait for the user to tap before capturing, so Python can ask for a photo or a recording. A request resolves only with media captured for it, and raisesCaptureCancelledon Cancel,TimeoutErroron a timeout, and the browser's error when the camera or microphone is refused. Every ending releases the device. See #78.
Changed
- A failed fetch is reported as a fetch. A load error of
Load failed(Safari),Failed to fetch(Chrome) orNetworkError(Firefox) used to get the advice that the model may not be supported by the backend. It now says a file could not be fetched and how to find which one, and suggests the other backend only after a WebGPU failure. See #109. - ch20 (text to image) and ch21 (WebGPU) pass
backend_fallback=False, so they cannot run on WASM without saying so. - The two Voici apps (
camera-objects,speak-french) ask forbackend="webgpu"instead of"wasm", and run on WASM where WebGPU is missing or fails to load. Only the fallback path was run, in headless Chromium without a GPU (voici-smoke); they were not run on a real GPU or a phone.
Fixed
- A tool call that was cut off or malformed ended a
ToolRunnerrun. After a tool ran, a reply thatjson.loadsrejected, such as a call cut off at the token limit or with a trailing comma, became the final answer. A reply is now prose only when it has no opening brace; anything that looks like JSON but does not parse goes back to the model. See #108.
Docs
- Running a static embedding model (POTION) with
OnnxModelandtokenizer()is documented in the ONNX guide (#94).
Notes
- Only the WebGPU fallback in the no-adapter case was run in a real browser (headless Chromium,
backend-fallback-smoke), plus ch21 on an Apple GPU. A WebGPU failure after a successful adapter check is covered by tests with mocks, not a real browser. - ch20 and ch06 were not re-run in a browser with these changes.
- Real Safari is still untested.
- Making WebGPU the default backend is tracked in #114.