Skip to content

Commit 2105e37

Browse files
committed
Auto-update notebook cells
Updated from commit: 27d5781
1 parent 27d5781 commit 2105e37

File tree

1 file changed

+67
-45
lines changed

1 file changed

+67
-45
lines changed

doc/llms/pyimagej-ai-guide.ipynb

Lines changed: 67 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"id": "view-in-github"
88
},
99
"source": [
10-
"<a href=\"https://colab.research.google.com/github/imagej/pyimagej/blob/colab/doc/llms/pyimagej-ai-guide.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
10+
"<a href=\"https://colab.research.google.com/github/imagej/pyimagej/blob/main/doc/llms/pyimagej-ai-guide.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
1111
]
1212
},
1313
{
@@ -107,7 +107,7 @@
107107
" # --AUTO-GENERATED CONTENT--\n",
108108
" # The following line is automatically updated by GitHub Actions\n",
109109
" # to checkout the commit that triggered the workflow, ensuring consistency\n",
110-
" !cd /content/pyimagej && git checkout colab\n",
110+
" !cd /content/pyimagej && git checkout 27d5781849d6764b575a0a9b67e7e0766f263c8e\n",
111111
" print(\"✅ PyImageJ repository cloned successfully!\")\n",
112112
"else:\n",
113113
" print(\"✅ PyImageJ repository already available\")"
@@ -129,12 +129,13 @@
129129
"#@markdown Select your experience levels with the relevant tools, then run this cell to set Gemini's persona.\n",
130130
"#@markdown\n",
131131
"#@markdown 💡 Tip: Changing selections automatically updates the AI (after manually running once)\n",
132-
"#@markdown\n",
133-
"#@markdown 💡 Tip: Copy output text to use with other LLMs (ChatGPT, Claude, etc.)\n",
132+
"\n",
133+
"# AUTO-GENERATED CELL - DO NOT EDIT MANUALLY\n",
134+
"# This section is automatically updated based on files in doc/llms/personas/\n",
134135
"\n",
135136
"# Experience level parameters (Colab forms)\n",
136-
"coding_experience = \"New to programming\" #@param [\"New to programming\", \"Some programming experience\", \"Advanced programmer\"]\n",
137137
"colab_experience = \"New to Google Colab\" #@param [\"New to Google Colab\", \"Some Colab experience\", \"Colab expert\"]\n",
138+
"coding_experience = \"New to programming\" #@param [\"New to programming\", \"Some programming experience\", \"Advanced programmer\"]\n",
138139
"pyimagej_experience = \"New to PyImageJ\" #@param [\"New to PyImageJ\", \"Some PyImageJ experience\", \"PyImageJ expert\"]\n",
139140
"\n",
140141
"beginner = \"beginner\"\n",
@@ -143,41 +144,42 @@
143144
"\n",
144145
"# Convert display names to internal values\n",
145146
"experience_mapping = {\n",
147+
"\t\"New to Google Colab\": beginner,\n",
148+
"\t\"Some Colab experience\": intermediate,\n",
149+
"\t\"Colab expert\": advanced,\n",
146150
"\t\"New to programming\": beginner,\n",
147-
"\t\"Some programming experience\": intermediate, \n",
151+
"\t\"Some programming experience\": intermediate,\n",
148152
"\t\"Advanced programmer\": advanced,\n",
149153
"\t\"New to PyImageJ\": beginner,\n",
150154
"\t\"Some PyImageJ experience\": intermediate,\n",
151155
"\t\"PyImageJ expert\": advanced,\n",
152-
"\t\"New to Google Colab\": beginner,\n",
153-
"\t\"Some Colab experience\": intermediate,\n",
154-
"\t\"Colab expert\": advanced\n",
155156
"}\n",
156157
"\n",
157-
"# Template file mapping for different experience categories\n",
158+
"# Activity file mapping for different experience categories\n",
158159
"activity_dir = 'activities/'\n",
159160
"\n",
160161
"coding_activities = {\n",
162+
"\tadvanced: activity_dir + 'coding_advanced.md',\n",
161163
"\tbeginner: activity_dir + 'coding_beginner.md',\n",
162164
"\tintermediate: activity_dir + 'coding_intermediate.md',\n",
163-
"\tadvanced: activity_dir + 'coding_advanced.md'\n",
165+
"}\n",
166+
"\n",
167+
"colab_activities = {\n",
168+
"\tadvanced: activity_dir + 'colab_advanced.md',\n",
169+
"\tbeginner: activity_dir + 'colab_beginner.md',\n",
170+
"\tintermediate: activity_dir + 'colab_intermediate.md',\n",
164171
"}\n",
165172
"\n",
166173
"pyimagej_activities = {\n",
174+
"\tadvanced: activity_dir + 'pyimagej_advanced.md',\n",
167175
"\tbeginner: activity_dir + 'pyimagej_beginner.md',\n",
168176
"\tintermediate: activity_dir + 'pyimagej_intermediate.md',\n",
169-
"\tadvanced: activity_dir + 'pyimagej_advanced.md'\n",
170177
"}\n",
171178
"\n",
172-
"colab_activities = {\n",
173-
"\tbeginner: activity_dir + 'colab_beginner.md',\n",
174-
"\tintermediate: activity_dir + 'colab_intermediate.md',\n",
175-
"\tadvanced: activity_dir + 'colab_advanced.md'\n",
176-
"}\n",
177179
"\n",
178180
"from pathlib import Path\n",
179181
"def load_persona_file(filename):\n",
180-
"\t\"\"\"Load a persona template file\"\"\"\n",
182+
"\t\"\"\"Load a persona template file with clear section markers\"\"\"\n",
181183
"\ttry:\n",
182184
"\t\t# First check if we're in a cloned pyimagej repo\n",
183185
"\t\tpersona_path = Path('/content/pyimagej/doc/llms/personas') / filename\n",
@@ -186,33 +188,41 @@
186188
"\t\t\tpersona_path = Path('./personas') / filename\n",
187189
"\t\t\t\n",
188190
"\t\tif persona_path.exists():\n",
189-
"\t\t\treturn persona_path.read_text(encoding='utf-8')\n",
191+
"\t\t\tcontent = persona_path.read_text(encoding='utf-8')\n",
192+
"\t\t\t# Add clear section markers for LLM parsing\n",
193+
"\t\t\tbase_name = Path(filename).stem # Remove directory and .md extension\n",
194+
"\t\t\t# For activity files, remove experience level suffix and add \"ACTIVITIES\"\n",
195+
"\t\t\tif '_beginner' in base_name or '_intermediate' in base_name or '_advanced' in base_name:\n",
196+
"\t\t\t\t# Strip the last underscore and everything after it, then add \"ACTIVITIES\"\n",
197+
"\t\t\t\tactivity_name = base_name.rsplit('_', 1)[0].replace('_', ' ').upper()\n",
198+
"\t\t\t\tsection_name = f\"{activity_name} ACTIVITIES\"\n",
199+
"\t\t\telse:\n",
200+
"\t\t\t\t# Other files: use as-is\n",
201+
"\t\t\t\tsection_name = base_name.replace('_', ' ').upper()\n",
202+
"\t\t\treturn f\"\\n===== START OF {section_name} =====\\n{content}\\n===== END OF {section_name} =====\\n\"\n",
190203
"\t\telse:\n",
191-
"\t\t\treturn f\"# Template not found: {filename}\\n(Using basic fallback)\"\n",
204+
"\t\t\treturn f\"# Persona file not found: {filename}\\n(Using basic fallback)\"\n",
192205
"\texcept Exception as e:\n",
193206
"\t\treturn f\"# Error loading {filename}: {e}\\n(Using basic fallback)\"\n",
194207
"\n",
195-
"# Load base persona\n",
196-
"persona_text = \"===START OF PERSONA TEXT===\\n\"\n",
197-
"persona_text += load_persona_file('base_persona.md')\n",
198-
"persona_text += \"\\n===END OF PERSONA TEXT===\\n\\n\"\n",
208+
"# Load base persona with section markers\n",
209+
"persona_text = load_persona_file('base_persona.md')\n",
199210
"\n",
200211
"# Get experience levels\n",
212+
"colab_level = experience_mapping[colab_experience]\n",
201213
"coding_level = experience_mapping[coding_experience]\n",
202214
"pyimagej_level = experience_mapping[pyimagej_experience]\n",
203-
"colab_level = experience_mapping[colab_experience]\n",
204215
"\n",
205216
"# Add activities based on experience levels\n",
206-
"persona_text = \"===START OF ACTIVITY TEXT===\\n\"\n",
217+
"if colab_level in colab_activities:\n",
218+
"\tpersona_text += load_persona_file(colab_activities[colab_level])\n",
219+
"\n",
207220
"if coding_level in coding_activities:\n",
208-
"\tpersona_text += \"\\n\" + load_persona_file(coding_activities[coding_level])\n",
221+
"\tpersona_text += load_persona_file(coding_activities[coding_level])\n",
209222
"\n",
210223
"if pyimagej_level in pyimagej_activities:\n",
211-
"\tpersona_text += \"\\n\" + load_persona_file(pyimagej_activities[pyimagej_level])\n",
224+
"\tpersona_text += load_persona_file(pyimagej_activities[pyimagej_level])\n",
212225
"\n",
213-
"if colab_level in colab_activities:\n",
214-
"\tpersona_text += \"\\n\" + load_persona_file(colab_activities[colab_level])\n",
215-
"persona_text += \"\\n===END OF ACTIVITY TEXT===\\n\\n\"\n",
216226
"\n",
217227
"# Register the persona with the LLM\n",
218228
"print(persona_text)"
@@ -232,24 +242,25 @@
232242
"#@markdown Select your target environment, then run this cell to load the appropriate rulesets.\n",
233243
"#@markdown\n",
234244
"#@markdown 💡 Tip: Changing selections automatically updates the AI (after manually running once)\n",
235-
"#@markdown\n",
236-
"#@markdown 💡 Tip: Copy output text to use with other LLMs (ChatGPT, Claude, etc.)\n",
245+
"\n",
246+
"# AUTO-GENERATED CELL - DO NOT EDIT MANUALLY\n",
247+
"# This section is automatically updated based on files in doc/llms/rulesets/\n",
237248
"\n",
238249
"# Environment parameters (Colab forms)\n",
239-
"environment = \"Google Colab\" #@param [\"Google Colab\", \"Interactive Desktop\", \"True Headless\", \"Fiji Script Editor\"]\n",
250+
"environment = \"Google Colab\" #@param [\"Google Colab\", \"True Headless\", \"Interactive Desktop\", \"Scripting\"]\n",
240251
"\n",
241252
"# Convert display names to internal values\n",
242253
"environment_mapping = {\n",
243-
"\t\"Google Colab\": \"env_colab\",\n",
244-
"\t\"Interactive Desktop\": \"env_interactive\", \n",
245-
"\t\"True Headless\": \"env_headless\",\n",
246-
"\t\"Fiji Script Editor\": \"env_script_editor\"\n",
254+
"\t\"Google Colab\": \"environments/env_colab\",\n",
255+
"\t\"True Headless\": \"environments/env_headless\",\n",
256+
"\t\"Interactive Desktop\": \"environments/env_interactive\",\n",
257+
"\t\"Scripting\": \"environments/env_scripting\",\n",
247258
"}\n",
248259
"\n",
249260
"from pathlib import Path\n",
250261
"\n",
251262
"def load_ruleset_template(filename):\n",
252-
"\t\"\"\"Load a ruleset template file\"\"\"\n",
263+
"\t\"\"\"Load a ruleset template file with clear section markers\"\"\"\n",
253264
"\ttry:\n",
254265
"\t\t# First check if we're in a cloned pyimagej repo\n",
255266
"\t\truleset_path = Path('/content/pyimagej/doc/llms/rulesets') / filename\n",
@@ -258,19 +269,30 @@
258269
"\t\t\truleset_path = Path('./rulesets') / filename\n",
259270
"\t\t\t\n",
260271
"\t\tif ruleset_path.exists():\n",
261-
"\t\t\treturn ruleset_path.read_text(encoding='utf-8')\n",
272+
"\t\t\tcontent = ruleset_path.read_text(encoding='utf-8')\n",
273+
"\t\t\t# Add clear section markers for LLM parsing\n",
274+
"\t\t\tbase_name = Path(filename).stem # Remove directory and .md extension\n",
275+
"\t\t\tif base_name.startswith('env_'):\n",
276+
"\t\t\t\t# Environment files: strip \"env_\" prefix and add \"ENVIRONMENT\"\n",
277+
"\t\t\t\tenv_name = base_name[4:].replace('_', ' ').upper()\n",
278+
"\t\t\t\tsection_name = f\"{env_name} ENVIRONMENT\"\n",
279+
"\t\t\telse:\n",
280+
"\t\t\t\t# Other files: use as-is\n",
281+
"\t\t\t\tsection_name = base_name.replace('_', ' ').upper()\n",
282+
"\t\t\treturn f\"\\n===== START OF {section_name} RULES =====\\n{content}\\n===== END OF {section_name} RULES =====\\n\"\n",
262283
"\t\telse:\n",
263284
"\t\t\treturn f\"# Ruleset not found: {filename}\\n(Using basic fallback)\"\n",
264285
"\texcept Exception as e:\n",
265286
"\t\treturn f\"# Error loading {filename}: {e}\\n(Using basic fallback)\"\n",
266287
"\n",
267-
"# Load core PyImageJ ruleset (always included)\n",
288+
"# Load core PyImageJ ruleset with section markers\n",
268289
"ruleset_text = load_ruleset_template('pyimagej_core.md')\n",
269290
"\n",
270-
"# Get environment-specific ruleset\n",
271-
"env_key = environment_mapping[environment]\n",
272-
"env_filename = f\"{env_key}.md\"\n",
273-
"ruleset_text += \"\\n\" + load_ruleset_template(env_filename)\n",
291+
"# Get environment-specific ruleset with section markers\n",
292+
"env_val = environment_mapping[environment]\n",
293+
"# Strip any leading subdirectories from the path\n",
294+
"env_filename = f\"{env_val}.md\"\n",
295+
"ruleset_text += load_ruleset_template(env_filename)\n",
274296
"\n",
275297
"# Register the rulesets with the LLM\n",
276298
"print(ruleset_text)"

0 commit comments

Comments
 (0)