AI Assistant for Obsidian

Unlocking the power of AI in your Obsidian vault. Powerful workflows to automate the trivial so you can focus on the important. A guide to using the AI Assistant.

Hey there.

I hope you've had a great week.

This past week, QuickAdd for Obsidian reached over 250,000 downloads. I made a post on Twitter to celebrate.

What I've made for you

Twitter threadLeverage is how you get outputs that are disproportionate to your inputs.
As an example of leverage, I mention AI & large-scale automations, which leads me to...

Twitter threadI have finally unlocked the power of AI in Obsidian
I've created a custom tool that can

  • use prompt templates

  • chain prompts 🤯

  • use plugins like Dataview

  • can easily be injected into any of my existing workflows, e.g. summarize book notes

This thread showcases some of the use cases for it.
Because you’re subscribed, I want you to be among the first to use the tool, so here is the first release & a guide to using it.

AI Assistant for Obsidian

What if you could take all of your existing workflows in Obsidian, and in just a few steps, add the power of AI?

Imagine…

  • Creating a new note and having AI curate writing prompts, based on links you’ve already made, so you never start from a blank page

  • Using AI as an intellectual sparring partner as you write your notes

  • Effortlessly transforming the structure of your writing by giving instructions in plain English

All this, and so much more, is now possible from within Obsidian.

I’ve created a user script for QuickAdd which leverages the full power of QuickAdd and integrates it with AI.

Let me show you how to get this power for yourself.

I’ve recorded a video showing you how to set everything up in your vault, from 0 to AI-powered.

All right. Here’s everything you’ll need:

The video shows you how to get everything set up, but here’s a short rundown:

  1. Save the script somewhere in your vault. I recommend having a ‘scripts’ folder for it. You can save it by going to the raw file view and right-click-saving it (or CTRL+S). It’ll be the openai-gpt.js file.

  2. Inside Obsidian, create a folder for AI prompt templates. Remember the path to this folder, you’ll need it later. E.g. bins/ai_prompts.

  3. Create a new QuickAdd Macro Choice in the QuickAdd settings. Click the cog-wheel to configure the Macro Choice.

  4. Click the + button to make a Macro associated with that choice. Then click the cog to open the Macro settings for the newly created macro.

  5. Add the user script to the macro - the script you just saved. If you didn’t change the name, it’ll be called openai-gpt.

  6. Open the user script settings by clicking the cog next to it. Add your OpenAI API key.

  7. Write the path to your AI prompt template folder.

  8. Configure the remaining settings as you like - see the video for description of each setting.

  9. Going out of the user script settings, back to the Macro settings: add a Capture or Template to the macro - depending on your use case. Basically, Template Choices are for creating new notes, and Captures are for capturing to existing notes. This is all described in my previous video on QuickAdd.

And that’s really all you need to have a basic setup.
You can now create a ton of AI prompt templates and start using them.
Creating prompts is simple: just create a note in your prompt templates folder. You can use any of QuickAdds Format Syntax.

For inspiration, here are some of the ways I’m already using this tool. 👇

My basic setup

I have a folder for AI prompt templates, as recommended. My basic AI Assistant macro setup uses just the user script followed by a Capture.

The Capture is set to capture to the active file, and has the following Capture format (link):

{{selected} }

{{value:output} }

As explained in the video, {{selected} } is either empty or whatever text you’ve selected, making it ideal for using AI in the active file. {{value:output} } is the assistant’s output.

But the script can be used as a building block in more elaborate macros, as we shall see.

IMPORTANT: There will be a bunch of QuickAdd format syntax below. My email provider seems to use similar syntax for templating in their emails, which conflicts with the templates I’m providing. QuickAdd’s format syntax is always {{ followed by a syntax item (e.g. value, selected), and then closed by two } } (without the space between). In this mail, I unfortunately have to add a space between one of the curly braces to avoid the syntax getting eaten. To make up for this, I’ve included links to each complete file, so you can copy-paste from there instead.

Generating writing prompts

Enter a link and AI generates 10 writing prompts based on your notes connecting to that note. (link)

This prompt template uses Dataview (required plugin) to get all notes related to the one you enter.

Here is a list of Obsidian (Markdown) links to pages related to {{value:Link} }. 
Please use these to give me 10 writing prompts in bullet form concerning {{value:Link} }.

Use the links in paragraps as part of the sentences.

```js quickadd
// Use a shorthand for the DataView API
const dv = DataviewAPI;
// Prompt user for link to MOC note
const targetLink = await this.quickAddApi.inputPrompt("MoC Link", "Enter a link we'll use to get all notes linked to it.");
this.variables["Link"] = targetLink;

// Get a list of all notes linked to the target link
const healthPages = dv.pages(targetLink).values;
// Format the notes as [[links]]
const links = healthPages.map(f => {
	const tf = app.vault.getAbstractFileByPath(f.file.path);
	return app.fileManager.generateMarkdownLink(tf, '/');
});

// Join the list such that it is in text format, and there is one link per line
return links.join("\n");
```

MOC Creator

Here’s the MOC outline creator I showcased in the Twitter thread. This is an improved version which, like the above prompt, asks you for a link, and then it generated a MOC for that note. (link)

Here is a list of Obsidian (Markdown) links to pages related to {{value:Link} }. 
Please use these to write the outline for a note concerning {{value:Link} }. It should be at most 200 words.

Use the markdown links in paragraps as part of the sentences. 

```js quickadd
// Use a shorthand for the DataView API
const dv = DataviewAPI;
// Prompt user for link to MOC note
const targetLink = await this.quickAddApi.inputPrompt("MoC Link", "Enter a link we'll use to get all notes linked to it.");
this.variables["Link"] = targetLink;

// Get a list of all notes linked to the target link
const healthPages = dv.pages(targetLink).values;
// Format the notes as [[links]]
const links = healthPages.map(f => {
	const tf = app.vault.getAbstractFileByPath(f.file.path);
	return app.fileManager.generateMarkdownLink(tf, '/');
});

// Join the list such that it is in text format, and there is one link per line
return links.join("\n");
```

Summarizer

Here’s a simple prompt where you select some text, and then use the assistant with that prompt. Then it’ll spit out an AI-generated summary: (link)

Please summarize the following text. Use only the text itself as material for summarization, and do not add anything new. Rewrite this for brevity, in outline form:
{{value} }

Transform selected

This prompt template will ask you for instructions, which it’ll use to transform the text you’ve selected. (link)

It can do basically anything - not just transform. You could ask it to summarize text by giving instructions similar to those in the summarizer prompt, explain the text you’ve selected, rewrite something in outline form, or anything you’d like.

I asked it to explain a LaTeX equation I had selected by using the symbols as reference, and it did so perfectly, explaining each symbol, and then the whole formula.

Instructions:
{{VALUE:Instructions} }

Please follow the instructions above to transform the text:
{{selected} }

Flashcard creator

This prompt template generates flashcards based on selected text. (link)

Please create flashcards in the form
Q: Question here
A: Answer here

The question should be brief, to the point, simple, and should not be double-barreled. Avoid general questions and double negative questions.
The answer should also be brief and simple.

If you cannot contain the material in a single question, please create multiple flashcards.

---
{{value} }

Get me started writing about…

To get your writing kickstarted: (link)

I'm writing about {{value:Topic} }.

Please give me some points to get started:
- What are the adjacent topics? 
- What are the basics of the topic? 
- Why was the "{{value:Topic} }" topic created? 
- What problems does it solve?

Manual prompt

I consider this almost essential. It’s similar to just opening ChatGPT and prompting it.

The template will ask you for some input, which is the entire prompt. (link)

{{value} }

Alternative viewpoints

This one helps me a lot when I’m stuck. It’s nice to get another perspective on things. You’ll want to select some text (your draft) and then enter a topic when prompted. (link)

I'm writing about {{value:Topic} }. Here's my draft:

{{value} }

Please suggest 3 improvements, 3 alternative viewpoints, and 3 questions for further reflection.

Prompt Chaining

Okay, let’s get to some more advanced stuff.

Prompt chaining is where a prompt uses the output of a previous prompt. Essentially, you’re making the AI think in steps - like following a recipe.

Like I mentioned earlier, the AI Assistant script can be viewed as a building block.
You can stack them together to get powerful results.

Three AI prompts after each other

And when you configure each one to have specific settings, you can have it completely automated:

AI Assistant that won’t ask you any questions. It just follows orders.

For example, this is the first step. It uses the ChainPrompt1 template and outputs its value in {{value:out1} }. And since this is a macro, each output variable can be used in subsequent steps.

By stacking the assistant a bunch of times and using templates that each consume the output variable of the previous step, we get chain prompting.

Chain prompting templates

The final capture has a capture format like this one:

## Iteration 1
{{value:out1} }

## Iteration 2
{{value:out2} }

## Output
{{value:out_final} }

Summarize book notes

This was one of the first workflows I built with the AI Assistant.

Here is my previous workflow for importing book notes into Obsidian:

1. Get highlights from Readwise
2. Create note in vault

New, AI-powered workflow:

1. Get highlights from Readwise
2. AI Assistant summarizes book based on highlights
3. Create note in vault with summary

The core workflow is really the same. I just pick a book, and it gets imported, so my input hasn’t changed.

New workflow summarizing my book notes on Outlive by Peter Attia. I wasn’t done with the book when this was taken.

You can get this workflow, too! Here is the macro we need to set up:

AI-powered book importer macro

The first and last steps both come from my How I Import Literature Notes into Obsidian blog post. If you have followed it previously, you’ll need to do so again, as I’ve recently updated the script and instructions for a more powerful workflow (prior to making the AI assistant).

Here’s the AI Assistant script settings:

AI Assistant script settings

It uses the GPT-4 model for greater context size - it can simply take a much larger input.

Here’s the template it uses: (link)

Please summarize the following book "{ {value:title} }" by { {value:author} }. Use only the text itself as material for summarization, and do not add anything new. Rewrite this for brevity:

{ {value:highlights} }

Each of these values come from the EzImport script, which is why the ordering of the macro has to be EzImport → AI Assistant → Capture.

So, start by following the guide. Inject the AI Assistant in the middle of that workflow with the settings shown above… and that’s it.

Conclusion on AI Assistant

This is still the early stages. I have so many ideas for workflows, prompts, and other cool things we can do with this AI Assistant.

If you have any questions, please let me know.
All my prompt templates can also be found on the same page the AI Assistant script is.

I’m also considering making this a part of QuickAdd, so you don’t have to insert your API key each time you add the script to a macro. It wouldn’t be difficult to do, and could fit nicely. Thoughts?

Also, I’d love to see how you are using AI in your vault. Feel free to @ me on Twitter or by replying to this email.

Please remember that using your API has monetary costs. GPT-3.5 is rather inexpensive, but GPT-4 can get costly if used excessively. I strongly encourage you to set a spending limit on your OpenAI account for this very reason. Try to play around with the models to see what works for you.

{{hi}}

Quote

Take a simple idea and take it seriously.

Charlie Munger