Auto tagging obsidian notes w/ AI
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add multiple prompt options with custom prompt support

- Add dropdown to select between standard, descriptive, academic, concise, and custom prompts
- Show editable text area only when custom option is selected
- Add styling for disabled text areas in read-only mode
- Store prompt templates in a constant for better organization

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>

+76 -13
+70 -13
main.ts
··· 14 14 apiKey: string; 15 15 modelName: string; 16 16 maxTags: number; 17 + promptOption: string; 17 18 promptTemplate: string; 18 19 } 19 20 21 + // Define prompt templates 22 + const PROMPT_TEMPLATES = { 23 + standard: "Generate {maxTags} relevant tags for the following note content. Return only the tags as a comma-separated list, without any additional commentary. Tags should be lowercase and use hyphens for multi-word tags.\n\nContent:\n{content}", 24 + descriptive: "Analyze the following note content and generate {maxTags} descriptive tags that capture the main topics, concepts, and themes. Return only the tags as a comma-separated list, without any additional commentary. Tags should be lowercase and use hyphens for multi-word tags.\n\nContent:\n{content}", 25 + academic: "Review the following academic or research note and generate {maxTags} specific tags that would help categorize this content in an academic context. Include relevant field-specific terminology. Return only the tags as a comma-separated list, without any additional commentary. Tags should be lowercase and use hyphens for multi-word tags.\n\nContent:\n{content}", 26 + concise: "Generate {maxTags} short, concise tags for the following note content. Focus on single-word tags when possible. Return only the tags as a comma-separated list, without any additional commentary. Tags should be lowercase.\n\nContent:\n{content}", 27 + custom: "", 28 + }; 29 + 20 30 const DEFAULT_SETTINGS: AITaggerSettings = { 21 31 apiKey: "", 22 32 modelName: "claude-3-5-sonnet-20240620", 23 33 maxTags: 5, 24 - promptTemplate: 25 - "Generate {maxTags} relevant tags for the following note content. Return only the tags as a comma-separated list, without any additional commentary. Tags should be lowercase and use hyphens for multi-word tags.\n\nContent:\n{content}", 34 + promptOption: "standard", 35 + promptTemplate: PROMPT_TEMPLATES.standard, 26 36 }; 27 37 28 38 export default class AITaggerPlugin extends Plugin { ··· 421 431 }) 422 432 ); 423 433 434 + // Prompt option dropdown 424 435 new Setting(containerEl) 425 - .setName("Prompt template") 426 - .setDesc( 427 - "Customize the prompt sent to the AI. Use {maxTags} and {content} as placeholders." 428 - ) 429 - .addTextArea((textarea) => 430 - textarea 431 - .setValue(this.plugin.settings.promptTemplate) 436 + .setName("Prompt style") 437 + .setDesc("Choose a predefined prompt style or create your own custom prompt.") 438 + .addDropdown((dropdown) => { 439 + dropdown 440 + .addOption("standard", "Standard") 441 + .addOption("descriptive", "Descriptive") 442 + .addOption("academic", "Academic") 443 + .addOption("concise", "Concise") 444 + .addOption("custom", "Custom") 445 + .setValue(this.plugin.settings.promptOption) 432 446 .onChange(async (value) => { 433 - this.plugin.settings.promptTemplate = value; 447 + this.plugin.settings.promptOption = value; 448 + 449 + // Update prompt template if not using custom 450 + if (value !== "custom") { 451 + this.plugin.settings.promptTemplate = PROMPT_TEMPLATES[value as keyof typeof PROMPT_TEMPLATES]; 452 + 453 + // Force refresh to update the textarea with the new template 454 + this.display(); 455 + } else if (this.plugin.settings.promptTemplate === "") { 456 + // If switching to custom and no custom template yet, initialize with standard 457 + this.plugin.settings.promptTemplate = PROMPT_TEMPLATES.standard; 458 + this.display(); 459 + } 460 + 434 461 await this.plugin.saveSettings(); 435 - }) 436 - ) 437 - .setClass("ai-tagger-wide-setting"); 462 + }); 463 + return dropdown; 464 + }); 465 + 466 + // Only show prompt template textarea if custom option is selected 467 + if (this.plugin.settings.promptOption === "custom") { 468 + new Setting(containerEl) 469 + .setName("Custom prompt template") 470 + .setDesc( 471 + "Customize the prompt sent to the AI. Use {maxTags} and {content} as placeholders." 472 + ) 473 + .addTextArea((textarea) => 474 + textarea 475 + .setValue(this.plugin.settings.promptTemplate) 476 + .onChange(async (value) => { 477 + this.plugin.settings.promptTemplate = value; 478 + await this.plugin.saveSettings(); 479 + }) 480 + ) 481 + .setClass("ai-tagger-wide-setting"); 482 + } else { 483 + // Show the current template as read-only if not using custom 484 + new Setting(containerEl) 485 + .setName("Current prompt template") 486 + .setDesc("This is the prompt template that will be used (read-only). Switch to Custom if you want to edit it.") 487 + .addTextArea((textarea) => { 488 + textarea 489 + .setValue(this.plugin.settings.promptTemplate) 490 + .setDisabled(true); 491 + return textarea; 492 + }) 493 + .setClass("ai-tagger-wide-setting"); 494 + } 438 495 } 439 496 }
+6
styles.css
··· 25 25 resize: vertical; 26 26 } 27 27 28 + /* Styling for disabled textarea */ 29 + .ai-tagger-wide-setting textarea:disabled { 30 + opacity: 0.75; 31 + background-color: var(--background-secondary); 32 + } 33 + 28 34 /* Add a subtle highlight for successfully tagged notes if needed */ 29 35 .ai-tagged { 30 36 border-left: 2px solid var(--interactive-accent);