Skip to content

eugene-kamenev/logseq-llm-plugin

Repository files navigation

ollama-logseq

ollama-logseq is a Logseq plugin that connects your graph to any OpenAI-compatible chat completion endpoint.

It is designed for local and hosted LLM workflows alike:

  • OpenAI
  • Ollama
  • LM Studio
  • vLLM
  • LocalAI
  • any other provider that exposes an OpenAI-compatible /chat/completions API

The plugin gives Logseq users a command palette for AI actions, block and page aware prompts, streamed responses inserted directly into the graph, flashcard generation, and a customizable command system that can be extended per graph.

What the plugin does

The plugin adds an AI command layer on top of Logseq blocks and pages.

From Logseq, you can:

  • open an AI command palette from a shortcut, slash command, or toolbar button
  • run prompts against the current block or the entire page
  • summarize content into structured Logseq blocks
  • generate nested TODO breakdowns from a task block
  • turn notes into flashcards
  • define your own prompt commands in your graph
  • override bundled commands without changing plugin source code
  • pin a specific model to a specific custom command

Responses are streamed into Logseq as they arrive. When possible, the plugin converts markdown-like output into proper nested Logseq blocks instead of leaving everything in one long paragraph.

Highlights

  • Works with any OpenAI-compatible chat completion endpoint
  • API key is optional for local endpoints that do not require authentication
  • Supports multiple configured models
  • Per-command model override support
  • Streamed response rendering while the model is generating
  • Block-aware and page-aware commands
  • Structured output insertion into nested Logseq blocks
  • Flashcard generation with #card
  • Graph-level custom commands and command overrides
  • Keyboard shortcut to reload command templates without restarting the plugin
  • Context menu commands for no-input block/page commands that explicitly use page or block context

How it appears in Logseq

After the plugin is enabled, users can access it in several ways:

  • toolbar button with a wand icon
  • slash command /ai
  • slash command /llm
  • configurable shortcut to open the AI command palette
  • configurable shortcut to reload commands
  • block context menu entries for eligible commands

The command palette groups commands into:

  • Block Commands
  • Page Commands

If a command requires user input, selecting it opens a prompt box. If it does not require input, it runs immediately.

Installation

Use as a Logseq plugin

Use your preferred Logseq plugin installation workflow.

If you are installing from source:

  1. Clone this repository.
  2. Install dependencies with pnpm install.
  3. Build the plugin with pnpm build.
  4. Load the project as an unpacked plugin in Logseq.

This project is configured as a Logseq plugin package and points Logseq to the built frontend entry at dist/index.html.

Configuration

The plugin exposes the following settings in Logseq.

Setting Purpose Notes
Base API URL Base URL for the OpenAI-compatible API You can enter either the API base, such as https://api.openai.com/v1, or the full .../chat/completions URL
API token Bearer token used for requests Leave empty for local endpoints that do not require auth
Models List of model names, one per line The first model becomes the default fallback model
Shortcut Opens the plugin command palette Default: mod+shift+o
Reload commands shortcut Reloads command templates Default: mod+shift+u
Command templates file Page name inside the current graph that contains custom command definitions Matching titles override bundled commands, empty user prompts remove bundled commands, new titles append new commands

Default bundled commands

The plugin ships with a set of bundled commands in public/defaultCommands.md.

Ask AI

  • asks the model whatever the user types
  • requires manual input
  • no page or block context is injected automatically

Ask with page context

  • requires manual input
  • injects the current page content into the prompt
  • useful for page-wide Q and A, analysis, or transformation

Ask with block context

  • requires manual input
  • injects the current block tree into the prompt
  • useful for rewriting, clarifying, or expanding a selected block and its children

Summarize Page

  • no manual input required
  • uses the current page as context
  • inserts a structured summary under a Summary root block
  • typically writes near the end of the current page

Summarize Block

  • no manual input required
  • uses the current block tree as context
  • inserts a structured summary under a Summary root block below the current block

Divide into subtasks

  • no manual input required
  • uses the current block tree as the task input
  • asks the model for a nested breakdown
  • inserts nested TODO blocks in Logseq

Convert to flash card

  • no manual input required
  • uses the current block tree as the knowledge source
  • generates:
    • a question block tagged with #card
    • an answer block directly below it

Command behavior in practice

Block context

For block-aware commands, the plugin reads the current block and its child tree, not only the single visible line.

That means a command can operate on:

  • a single block
  • a block with nested bullets beneath it
  • a small outline subtree

Page context

For page-aware commands, the plugin reads the full page block tree.

This is useful for:

  • page summaries
  • page-level study guides
  • extracting action items from a page
  • page-wide rewriting or analysis prompts

Structured output

For standard commands, the plugin tries to transform LLM output into Logseq-friendly nested blocks.

Examples:

  • headings are preserved as blocks
  • lists become nested list blocks
  • markdown checkboxes become TODO
  • code blocks are preserved as block text

This makes outputs much more usable inside a graph than a raw wall of text.

Flashcard output

Flashcard commands use a two-step flow:

  1. generate a question
  2. generate a short answer based on that question and the original source content

The resulting question block is tagged with #card, which fits standard Logseq flashcard workflows.

Custom commands

One of the most useful parts of this plugin is that commands are data-driven.

You can create your own commands in a page inside your graph, point the Command templates file setting at that page, and reload commands without restarting Logseq.

How custom commands are loaded

The command template source is read from a page in the current graph.

Recommended workflow:

  1. Create a page such as AI Commands.
  2. Paste your command definitions into that page.
  3. Set Command templates file to AI Commands.
  4. Press the reload shortcut, or restart the plugin.

If the page cannot be loaded, the plugin falls back to the bundled defaults and shows a warning.

Merge and override rules

Custom commands do not replace the whole bundled set by default.

Instead, the plugin merges commands using the command title:

  • if a custom command title matches a bundled command title, the custom command overrides it
  • if a custom command title is new, it is appended as an additional command
  • if a matching custom command has an empty llm-user, it removes the bundled command

Title matching is case-insensitive.

Reload behavior

The reload shortcut re-reads:

  • bundled commands
  • your graph command page

This is useful when you are iterating on prompts.

Note that Logseq does not provide a way to unregister stale block context menu entries. If you remove a command that previously appeared in the context menu, an old menu item may remain visible until the plugin is restarted. The plugin updates active command mappings on reload, but it cannot fully remove stale menu entries on its own.

Command template format

Commands are written as markdown list items.

At minimum, a command starts with:

- llm-command My Command

Supported sections are:

  • llm-system
  • llm-user
  • llm-follow-up-user
  • llm-response
  • llm-output
  • llm-model

Minimal example

- llm-command Rewrite block as bullets
  - llm-system
  ```md
  You rewrite notes into concise bullet points.
  ```
  - llm-user
  ```md
  Rewrite the following into short actionable bullets:

  ${block}
  ```

Page-aware example

- llm-command Extract page action items
  - llm-system
  ```md
  You extract actionable tasks from notes and return only concise task items.
  ```
  - llm-user
  ```md
  Review the following page and extract action items:

  ${page}
  ```
  - llm-response
  ```md
  Action Items
  ${response}
  ```

Flashcard example

- llm-command Make vocabulary card
  - llm-system
  ```md
  You create compact study flashcards.
  ```
  - llm-output flashcard
  - llm-user
  ```md
  Create a question for a flashcard. Provide the question only. Here is the knowledge to check:
  ${block}
  ```
  - llm-follow-up-user
  ```md
  Given the question ${question} and the context of ${block}, what is the answer? Be brief and provide the answer only.
  ```

Override an existing bundled command

If you want to replace the built-in Summarize Block command with your own version, define a command with the same title:

- llm-command Summarize Block
  - llm-system
  ```md
  You summarize technical notes into crisp study bullets.
  ```
  - llm-user
  ```md
  Summarize the following block tree into key insights, open questions, and next steps:

  ${block}
  ```
  - llm-response
  ```md
  Summary
  ${response}
  ```

Remove a bundled command

To remove a bundled command, define it with the same title but leave llm-user empty:

- llm-command Command Name

Template variables

The plugin replaces variables inside command templates before sending requests.

Request-time variables

These are available in llm-system, llm-user, and where applicable llm-follow-up-user:

Variable Meaning
${input} User-entered text from the prompt dialog
${block} Current block tree content
${page} Current page content
${pageName} Current page name when page context is resolved
${question} Generated flashcard question, only in follow-up flashcard prompts

Response-time variables

These are available in llm-response:

Variable Meaning
${response} The model output
${input} Original user input, if any
${block} Current block tree content, if used
${page} Current page content, if used
${pageName} Current page name, if used

Important template rules

  • if a command uses ${input}, the plugin opens the prompt UI before execution
  • if a command uses ${page}, it is treated as a page command
  • if a command does not use ${input}, it runs immediately when selected
  • if llm-model is omitted, the first configured model from settings is used
  • llm-output defaults to structured
  • llm-output flashcard requires llm-follow-up-user

Choosing models

The plugin supports two model selection levels:

Global default models

Set one model per line in the Models setting. The first entry is used as the default fallback.

Per-command model override

Use llm-model in a command template to pin a command to a specific model:

- llm-command Deep reasoning review
  - llm-model gpt-4.1
  - llm-user
  ```md
  Review the following and identify hidden assumptions:

  ${block}
  ```

This is useful when you want:

  • a fast cheap model for simple rewrites
  • a stronger reasoning model for planning or critique
  • a local model for private notes
  • a hosted model for higher quality summaries

Best practices for users

  • Keep at least one valid model in the Models setting.
  • Start with simple custom commands before building multi-step prompts.
  • Use ${block} when you want to operate on a focused subtree.
  • Use ${page} only when you really need whole-page context.
  • Prefer short, explicit system prompts.
  • Use llm-response when you want inserted output to have a stable heading such as Summary or Action Items.
  • Reload commands after editing your command page.
  • Restart the plugin if you removed a context-menu-visible command and the stale menu entry is still shown.

Best practices for writing commands

  • Give commands clear, action-oriented titles.
  • Make the user prompt explicit about output format.
  • Ask for note-friendly structure when the result should become Logseq blocks.
  • Use flashcard output only for true question/answer workflows.
  • If a command should be reusable from the block context menu, avoid ${input} and include ${block} or ${page} explicitly.
  • Keep custom command definitions on a dedicated page so they are easy to maintain.

Troubleshooting

The plugin says it could not fulfill the request

Check:

  • Base API URL
  • API token
  • model name
  • whether your server really supports OpenAI-compatible chat completions

Commands do not reload

Check:

  • that Command templates file points to an existing page in the current graph
  • that your command syntax starts with - llm-command ...
  • that you pressed the reload shortcut or restarted the plugin

A custom command does not ask for input

The prompt UI only opens if the command template contains ${input}.

A command does not appear in the block context menu

Only commands that:

  • do not require manual input
  • explicitly reference ${block} or ${page}

are registered as block context menu actions.

License

MIT

About

LLM plugin for LogSeq

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors