|
7 | 7 | "id": "view-in-github" |
8 | 8 | }, |
9 | 9 | "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>" |
11 | 11 | ] |
12 | 12 | }, |
13 | 13 | { |
|
107 | 107 | " # --AUTO-GENERATED CONTENT--\n", |
108 | 108 | " # The following line is automatically updated by GitHub Actions\n", |
109 | 109 | " # 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", |
111 | 111 | " print(\"✅ PyImageJ repository cloned successfully!\")\n", |
112 | 112 | "else:\n", |
113 | 113 | " print(\"✅ PyImageJ repository already available\")" |
|
129 | 129 | "#@markdown Select your experience levels with the relevant tools, then run this cell to set Gemini's persona.\n", |
130 | 130 | "#@markdown\n", |
131 | 131 | "#@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", |
134 | 135 | "\n", |
135 | 136 | "# Experience level parameters (Colab forms)\n", |
136 | | - "coding_experience = \"New to programming\" #@param [\"New to programming\", \"Some programming experience\", \"Advanced programmer\"]\n", |
137 | 137 | "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", |
138 | 139 | "pyimagej_experience = \"New to PyImageJ\" #@param [\"New to PyImageJ\", \"Some PyImageJ experience\", \"PyImageJ expert\"]\n", |
139 | 140 | "\n", |
140 | 141 | "beginner = \"beginner\"\n", |
|
143 | 144 | "\n", |
144 | 145 | "# Convert display names to internal values\n", |
145 | 146 | "experience_mapping = {\n", |
| 147 | + "\t\"New to Google Colab\": beginner,\n", |
| 148 | + "\t\"Some Colab experience\": intermediate,\n", |
| 149 | + "\t\"Colab expert\": advanced,\n", |
146 | 150 | "\t\"New to programming\": beginner,\n", |
147 | | - "\t\"Some programming experience\": intermediate, \n", |
| 151 | + "\t\"Some programming experience\": intermediate,\n", |
148 | 152 | "\t\"Advanced programmer\": advanced,\n", |
149 | 153 | "\t\"New to PyImageJ\": beginner,\n", |
150 | 154 | "\t\"Some PyImageJ experience\": intermediate,\n", |
151 | 155 | "\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", |
155 | 156 | "}\n", |
156 | 157 | "\n", |
157 | | - "# Template file mapping for different experience categories\n", |
| 158 | + "# Activity file mapping for different experience categories\n", |
158 | 159 | "activity_dir = 'activities/'\n", |
159 | 160 | "\n", |
160 | 161 | "coding_activities = {\n", |
| 162 | + "\tadvanced: activity_dir + 'coding_advanced.md',\n", |
161 | 163 | "\tbeginner: activity_dir + 'coding_beginner.md',\n", |
162 | 164 | "\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", |
164 | 171 | "}\n", |
165 | 172 | "\n", |
166 | 173 | "pyimagej_activities = {\n", |
| 174 | + "\tadvanced: activity_dir + 'pyimagej_advanced.md',\n", |
167 | 175 | "\tbeginner: activity_dir + 'pyimagej_beginner.md',\n", |
168 | 176 | "\tintermediate: activity_dir + 'pyimagej_intermediate.md',\n", |
169 | | - "\tadvanced: activity_dir + 'pyimagej_advanced.md'\n", |
170 | 177 | "}\n", |
171 | 178 | "\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", |
177 | 179 | "\n", |
178 | 180 | "from pathlib import Path\n", |
179 | 181 | "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", |
181 | 183 | "\ttry:\n", |
182 | 184 | "\t\t# First check if we're in a cloned pyimagej repo\n", |
183 | 185 | "\t\tpersona_path = Path('/content/pyimagej/doc/llms/personas') / filename\n", |
|
186 | 188 | "\t\t\tpersona_path = Path('./personas') / filename\n", |
187 | 189 | "\t\t\t\n", |
188 | 190 | "\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", |
190 | 203 | "\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", |
192 | 205 | "\texcept Exception as e:\n", |
193 | 206 | "\t\treturn f\"# Error loading {filename}: {e}\\n(Using basic fallback)\"\n", |
194 | 207 | "\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", |
199 | 210 | "\n", |
200 | 211 | "# Get experience levels\n", |
| 212 | + "colab_level = experience_mapping[colab_experience]\n", |
201 | 213 | "coding_level = experience_mapping[coding_experience]\n", |
202 | 214 | "pyimagej_level = experience_mapping[pyimagej_experience]\n", |
203 | | - "colab_level = experience_mapping[colab_experience]\n", |
204 | 215 | "\n", |
205 | 216 | "# 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", |
207 | 220 | "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", |
209 | 222 | "\n", |
210 | 223 | "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", |
212 | 225 | "\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", |
216 | 226 | "\n", |
217 | 227 | "# Register the persona with the LLM\n", |
218 | 228 | "print(persona_text)" |
|
232 | 242 | "#@markdown Select your target environment, then run this cell to load the appropriate rulesets.\n", |
233 | 243 | "#@markdown\n", |
234 | 244 | "#@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", |
237 | 248 | "\n", |
238 | 249 | "# 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", |
240 | 251 | "\n", |
241 | 252 | "# Convert display names to internal values\n", |
242 | 253 | "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", |
247 | 258 | "}\n", |
248 | 259 | "\n", |
249 | 260 | "from pathlib import Path\n", |
250 | 261 | "\n", |
251 | 262 | "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", |
253 | 264 | "\ttry:\n", |
254 | 265 | "\t\t# First check if we're in a cloned pyimagej repo\n", |
255 | 266 | "\t\truleset_path = Path('/content/pyimagej/doc/llms/rulesets') / filename\n", |
|
258 | 269 | "\t\t\truleset_path = Path('./rulesets') / filename\n", |
259 | 270 | "\t\t\t\n", |
260 | 271 | "\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", |
262 | 283 | "\t\telse:\n", |
263 | 284 | "\t\t\treturn f\"# Ruleset not found: {filename}\\n(Using basic fallback)\"\n", |
264 | 285 | "\texcept Exception as e:\n", |
265 | 286 | "\t\treturn f\"# Error loading {filename}: {e}\\n(Using basic fallback)\"\n", |
266 | 287 | "\n", |
267 | | - "# Load core PyImageJ ruleset (always included)\n", |
| 288 | + "# Load core PyImageJ ruleset with section markers\n", |
268 | 289 | "ruleset_text = load_ruleset_template('pyimagej_core.md')\n", |
269 | 290 | "\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", |
274 | 296 | "\n", |
275 | 297 | "# Register the rulesets with the LLM\n", |
276 | 298 | "print(ruleset_text)" |
|
0 commit comments