Local chat assistant scaffold for napari image-analysis workflows
Project description
napari-chat-assistant
Local Ollama-powered chat assistant for napari image-analysis workflows.
napari-chat-assistant adds a dock widget to napari that stays aware of the current viewer, selected layer, and available layers. It can answer questions about the session, run a controlled set of built-in image-analysis actions, and generate Python code for napari when needed.
Overview
This plugin is designed for local interactive work inside napari.
Current capabilities:
- connect to a local Ollama server
- discover, pull, and unload local models from the plugin UI
- inspect napari layers and selected-layer properties
- run built-in thresholding and mask tools
- generate Python code for napari workflows
- copy generated code into the napari QtConsole
- optionally run generated code from the plugin
The current default model is:
qwen3.5
Why This Plugin
Most chat interfaces are detached from the napari viewer. This plugin keeps the assistant inside napari and grounds responses in the current session.
That means the assistant can:
- see the current layers
- see which layer is selected
- distinguish common napari layer kinds such as
Image,Labels,Points, andShapes - report layer dimensions, dtype, visibility, and related properties
- run explicit image-analysis actions rather than only talking about them
Current Features
Built-in Tool Actions
The assistant currently supports built-in tools for:
- listing all layers
- inspecting the selected layer
- inspecting a specific named layer
- threshold preview
- threshold apply
- batch threshold preview and apply
- mask measurement
- batch mask measurement
- mask morphology operations
Supported mask operations:
dilateerodeopenclosefill_holesremove_smallkeep_largest
Code Workflows
When the request is not covered by a built-in tool, the assistant can generate napari Python code.
There are two ways to use that code:
Run Pending CodeExecutes the pending code inside the plugin.Copy Pending CodeCopies the pending code to the clipboard so you can paste it into the napari QtConsole.
This is useful when you want:
- a script you can inspect first
- code you want to modify manually
- code to run in the napari QtConsole instead of through the plugin
Requirements
- Python 3.9+
- napari
- Ollama installed on the machine
- a local Ollama model such as
qwen3.5
The plugin package is self-contained for napari, but it does not bundle the Ollama server or model weights.
Installation
Step 1. Install Ollama Provider
Install Ollama on the machine first.
Start the local Ollama server:
ollama serve
Pull a model before using the plugin:
ollama pull qwen3.5
Optional stronger model:
ollama pull qwen3.5:27b
Step 2. Install The napari Plugin
Clone the repository and install the plugin:
git clone https://github.com/wteox2/napari-chat-assistant.git
cd napari-chat-assistant
pip install -e .
Usage
- Start napari.
- Open
Plugins -> Chat Assistant. - Leave
Base URLashttp://127.0.0.1:11434unless your Ollama server is elsewhere. - Choose a model from the
Modeldropdown or type a model tag manually. - Click
Test Connection. - Start chatting.
You do not need to rely only on free-form prompts. The plugin is strongest when you ask for concrete napari actions.
Examples:
show me my layersinspect the selected layerinspect layer LV-nervepreview threshold for the selected imageapply threshold for dim objectsmeasure the current maskwrite napari code to duplicate the selected layergive me QtConsole code to print the selected layer shape
UI Overview
Model Connection
- local Ollama base URL
- model picker with discovered local models
- test connection
- save current settings
- pull model
- unload model
Chat
- multi-line prompt box
- Enter to send
- Shift/Ctrl/Alt+Enter for newline
- transcript showing user messages, assistant replies, tool results, and generated code
Code Actions
Run Pending CodeCopy Pending CodeDiscard Pending Code
Current Context
- current layer summary from the active napari viewer
Action Log
- local status updates
- model connection messages
- tool execution messages
- code execution and copy actions
How It Works
The assistant is not a fully unrestricted chatbot.
The current strategy is:
- collect structured napari viewer context
- send that context and the user request to a local Ollama model
- let the model return one JSON response
- interpret that response as either:
- a normal reply
- a built-in tool call
- generated Python code
- run the selected tool or expose the generated code through the UI
This keeps the assistant more grounded than a plain chat interface and makes common operations more reliable.
Recommended Models
Good starting choices:
qwen3.5qwen3.5:27b
qwen3.5 is the current default because it has performed better in this plugin than the previous qwen2.5 default.
Current Limitations
- still an early-stage plugin
- model output can still be inconsistent, especially for generated code
- not all requests map cleanly to built-in tools yet
- generated code can still fail if the model invents incorrect napari APIs
- no multi-step planning loop yet
- no image attachment or multimodal input pipeline yet
- large 2D/3D volumes are not heavily optimized yet
For now, the most reliable path is:
- use built-in tools for common layer inspection and mask/image actions
- use
Copy Pending Codewhen you want to inspect or adjust Python yourself
Development
Editable install:
pip install -e .
Build a release artifact:
python -m build
License
MIT. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file napari_chat_assistant-0.0.1.tar.gz.
File metadata
- Download URL: napari_chat_assistant-0.0.1.tar.gz
- Upload date:
- Size: 21.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46344c5fe8f9f06204d584f3349da977bf6d4c09cd9adb9b6f1499d06104081e
|
|
| MD5 |
77a5ce39be2792fff185a414ae3eae5c
|
|
| BLAKE2b-256 |
09fd228b2ce259b96fbd7709fd9e6d318e2f48d06e33b0dc51277b560cf1a9c9
|
File details
Details for the file napari_chat_assistant-0.0.1-py3-none-any.whl.
File metadata
- Download URL: napari_chat_assistant-0.0.1-py3-none-any.whl
- Upload date:
- Size: 21.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
132fe30b1994f30e39840622a5ca7a3638615e30dacc788c809e91499d12a9f5
|
|
| MD5 |
2f3a5aea6551827790ba56564fc868b1
|
|
| BLAKE2b-256 |
ee9eacd52e49728a47e7502a3b3ca70f5d8931c15d1a7ae38c03ab342d686fb2
|