Skip to main content

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, and Shapes
  • 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:

  • dilate
  • erode
  • open
  • close
  • fill_holes
  • remove_small
  • keep_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 Code Executes the pending code inside the plugin.
  • Copy Pending Code Copies 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

  1. Start napari.
  2. Open Plugins -> Chat Assistant.
  3. Leave Base URL as http://127.0.0.1:11434 unless your Ollama server is elsewhere.
  4. Choose a model from the Model dropdown or type a model tag manually.
  5. Click Test Connection.
  6. 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 layers
  • inspect the selected layer
  • inspect layer LV-nerve
  • preview threshold for the selected image
  • apply threshold for dim objects
  • measure the current mask
  • write napari code to duplicate the selected layer
  • give 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 Code
  • Copy Pending Code
  • Discard 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:

  1. collect structured napari viewer context
  2. send that context and the user request to a local Ollama model
  3. let the model return one JSON response
  4. interpret that response as either:
    • a normal reply
    • a built-in tool call
    • generated Python code
  5. 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.5
  • qwen3.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 Code when 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

napari_chat_assistant-0.0.1.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

napari_chat_assistant-0.0.1-py3-none-any.whl (21.7 kB view details)

Uploaded Python 3

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

Hashes for napari_chat_assistant-0.0.1.tar.gz
Algorithm Hash digest
SHA256 46344c5fe8f9f06204d584f3349da977bf6d4c09cd9adb9b6f1499d06104081e
MD5 77a5ce39be2792fff185a414ae3eae5c
BLAKE2b-256 09fd228b2ce259b96fbd7709fd9e6d318e2f48d06e33b0dc51277b560cf1a9c9

See more details on using hashes here.

File details

Details for the file napari_chat_assistant-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for napari_chat_assistant-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 132fe30b1994f30e39840622a5ca7a3638615e30dacc788c809e91499d12a9f5
MD5 2f3a5aea6551827790ba56564fc868b1
BLAKE2b-256 ee9eacd52e49728a47e7502a3b3ca70f5d8931c15d1a7ae38c03ab342d686fb2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page