Skip to content

Commit 2c39452

Browse files
committed
docs wip
1 parent 49bbf93 commit 2c39452

File tree

8 files changed

+170
-15
lines changed

8 files changed

+170
-15
lines changed

docs/pages/docs/_meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"custom-schemas": "Custom Schemas",
99
"collaboration": "Collaboration",
1010
"advanced": "Advanced",
11+
"ai": "AI",
1112
"discord-link": {
1213
"title": "Community ↗",
1314
"href": "https://discord.gg/Qc2QTTH5dF",

docs/pages/docs/ai.mdx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: AI Rich Text Editing
3+
description: Add AI functionality to your BlockNote rich text editor
4+
imageTitle: BlockNote AI
5+
path: /docs/ai
6+
---
7+
8+
import { Example } from "@/components/example";
9+
import { Callout } from "nextra/components";
10+
11+
# BlockNote AI integration
12+
13+
With BlockNote AI, you can add AI functionality to your rich text editor.
14+
Users can work with an AI agent to edit, write and format their documents.
15+
16+
[VIDEO]
17+
18+
- Try the [basic AI demo](/examples/ai/minimal)
19+
- ..or try different models in the [AI playground](/examples/ai/playground)
20+
- [Setup documentation](/docs/ai/getting-started)
21+
- TODO
22+
23+
## Features
24+
25+
BlockNote AI has been designed to be fully customizable.
26+
BlockNote shows exactly what the AI agent is doing - making it easy for users to
27+
work hand in hand with AI agents.
28+
29+
- Customize commands to write new content or update existing content or formatting
30+
- Streaming support for quick feedback
31+
- Users can accept or reject AI suggestions
32+
- Connect any LLM model (from Llama to OpenAI, Mistral or Anthropic)
33+
- Customizable prompts
34+
- Built directly on the [Vercel AI SDK](https://sdk.vercel.ai)
35+
- No dependency on our backend - use your own infrastructure or connect directly to a hosted LLM API
36+
- Feature requests? [Get in touch](/about).
37+
38+
<Callout type={"info"}>
39+
This feature is provided by the `@blocknote/xl-ai`. `xl-` packages are fully
40+
open source, but released under a copyleft license. A commercial license for
41+
usage in closed source, proprietary products comes as part of the [Business
42+
subscription](/pricing).
43+
</Callout>

docs/pages/docs/ai/_meta.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"setup": "Editor Setup",
3+
"custom-commands": "Customizing Commands",
4+
"reference": "Reference"
5+
}

docs/pages/docs/ai/custom-commands.mdx

Whitespace-only changes.

docs/pages/docs/ai/reference.mdx

Whitespace-only changes.

docs/pages/docs/ai/setup.mdx

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
title: AI Rich Text Editing
3+
description: Add AI functionality to your BlockNote rich text editor
4+
imageTitle: BlockNote AI
5+
path: /docs/ai
6+
---
7+
8+
import { Example } from "@/components/example";
9+
import { Callout } from "nextra/components";
10+
11+
# Getting Started with BlockNote AI
12+
First, install the `@blocknote/xl-ai` package:
13+
14+
```bash
15+
npm install @blocknote/xl-ai
16+
```
17+
18+
## Creating a Model
19+
20+
BlockNote AI uses the the [AI SDK](https://ai-sdk.dev/docs/foundations/overview) to standardize integrating artificial intelligence (AI) models across [supported providers](https://ai-sdk.dev/docs/foundations/providers-and-models).
21+
22+
As a first step, you'll need to register a new model with the AI SDK. For example, for Llama hosted on Groq:
23+
24+
```bash
25+
npm install @ai-sdk/groq
26+
```
27+
28+
```ts
29+
import { createGroq } from "@ai-sdk/groq";
30+
31+
const provider = createGroq({
32+
apiKey: "YOUR_GROQ_API_KEY",
33+
});
34+
35+
const model = provider("llama-3.3-70b-versatile");
36+
```
37+
38+
<Callout type={"warning"}>
39+
Note that this setup directly calls the provider from the client, and exposes
40+
your API keys on the client. For Production scenarios, a more common approach is to
41+
handle authentication on your own server and proxy requests to a provider. See
42+
our [Demo AI
43+
Server](https://github.com/TypeCellOS/BlockNote/tree/main/packages/xl-ai-server)
44+
for a Node.js example or check the AI SDK best practices.
45+
</Callout>
46+
47+
## Setting up the editor
48+
49+
Now, you can create the editor with the AI Extension enabled:
50+
51+
```ts
52+
import { createBlockNoteEditor } from "@blocknote/core";
53+
import { BlockNoteAIExtension } from "@blocknote/xl-ai";
54+
import {
55+
AIToolbarButton,
56+
BlockNoteAIUI,
57+
locales as aiLocales,
58+
createAIExtension,
59+
createBlockNoteAIClient,
60+
getAISlashMenuItems,
61+
} from "@blocknote/xl-ai";
62+
63+
const editor = createBlockNoteEditor({
64+
dictionary: {
65+
...en,
66+
ai: aiLocales.en, // add default translations for the AI extension
67+
},
68+
extensions: [
69+
createAIExtension({
70+
model,
71+
}),
72+
],
73+
// ... other editor options
74+
});
75+
```
76+
77+
### The `createAIExtension` method
78+
79+
TODO
80+
81+
## Adding AI UI elements
82+
83+
Now, the only thing left to do is to customize the UI elements of your editor.
84+
85+
```tsx
86+
<BlockNoteView
87+
editor={editor}
88+
// We're disabling some default UI elements
89+
formattingToolbar={false}
90+
slashMenu={false}>
91+
{/* This has AI specific components like the AI Command menu */}
92+
<BlockNoteAIUI />
93+
94+
{/* Create you own Formatting Toolbar with an AI button,
95+
(see the full example code below) */}
96+
<FormattingToolbarWithAI />
97+
98+
{/* Create you own SlashMenu with an AI option,
99+
(see the full example code below) */}
100+
<SuggestionMenuWithAI editor={editor} />
101+
</BlockNoteView>
102+
```
103+
104+
# Full Example
105+
106+
<Example name="ai/minimal" />

examples/09-ai/01-minimal/App.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/// <reference types="./vite-env.d.ts" />
2-
31
import { createGroq } from "@ai-sdk/groq";
42
import { BlockNoteEditor, filterSuggestionItems } from "@blocknote/core";
53
import "@blocknote/core/fonts/inter.css";
@@ -27,10 +25,9 @@ import "@blocknote/xl-ai/style.css";
2725
// Optional: proxy requests through the `@blocknote/xl-ai-server` proxy server
2826
// so that we don't have to expose our API keys to the client
2927
const client = createBlockNoteAIClient({
30-
apiKey: import.meta.env.VITE_BLOCKNOTE_AI_SERVER_API_KEY || "PLACEHOLDER",
28+
apiKey: getEnv("BLOCKNOTE_AI_SERVER_API_KEY") || "PLACEHOLDER",
3129
baseURL:
32-
import.meta.env.VITE_BLOCKNOTE_AI_SERVER_BASE_URL ||
33-
"https://localhost:3000/ai",
30+
getEnv("BLOCKNOTE_AI_SERVER_BASE_URL") || "https://localhost:3000/ai",
3431
});
3532

3633
// Use an "open" model such as llama, in this case via groq.com
@@ -100,6 +97,7 @@ export default function App() {
10097
<div>
10198
<BlockNoteView
10299
editor={editor}
100+
// We're disabling some default UI elements
103101
formattingToolbar={false}
104102
slashMenu={false}>
105103
{/* This has AI specific components like the AI Command menu */}
@@ -128,6 +126,7 @@ function FormattingToolbarWithAI() {
128126
formattingToolbar={() => (
129127
<FormattingToolbar>
130128
{...getFormattingToolbarItems()}
129+
{/* Add the AI button */}
131130
<AIToolbarButton />
132131
</FormattingToolbar>
133132
)}
@@ -146,6 +145,7 @@ function SuggestionMenuWithAI(props: {
146145
filterSuggestionItems(
147146
[
148147
...getDefaultReactSlashMenuItems(props.editor),
148+
// add the default AI slash menu items, or define your own
149149
...getAISlashMenuItems(props.editor),
150150
],
151151
query,
@@ -154,3 +154,13 @@ function SuggestionMenuWithAI(props: {
154154
/>
155155
);
156156
}
157+
158+
// helper function to get env variables across next / vite
159+
// only needed so this example works in BlockNote demos and docs
160+
function getEnv(key: string) {
161+
// TODO
162+
// const env2 = process.env.NEXT_PUBLIC_BLOCKNOTE_AI_SERVER_BASE_URL;
163+
return (import.meta as any).env
164+
? (import.meta as any).env["VITE_" + key]
165+
: process.env["NEXT_PUBLIC_" + key];
166+
}

examples/09-ai/01-minimal/vite-env.d.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)