Smart Composer for Obsidian

repository·main·Indexed 25 days ago

https://github.com/glowingjade/obsidian-smart-composer

An Obsidian plugin that enhances AI-assisted writing by integrating vault content into AI context. It features @file mentions, semantic vault search (RAG), one-click document edits, and support for the Model Context Protocol (MCP). Compatible with various API providers including OpenAI, Anthropic, Gemini, and local LLMs via Ollama or LM Studio.

Tokens
2.4K
Snippets
1
Records
23
Agent score
81%

What's inside Smart Composer

  1. Use Prompt Templates and Custom System Prompts

    main

    Prompt Templates

    Standardize repetitive tasks by creating and reusing templates. In the chat view, type / to access your templates. You can also create templates from any selected text with one click.

    Custom System Prompts

    You can define your own system prompts in the settings, which will be applied to every chat conversation to guide the AI's behavior.

  2. Install and set up Smart Composer

    main

    To use Smart Composer in Obsidian, follow these steps:

    1. Install via Community Plugins:

      • Open Obsidian Settings.
      • Navigate to Community plugins and click Browse.
      • Search for Smart Composer and click Install.
      • Enable the plugin.
    2. Configure AI Providers: You can choose between two connection methods in Settings > Smart Composer:

      • Connect subscription (no API key): Use this to connect your Claude or OpenAI accounts directly via an OAuth-style flow.
        • Warning: Using subscription OAuth for Claude carries a risk of account restriction/banning per Anthropic's Terms of Service. Use at your own risk.
      • API Providers (usage-based billing): Add an API key in Settings > Smart Composer > Providers for providers like OpenAI, Anthropic, or Gemini.
    3. Troubleshooting Installation: If the plugin fails to load, ensure your Obsidian installer is up to date. If Settings > General > Check for updates doesn't resolve it, manually download and run the latest installer from obsidian.md.

  3. Use Contextual Chat with @mentions and Multimedia

    main

    The Contextual AI Assistant allows you to precisely control the information the AI uses for its responses.

    Referencing Vault Content

    Use the @ symbol in the chat to select specific context:

    • Type @<fname> to choose specific files or folders as your conversation context.

    Adding Multimedia Context

    You can expand the AI's context by adding non-textual information:

    • Websites: Add website links; content is automatically extracted.
    • Images: Add images via the upload button, drag & drop, or pasting from the clipboard.
    • YouTube: Add YouTube links to include video transcripts as context.
    • External Files: Support for PDF and DOCX is planned for a future update.
  4. Configure custom models and local LLMs

    main

    You can customize which AI models power your experience via Settings > Smart Composer > Providers.

    Supported API Providers

    • OpenAI
    • Anthropic
    • Google (Gemini)
    • Groq
    • DeepSeek
    • OpenRouter
    • Azure OpenAI
    • Any other OpenAI-compatible providers

    Local Model Support

    For complete privacy and offline usage, you can run open-source LLMs and embedding models locally using Ollama, [LM Studio], or [MorphLLM].

  5. Configure Drizzle ORM for PostgreSQL

    main

    The project uses Drizzle ORM with a PostgreSQL dialect. The configuration is defined using defineConfig from drizzle-kit. To maintain the database schema, ensure the schema path points to ./src/database/schema.ts and the dialect is set to 'postgresql'.

    import { defineConfig } from 'drizzle-kit'
    
    export default defineConfig({
      dialect: 'postgresql',
      schema: './src/database/schema.ts',
    })
  6. Configure Smart Composer settings schema

    main
    The smartComposerSettingsSchema defines the structure and validation for the plugin's configuration. It includes settings for LLM providers, chat models, embedding models, RAG (Retrieval-Augmented Generation) options, MCP (Model Context Protocol) server configurations, and chat behavior. If values are invalid, the schema uses .catch() to revert to safe defaults.
  7. Open and interact with the Chat View

    main

    The plugin provides several ways to interact with the Chat interface:

    • openChatView(openNewChat?: boolean): Opens the chat view. If openNewChat is true, it starts a fresh session. If an active editor is present, it attempts to include the selected block data in the context.
    • activateChatView(chatProps?: ChatProps, openNewChat?: boolean): Low-level method to ensure the chat leaf is active and set to the correct state.
    • addSelectionToChat(editor: Editor, view: MarkdownView): Specifically targets the current selection in the editor and adds it to the existing chat session, then focuses the message input.
  8. Format LLM messages with formatMessages()

    main

    Use formatMessages() to prepare an array of RequestMessage objects for LLM API consumption. This function ensures compatibility with providers that require strict alternation between user and assistant roles by merging consecutive messages of the same role.

    Key behaviors:

    • System Message Consolidation: All messages with the system role are collected, concatenated with double newlines, and placed at the very beginning of the message array.
    • Role Alternation: Consecutive messages with the same role (e.g., two user messages in a row) are merged into a single message.
    • Content Merging: When merging, the function handles both string and ContentPart[] formats. If all merged parts are text-based, the resulting content is returned as a single concatenated string. Otherwise, it returns a ContentPart[] array.
    • Empty Content Filtering: Empty or whitespace-only text parts are filtered out during the merge process.
  9. Access the Database Manager

    main
    The DatabaseManager handles the underlying storage. Use getDbManager() to retrieve the instance. This is an asynchronous operation that initializes the database (using PGLite). If initialization fails due to a PGLiteAbortedException, the plugin will prompt the user to update the installer.