🧠 Second Brain


Search IconIcon to open search

Integrate OpenAI into Obsidian

Last updated Nov 9, 2023

OpenAI (GPT-3) is a powerful AI that can write whole articles, see Data Nets (fully written by AI). It’s the same AI backbone GPT-3 that is used for GitHub Copilot.

Wouldn’t it be nice to use the inside of Obsidian? Luckily there are two plugins and one that works for my needs.

I liked the integration better of Ava and gave it a try. And it’s superb as you select text and apply a Template, and voila, OpenAI will generate the text.

Here a small demonstrations how it looks like:

# How to install

Check the instructions on GitHub. But essentially you need to create an account on OpenAI API, and create secret key under View API Keys. Copy these and add to your pluging in Obsidian.

It also supports Stable Diffusion to generate image, which I haven’t used yet

# Set up the Template

With the Templater plugin you need to add a script, I had to call it completeSelection.js and added this code (see GitHub for the latest):

const completeSelection = async () => {
    document.body.style.cursor = "wait";
    const msg = window.getSelection().toString();
    const response = await app.plugins.plugins["ava"].openai.createCompletion({
        "model": "text-davinci-002",
        "prompt": msg,
        "temperature": 0.7,
        "max_tokens": msg.length + 100,
        "top_p": 1,
        "frequency_penalty": 0,
        "presence_penalty": 0
    document.body.style.cursor = "default";
    return `${msg}${response.data.choices[0].text}`;

module.exports = completeSelection;

Set the location you put this JavaScript:
![[Pasted image 20221124105048.png]]

Now create a new Markdown note which you move to your Templater folder that contains nothing else than:

<% tp.user.completeSelection() %>

Now you are all set and can use it.

# How to use it?

You select a text, and activate a template with Templater either via cmd+p and search for Templater: Open Insert Template modal or add a shortcut to it (I have cmd+t) and the AI will do his job.

# Example with text-davinci-002

# Example with text-davinci-003

After the upgrade 2022-11-29 to text-davinci-003, I added the exact same questions:

Vim is an incredibly powerful text editor that is used by experienced developers and system administrators. It is incredibly fast, has a large number of features, and is highly customizable. Learning Vim can help you become a more efficient programmer and system administrator, enabling you to work faster and with fewer mistakes. It can also help you become more familiar with the command line, which is an essential skill for many development and sysadmin tasks.

Why is OpenAI the future?

OpenAI is the future because of its potential to revolutionize the way we interact with technology. Its focus on artificial general intelligence (AGI) research and development will allow machines to learn and think in ways that are similar to humans, potentially enabling them to solve complex problems and create new solutions. OpenAI’s focus on ethical AI use, as well as its commitment to making its technology accessible to everyone, also gives it an advantage over other tech companies. By making its technology available to the public, OpenAI will help to ensure that the AI revolution is an inclusive one, rather than an exclusive one that only benefits

See also a video on this Tweet.

References: More on Second Brain Assistant with Obsidian (NoteGPT)
Created 2022-11-24