Skip to content

Commit 00dc122

Browse files
authored
Merge pull request #2 from parente/parente/webclipper
Create Obsidian Web Clip Summaries on MacOS with Firefox and Llama 3.2
2 parents b062af2 + 6db3d92 commit 00dc122

File tree

6 files changed

+146
-2
lines changed

6 files changed

+146
-2
lines changed

generate.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,22 @@ def org_pages(pages: list[Page]):
165165
class MarkdownParser:
166166
def __init__(self):
167167
self.md = markdown.Markdown(
168-
extensions=["meta", "fenced_code", "codehilite"], output_format="html"
168+
extensions=[
169+
"meta",
170+
"fenced_code",
171+
"codehilite",
172+
"footnotes",
173+
"sane_lists",
174+
],
175+
output_format="html",
169176
)
170177

171178
def execute(self, path: str, page: Page):
172179
"""Parse an md file in the path and update the page with its HTML rendered content and
173180
metadata."""
181+
# Don't leave conversion state across pages (e.g., footnotes)
182+
self.md.reset()
183+
174184
fn = join(path, "index.md")
175185
if not os.path.isfile(fn):
176186
return
644 KB
Loading
563 KB
Loading
548 KB
Loading
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
date: 2024-11-29
3+
title: Create Obsidian Web Clip Summaries on MacOS with Firefox and Llama 3.2
4+
excerpt: I use Obsidian to capture all kinds of information. I set out to get the Obsidian web clipper Firefox extension configured on my Mac with a local Meta Llama 3.2 model to summarize content. This post explains the steps I took top-to-bottom.
5+
---
6+
I use [Obsidian](https://obsidian.md) to capture information like my daily todo lists; notes about things I've read, listened to, watched, or done; reminders about repeating chores and home maintenance tasks; trips I'm planning or places I've visited--anything and everything.
7+
8+
I recently learned about the [Obsidian web clipper](https://github.com/obsidianmd/obsidian-clipper) browser extension. I was intrigued by some of the features [shown on the landing page](https://obsidian.md/clipper). I started thinking about how it might improve my workflows for indexing web pages that I want to go back and read in more detail and distilling them into notes for quick reference later. Instead of manually entering all of the page metadata, copy/pasting text from the page into a note, and writing a quick summary, maybe the extension could take a first pass for me.
9+
10+
I set out to get the [web clipper Firefox extension](https://addons.mozilla.org/en-US/firefox/addon/web-clipper-obsidian/) configured on my Mac, with a local [Meta Llama 3.2](https://ollama.com/library/llama3.2) model set as an [interpreter](https://help.obsidian.md/web-clipper/interpreter) to summarize content in some of my [templates](https://help.obsidian.md/web-clipper/templates). The [Obsidian help pages](https://help.obsidian.md/web-clipper) explained the basics. I wrote this post to describe the steps I took from top-to-bottom, including what I did to get summaries of acceptable quality in my clippings.[^1]
11+
# Prereqs
12+
13+
I started with the following:
14+
15+
- Macbook Pro M2 w/ 16 GB RAM
16+
- macOS Sequoia 15.x
17+
- [homebrew](https://homebrew.sh)
18+
- [Firefox](https://www.mozilla.org/en-US/firefox/) (`brew install --cask firefox`)
19+
- [Obsidian](https://obsidian.md) >=1.7.2 (`brew install --cask obsidian`)
20+
21+
# Page Highlights
22+
23+
I installed the extension and created an initial template to store page highlights in Obsidian notes by following the steps below.
24+
25+
1. Install the Obsidian web clipper extension from [the Firefox add-ons site](https://addons.mozilla.org/en-US/firefox/addon/web-clipper-obsidian/).
26+
2. Click the Obsidian icon in the Firefox toolbar and then click the gear to open the settings screen.
27+
3. Add my primary vault named `Journal` to the _Vaults_ list.
28+
4. Create a _New Template_ named `Highlights Only` which saves to the `untriaged` folder in my `Journal` vault and has _Note content_ `{{highlights|map: item => item.text|join:"\n\n"}}` (i.e., the text of all my highlights separated by newlines).
29+
5. Update the _Properties_ in the template to align with ones I already use on my Obsidian notes (e.g., `url` instead of `source`, `clipped` instead of `created` with a ISO-8601 datetime).
30+
6. Delete the _Default_ template.
31+
7. Click _Properties_ in the sidebar and then _Remove unused properties_ so only the metadata I care about is listed.
32+
33+
At this point, I was able to open the extension, click the highlighter icon, select portions of the page, and save notes containing my manual highlights.
34+
35+
![Screenshot of the web clipper capturing highlighted sections of a page on this blog](./clip-highlights.png)
36+
37+
# Page Summaries
38+
39+
I created a second template that includes a generated page summary in addition to my highlights by taking these steps.
40+
## Create an ollama model for summarization
41+
42+
1. Install the Ollama macOS desktop app and CLI with `brew install --cask ollama`.
43+
2. Run `launchctl setenv OLLAMA_ORIGINS 'moz-extension://*'` so that the local Ollama server will accept connections from my Firefox browser.[^2]
44+
3. Run the Ollama macOS app from the finder and work through the setup dialog screens until they disappear.[^3]
45+
4. Create a `Modelfile` with the following content.
46+
```
47+
# Use the 3B parameter, 2 GB base model file
48+
FROM llama3.2
49+
# Larger context window for page summaries
50+
PARAMETER num_ctx 32768
51+
# Lower temperature for more conservative sampling / less creative summaries
52+
PARAMETER temperature 0.25
53+
```
54+
5. Run `ollama create -f Modelfile llama3.2:ctx32k-t0.25` to create a model config with that ID.
55+
6. Run `ollama list` and confirm the base and custom models exist.
56+
57+
## Enable the model as an interpreter
58+
59+
1. Click the Obsidian icon in the Firefox toolbar and then click the gear to open the settings screen again.
60+
2. Click _Interpreter_ and enable it.
61+
3. Click _Add model_ and enter details about the local Ollama server.
62+
- _Display name_: `Llama 3.2 (ctx=32k, t=0.25)`
63+
- _Base URL_: `http://127.0.0.1:11434/api/chat`
64+
- _Model ID_: `llama3.2:ctx32k-t0.25` (the ID used when running `ollama create` earlier)
65+
- _Provider_: `Ollama`
66+
- _API key_: `ollama`
67+
4. Drag the new model so that it appears first and disable the other models.
68+
69+
## Create a new template
70+
71+
1. Click the _Highlights Only_ template created earlier.
72+
2. Click _More -> Duplicate_ at the top.
73+
3. Name the new template _Summary and Highlights_.
74+
4. Update the _Note content_ to include a prompt variable.
75+
```markdown
76+
# AI Summary
77+
78+
{{"Generate a concise, 5 sentence summary of the content within the prior <documentPrefix></documentPrefix> tags."|strip_tags}}
79+
80+
# Highlights
81+
82+
{{highlights|map: item => item.text|join:"\n\n"}}
83+
```
84+
5. Update the _Interpreter context_ to include a slice of the page content smaller than the context window configured for the model.
85+
```markdown
86+
<documentPrefix>{{content|slice:0,16384}}</documentPrefix>
87+
```
88+
89+
After these additional steps, I was able to select the `Summary and Highlights` template in the extension popup, select the `Llama 3.2 (ctx=32k, t=0.25)` interpreter, click _Interpret_ to get a preview of generated summary, and save notes containing both the summary and my manual highlights.
90+
91+
![Screenshot of the web clipper showing a generated summary highlighted sections of a page on this blog](./clip-summary-and-highlights.png)
92+
93+
# Site-Specific Templates
94+
95+
I found that my generic _Summary and Highlights_ template did not work on all sites. The `{{content}}` variable, for instance, only contains text about cookies on AWS documentation pages. I created a [template selected automatically](https://help.obsidian.md/web-clipper/templates#Automatically+trigger+a+template) for the AWS docs site by following the steps below.
96+
97+
1. Visit the extension settings again.
98+
2. Click the _Summary and Highlights_ template created earlier.
99+
3. Click _More -> Duplicate_ at the top.
100+
4. Name the new template _AWS Docs Summary and Highlights_.
101+
5. Put `https://docs.aws.amazon.com/` in the _Template triggers_ textbox.
102+
6. Update the _Note content_ with a slightly customized prompt.
103+
```markdown
104+
# AI Summary
105+
106+
{{"Generate a concise, 5 sentence summary of the AWS docs content within the prior <documentPrefix></documentPrefix> tags."|strip_tags}}
107+
108+
# Highlights
109+
110+
{{highlights|map: item => item.text|join:"\n\n"}}
111+
```
112+
7. Update the _Interpreter context_ to pull content from the HTML element with `id="main"` instead of [where the extension gets it by default](https://help.obsidian.md/web-clipper/troubleshoot#Some+content+is+missing).
113+
```markdown
114+
<documentPrefix>{{selectorHtml:#main|markdown|slice:0,16384}}</documentPrefix>
115+
```
116+
117+
I was able to visit one of the [Amazon Bedrock documentation pages](https://docs.aws.amazon.com/bedrock/latest/userguide/tool-use-inference-call.html) and generate a meaningful summary after configuring this template for automatic activation on the https://docs.aws.amazon.com site.
118+
119+
![Screenshot of the web clipper automatically switching to the AWS Docs Summary and Highlights template and generating a custom summary when visiting an AWS documentation page](./clip-aws-docs.png)
120+
# Final Thoughts
121+
122+
- The web clipper extension is in beta as of this writing. I expect the UX will change.
123+
- There are a lot of knobs to turn here, from model parameters to prompt variables to note formats to template configs. Tuning and tweaking is in order.
124+
- The OpenAI and Anthropic models would likely provide better results out of the gate. I'm sticking with Ollama/Llama in the spirit of the local-only Obsidian privacy model.
125+
126+
[^1]: I'm maintaining my latest Obsidian configs in [parente/obsidian-configs on GitHub](https://github.com/parente/obsidian-configs).
127+
[^2]: I did spend a few moments considering if I should set this env var less globally and narrow down the extension UUID(s) allowed. I did not think it worth the effort in my case. Follow your heart.
128+
[^3]: Restart the Ollama app from the macOS menu bar if you're already running it so that the `launchtl setenv` takes effect. Otherwise, the ollama server will respond with auth errors when the extension attempts to use it.

static/css/site.css

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,10 @@ body .gist {
199199

200200
.container{
201201
max-width:980px !important;
202-
}
202+
}
203+
204+
img {
205+
max-width: 100%;
206+
height: auto;
207+
border: 1px solid #ccc;
208+
}

0 commit comments

Comments
 (0)