|
| 1 | +# PyImageJ LLM Support |
| 2 | + |
| 3 | +This directory contains a complete framework for learning PyImageJ with Large Language Models (LLMs) like Gemini, ChatGPT, and Claude. The system uses modular persona and ruleset files to customize AI responses for different experience levels and environments. |
| 4 | + |
| 5 | +## 🚀 Quick Start with Google Colab |
| 6 | + |
| 7 | +The easiest way to get started is with our interactive Colab notebook: |
| 8 | + |
| 9 | +**➡️ [Open PyImageJ AI Guide in Colab](pyimagej-ai-guide.ipynb)** |
| 10 | + |
| 11 | +This notebook will: |
| 12 | +1. 📦 Download PyImageJ source and AI templates |
| 13 | +2. 🤖 Configure Gemini based on your experience level |
| 14 | +3. ⚖️ Set coding rules for your target environment |
| 15 | +4. 🏝️ Set up a complete Fiji bundle for analysis |
| 16 | +5. 🚀 Guide you through personalized learning activities |
| 17 | + |
| 18 | +The setup takes ~2-3 minutes on first run, then you're ready to learn with AI assistance! |
| 19 | + |
| 20 | +### Secondary Colab Notebook Uses |
| 21 | + |
| 22 | +* As this notebook contains robust PyImageJ initialization, coupled with extensive PyImageJ LLM rulesets, it can be used as a starting point for notebook development even by advanced developers |
| 23 | + |
| 24 | +## 📁 Framework Components |
| 25 | + |
| 26 | +### `pyimagej-ai-guide.ipynb` |
| 27 | +Interactive Colab notebook that orchestrates the entire learning experience. Features: |
| 28 | +- Experience-based persona selection (beginner/intermediate/advanced) |
| 29 | +- Environment-specific coding rules (Colab/Desktop/Headless/Script Editor) |
| 30 | +- Notebook-safe Fiji setup and PyImageJ integration |
| 31 | +- Easy transfer of persona text to other LLMs |
| 32 | + |
| 33 | +### `personas/` Directory |
| 34 | +Modular AI personality guides which can be combined and used to establish tailored persona and training roles. |
| 35 | + |
| 36 | +- **`base_persona.md`** - Core PyImageJ teaching approach |
| 37 | +- **Activity Files** - Experience-specific learning paths: |
| 38 | + - `activities/coding_*.md` - Core programming concepts |
| 39 | + - `activities/pyimagej_*.md` - Image procesing with PyImageJ |
| 40 | + - `activities/colab_*.md` - Useful Google Colab skills |
| 41 | + |
| 42 | +### `rulesets/` Directory |
| 43 | +Technical guidelines for how AI should write PyImageJ code. Select the ruleset appropriate for the environment you will be running your code. |
| 44 | + |
| 45 | +- **`pyimagej_core.md`** - Universal PyImageJ best practices |
| 46 | +- **Environment-specific rules** in `environments/` subdirectory: |
| 47 | + - `environments/env_colab.md` - Google Colab considerations |
| 48 | + - `environments/env_interactive.md` - Desktop GUI environments |
| 49 | + - `environments/env_headless.md` - Server/cluster environments |
| 50 | + - `environments/env_scripteditor.md` - Fiji Script Editor integration |
| 51 | + |
| 52 | +## 🔧 Using with Other LLMs |
| 53 | + |
| 54 | +While designed for Gemini in Colab, you can use these files with any LLM: |
| 55 | + |
| 56 | +### With ChatGPT, Claude, etc. |
| 57 | + |
| 58 | +1. **Run the Colab notebook** to generate your personalized content |
| 59 | +2. **Copy the output** using the provided copy buttons ("📋 Copy AI Configuration for Other LLMs" cell) |
| 60 | +3. **Paste into your preferred LLM** as context |
| 61 | + |
| 62 | +Or manually combine files: |
| 63 | + |
| 64 | +```bash |
| 65 | +# Example: Advanced PyImageJ user in headless environment |
| 66 | +cat personas/base_persona.md \ |
| 67 | + personas/activities/pyimagej_advanced.md \ |
| 68 | + rulesets/pyimagej_core.md \ |
| 69 | + rulesets/environments/env_headless.md > my_context.md |
| 70 | +``` |
| 71 | + |
| 72 | +### Prompt Template |
| 73 | +``` |
| 74 | +I'm learning PyImageJ for scientific image analysis. Please use this context to guide our conversation: |
| 75 | +
|
| 76 | +[PASTE PERSONA/RULESET CONTENT HERE] |
| 77 | +
|
| 78 | +I'm ready to start! What activities do you recommend based on my experience level? |
| 79 | +``` |
| 80 | + |
| 81 | +## 🤝 Contributing |
| 82 | + |
| 83 | +To extend this framework: |
| 84 | + |
| 85 | +- **Add new personas** in `personas/activities/` using the naming pattern `{category}_{level}.md` (e.g., `statistics_beginner.md`) |
| 86 | +- **Create environment rules** in `rulesets/environments/` using the pattern `env_{environment}.md` (e.g., `env_docker.md`) |
| 87 | +- **Update the notebook** to fix bugs, improve the documentation, or add more features |
| 88 | + |
| 89 | +### 🔄 Automated Updates |
| 90 | + |
| 91 | +The framework includes GitHub Actions automation to keep the notebook synchronized with persona and ruleset files: |
| 92 | + |
| 93 | +1. **Auto-detection**: GitHub Action triggers on commits to `main` that modify `personas/` or `rulesets/` files |
| 94 | +2. **Smart updates**: Uses Jinja templates to regenerate the "Personalize Gemini" and "Set Coding Rules" cells |
| 95 | +3. **Commit tracking**: Updates the download cell to use the exact commit SHA that triggered the update |
| 96 | +4. **Zero maintenance**: Persona dropdowns and environment options automatically reflect new files |
| 97 | +5. **Branch safety**: Builds on development branches must be triggered manually. The commit is generated as a `WIP`, which is blocked from merging by PR |
| 98 | + |
| 99 | +#### File naming requirements |
| 100 | +- **Personas**: `personas/activities/{category}_{level}.md` where level is `beginner`, `intermediate`, or `advanced` |
| 101 | + - You can create just one level (e.g., only `statistics_beginner.md`) or any combination |
| 102 | + - Missing levels are automatically skipped - no need to create all three |
| 103 | +- **Rulesets**: `rulesets/environments/env_{environment}.md` for new target environments |
| 104 | +- **Ordering**: Categories appear in order: `colab` → `coding` → `pyimagej` → (new categories alphabetically) |
| 105 | + |
| 106 | +#### To add new categories |
| 107 | +1. Create activity files: `newcategory_beginner.md` (and optionally `_intermediate.md`, `_advanced.md`) |
| 108 | +2. Commit to trigger the automation |
| 109 | +3. The notebook will automatically include the new category with only the levels you created |
| 110 | + |
| 111 | +#### Template locations |
| 112 | +- Automation scripts: `.github/workflows/update-notebook.yml` |
| 113 | +- Jinja templates: `.github/templates/` |
| 114 | +- Update logic: `.github/scripts/update_notebook.py` |
| 115 | + |
| 116 | +### 🌿 Branch Development Workflow |
| 117 | +**Automatic updates only run on `main`** to keep the main branch history clean. For development: |
| 118 | + |
| 119 | +1. Edit persona/ruleset files on your feature branch |
| 120 | +2. Manually test automation by going to **Actions** → **Update PyImageJ AI Guide Notebook** → **Run workflow** → select your branch |
| 121 | +3. This creates `WIP: Auto-update...` commits on your branch (clearly marked as temporary) |
| 122 | +4. Continue development normally |
| 123 | + |
| 124 | +##### Running the automation manually |
| 125 | +You can also manually apply the `update_notebook` script from the repository root: |
| 126 | + |
| 127 | +```bash |
| 128 | +COMMIT_SHA={commit} BRANCH_NAME={branch} python .github/scripts/update_notebook.py |
| 129 | +``` |
| 130 | + |
| 131 | +#### Merging to main |
| 132 | +1. Before creating a PR, ensure no `WIP:` commits will be merged: |
| 133 | + - Option A: Rebase/squash to remove WIP commits |
| 134 | + - Option B: Manually change commit messages to remove `WIP:` prefix |
| 135 | +2. Create PR to `main` - the **Check for WIP commits** workflow will verify no temporary commits remain |
| 136 | +3. After merge, automation runs automatically and creates a clean `Auto-update...` commit on `main` |
| 137 | + |
| 138 | +### Emergency options |
| 139 | +- Add `[skip-automation]` to any commit message to prevent automation |
| 140 | +- Use `workflow_dispatch` with "force update" to regenerate the notebook anytime |
| 141 | + |
| 142 | +## 📚 Learn More |
| 143 | +- [ImageJ Community Forum](https://forum.image.sc/) |
| 144 | +- [PyImageJ Documentation](https://pyimagej.readthedocs.io/) |
0 commit comments