Brian Sunter

Logseq GPT-3 OpenAI Popup

I updated the Logseq GPT-3 OpenAI plugin to have a popup UI and support user-defined commands.

I updated the Logseq OpenAI plugin to include a popup window to perform AI tasks powered by OpenAI’s GPT-3 in Logseq.

There are three modes: custom commands, built-in commands, and user-defined commands.

There’s also a way for the community to contribute useful commands to the plugin for everyone to use.

Background

OpenAI’s GPT-3 is an AI tool that allows you to analyze and generate text. It can perform many tasks, such as answering questions about a topic, writing blog posts, summarizing text, and more.

I’ve found various interesting use cases in my notetaking workflow, and it’s been a useful “swiss army knife” for notetaking and text manipulation.

The original version of this plugin was pretty basic. In the previous version, you would write a GPT-3 “prompt” inside a text block along with the input text, generating a response and inserting it underneath your text. I hope this new popup is easier to use and more convenient.

There have been a few “AI writer” integrations in existing tools like Notion and many startups built around OpenAI GPT-3.

These tools are nice and have good user interfaces but have some limitations for personal notetaking use cases and for power users. I wanted something that was pay-as-you-go instead of subscription-based, allowed a lot of customizability, and allowed users to share prompts with each other.

The plugin is free and open source but uses OpenAI’s API, which does charge per API request; however, using their API directly with your key is much cheaper than any commercial option.

Getting started

Go to the logseq plugin marketplace and search for “openai” or update the plugin to get the latest version.

Sign up for an OpenAI API key if you don’t already have one, and add it in the plugin settings.

Press CMD+g to open the GPT-3 popup.

If you have your cursor inside a block, the popup will use the text in the block as input to the command.

If the block is empty, it will run the command without input.

For now, the input text from the block is appended after the command prompt you type in the popup.

If you are on a page and don’t have a block selected, the plugin will append the result in a block at the bottom of the page and won’t use any text as input.

Custom commands

You can open the popup and type in any task you want to perform.

For example, if you have a block of text and want to generate question-and-answer flashcards to help you remember important points, you could type

create flash cards based on the following text:

If you’re in an empty block, you can ask it to perform a task without input.

What topics should I study to understand deep learning?

Built-in commands

There are many built-in commands for common use cases

Some of the built-in prompts include:

Summarize Text

Fix Grammar

Create Outline

Extract Keywords

Write introduction

Find Keywords

Ask Questions

Find common objections to an idea

Most important ideas

Define word

Find synonyms

Find antonyms

Create markdown table from text

Translate to other languages

Here are some demos of the built-in commands:

Summarize text

Create outline of text

Most important ideas in a text

Common objections to an idea

User-Defined commands

You can define your own commands to show up in the popup.

These are defined similarly as Logseq templates.

How to create a user-defined command

Indent a block underneath the prompt template block that contains a code block of type prompt (triple backticks followed by the word prompt)

These can be written anywhere in your notes and they’ll be detected in the popup (like logseq templates)

Language flash cards

Here’s an example of making language learning flashcards from a YouTube transcript.

Student teacher dialog example

This is an example of defining a custom prompt to rewrite a piece of text as a dialog between a student and teacher.

##+BEGIN_SRC

Student Teacher Dialog

   Rewrite the following text as a dialog between a teacher and a student:

##+END_SRC

Preview

After you hit enter to run a command, the popup will show you a preview of the result from GPT-3, so you can decide if you want to insert the result into your notes

Insert and Replace

After you run the command, you can either insert the GPT-3 result underneath the current block or replace the current block with the GPT-3 result.

The replace feature is helpful when using the plugin to improve the tone of existing writing, fix grammar/spelling, and translate text into different languages.

Replace example

Regenerate

Sometimes the first try doesn’t generate optimal results, so you can click “Regenerate” to re-run the prompt until you get something good.

Share Prompts

Do you have a prompt that the community would find useful? Contribute it to the built-in prompts list.

There’s a TOML text file in the repo where you can easily add new prompts.

Go here to see the prompt file in the repo

Future work

I have several enhancements in mind to add to the plugin.

The next features I’m planning are to add better support for sending multiple blocks as the command input.

I also want to add features that let you transform the input and output—for example, removing markdown from the input text and splitting the output text into multiple blocks.

Eventually, I’d like to support sourcing blocks throughout your notes using embeddings, so you can leverage the knowledge in your notes in the commands.

I have a Github Project and list of issues to track ideas for features. Feel free to open an issue or contribute if you have an idea or find a bug!

Share this post