Text Generator

repository·master·Indexed 24 days ago

https://github.com/nhaouari/obsidian-textgenerator-plugin

An open-source AI assistant plugin for Obsidian (v0.8.10-beta) that integrates generative AI capabilities into knowledge management workflows. It supports automated content generation, idea expansion, and summarization using providers such as OpenAI (GPT-3), Google Generative AI (Gemini-Pro), and HuggingFace. Key features include a template engine, community templates, and flexible prompt configuration via frontmatter.

Tokens
9.5K
Snippets
19
Records
69
Agent score
84%

What's inside obsidian-textgenerator-plugin

  1. Overview of Text Generator features

    master

    Text Generator is an open-source AI Assistant Tool for Obsidian that enables generative AI workflows within your knowledge base. Key features include:

    • Flexible Prompts: High flexibility using various options in the 'Considered Context'.
    • Template Engine: Create templates to automate repetitive AI tasks.
    • Community Templates: Access and share AI use cases via shared templates.
    • Highly Flexible Configuration: Use Frontmatter Configuration to switch between different AI services such as Google Generative AI (Gemini-Pro), OpenAI, and HuggingFace.
  2. Install Text Generator manually or for development

    master

    To install the plugin manually or use the latest development version, clone the repository directly into your Obsidian vault's plugins folder and build it using pnpm:

    1. Clone the repository:
      git clone https://github.com/nhaouari/obsidian-textgenerator-plugin.git
    2. Navigate to the directory:
      cd obsidian-textgenerator-plugin
    3. Install dependencies:
      pnpm install
    4. Build the plugin:
      pnpm run build
      Or, for active development:
      pnpm run dev
    5. Restart Obsidian and enable the plugin in Settings > Community plugins.

    Tip: You can use the Hot-Reload plugin to reload plugins without restarting Obsidian.

    git clone https://github.com/nhaouari/obsidian-textgenerator-plugin.git
    cd obsidian-textgenerator-plugin
    pnpm install
    pnpm run build
  3. Install Text Generator via Obsidian Community Plugins

    master

    The easiest way to install the Text Generator plugin is through the built-in Obsidian community plugin browser:

    1. Open Obsidian.
    2. Navigate to Settings > Community plugins.
    3. If Safe mode is enabled, turn it off.
    4. Click Browse and search for "Text Generator".
    5. Click Install, then click Enable.
  4. Configure the plugin via the Status Bar

    master

    The plugin adds several interactive elements to the Obsidian status bar:

    • Generator Icon: Clicking this opens the plugin settings tab.
    • Tokens Display: Shows the current max_tokens setting. Clicking this opens a SetMaxTokens modal to update the limit.
    • Processing Indicator: When generating text, the icon changes to a loading spinner (dots) and a Notice appears indicating the process is running.
  5. How AutoSuggest triggering works

    master

    The onTrigger method determines if the current editor state warrants an auto-suggestion request. It validates several conditions:

    1. Plugin State: isEnabled must be true and triggerPhrase must be defined.
    2. Vim Mode: If using Vim, it only triggers if the editor is in insert mode.
    3. Trigger Phrase Match: The text at the cursor must end with the configured triggerPhrase (unless allowInNewLine is configured otherwise).
    4. Context: If customInstructEnabled is false, there must be non-whitespace text in the selection to provide context.

    If all conditions are met, it returns an EditorSuggestTriggerInfo object containing the start position, end position, and the query (the text preceding the trigger phrase).

  6. Manage Text Generator packages

    master

    The PackageManager class handles the lifecycle of prompt packages and features within Obsidian. It manages downloading, installing, updating, and uninstalling packages from both GitHub repositories and external provider servers.

    Key capabilities include:

    • Installing Packages: Downloads prompt templates or installs external features.
    • Updating: Checks for newer versions of installed packages via GitHub releases.
    • Ownership Validation: Verifies access to premium/paid resources using an API key.
    • Registry Sync: Periodically refreshes the local package list from remote registries.
  7. Use asynchronous helpers with Handlebars

    master

    To use asynchronous helpers, wrap your standard handlebars instance with the handlebars-async-helpers function. This returns a new Handlebars instance (hb) that supports registering and executing async helpers. When compiling templates, ensure you await the execution of the compiled template function to resolve any asynchronous helpers within it.

    const handlebars = require('handlebars'),
          asyncHelpers = require('handlebars-async-helpers')
    
    const hb = asyncHelpers(handlebars)
    
    bg.registerHelper('sleep', async () => new Promise((resolve) => {
        setTimeout(() => resolve('Done!'), 1000)
    }))
    
    const template = hb.compile('Mark when is completed: {{#sleep}}{{/sleep}}')
    const result = await template()
    console.log(result)
    // 'Mark when is completed: Done!'
  8. Configure the PluginManager

    master

    The PluginManager class manages the lifecycle, installation, and sandboxing of live plugins. You can initialize it with a partial PluginManagerOptions object to customize its behavior, such as the plugin storage path, registry settings, or sandbox environment.

    Key configuration options include:

    • cwd: The current working directory.
    • pluginsPath: The directory where plugins are stored (defaults to cwd/plugin_packages).
    • sandbox: A PluginSandbox object to define env (process environment) and global (NodeJS globals) for the plugin execution environment.
    • npmRegistryUrl: The URL for the npm registry (defaults to https://registry.npmjs.org).
    • npmInstallMode: Either "useCache" or "noCache".
    • requireCoreModules: Boolean indicating if core modules should be required.
    • hostRequire: A NodeRequire function to allow plugins to access host-provided modules.
    • ignoredDependencies: An array of strings or RegExps to skip during dependency installation.
    • staticDependencies: An object containing dependencies that are already provided by the host.
    • githubAuthentication / bitbucketAuthentication: Credentials for private registry access.
  9. Configure AutoSuggest via plugin settings

    master

    The AutoSuggest service relies on autoSuggestOptions within the plugin settings. The following keys are used to control behavior:

    • isEnabled: Boolean to enable/disable the service.
    • triggerPhrase: The string that must precede the suggestion request.
    • allowInNewLine: Boolean determining if the trigger can occur at the start of a new line.
    • showStatus: Boolean to show/hide the status bar toggle.
    • inlineSuggestions: Boolean; if true, uses InlineSuggest mode; otherwise uses ListSuggest mode.
    • customInstructEnabled: Enables use of dynamic templates for prompts.
    • customInstruct: The template content for custom instructions.
    • systemPrompt: The system message sent to the LLM.
    • numberOfSuggestions: Integer defining how many completions to request.
    • stop: A string used as a stop sequence for the LLM.
    • selectedProvider: The specific LLM provider to use for auto-suggestions.
    • customProvider: Boolean to indicate if a non-default provider is used.