AI Playground
Explore different LLM models integrated with BlockNote in the AI Playground.
Change the configuration, then highlight some text to access the AI menu, or type /ai
anywhere in the editor.
Relevant Docs:
- Getting Stared with BlockNote AI
- BlockNote AI Reference
- Changing the Formatting Toolbar
- Changing Slash Menu Items
import { BlockNoteEditor, filterSuggestionItems } from "@blocknote/core";
import "@blocknote/core/fonts/inter.css";
import { en } from "@blocknote/core/locales";
import { BlockNoteView } from "@blocknote/mantine";
import "@blocknote/mantine/style.css";
import {
FormattingToolbar,
FormattingToolbarController,
SuggestionMenuController,
getDefaultReactSlashMenuItems,
getFormattingToolbarItems,
useBlockNoteContext,
useCreateBlockNote,
usePrefersColorScheme,
} from "@blocknote/react";
import {
AIMenuController,
AIToolbarButton,
createAIExtension,
getAIExtension,
getAISlashMenuItems,
} from "@blocknote/xl-ai";
import { en as aiEn } from "@blocknote/xl-ai/locales";
import "@blocknote/xl-ai/style.css";
import { Fieldset, MantineProvider } from "@mantine/core";
import { useEffect, useState } from "react";
import { DefaultChatTransport } from "ai";
import { BasicAutocomplete } from "./AutoComplete";
import { getEnv } from "./getEnv";
const BASE_URL =
getEnv("BLOCKNOTE_AI_SERVER_BASE_URL") || "https://localhost:3000/ai";
export default function App() {
const [model, setModel] = useState<string>(
"groq.chat/llama-3.3-70b-versatile",
);
// Creates a new editor instance.
const editor = useCreateBlockNote({
dictionary: {
...en,
ai: aiEn, // add default translations for the AI extension
},
// Register the AI extension
extensions: [
createAIExtension({
transport: new DefaultChatTransport({
// URL to your backend API, see example source in `packages/xl-ai-server/src/routes/regular.ts`
api: `${BASE_URL}/model-playground/streamText`,
}),
}),
],
// We set some initial content for demo purposes
initialContent: [
{
type: "heading",
props: {
level: 1,
},
content: "Open source software",
},
{
type: "paragraph",
content:
"Open source software refers to computer programs whose source code is made available to the public, allowing anyone to view, modify, and distribute the code. This model stands in contrast to proprietary software, where the source code is kept secret and only the original creators have the right to make changes. Open projects are developed collaboratively, often by communities of developers from around the world, and are typically distributed under licenses that promote sharing and openness.",
},
{
type: "paragraph",
content:
"One of the primary benefits of open source is the promotion of digital autonomy. By providing access to the source code, these programs empower users to control their own technology, customize software to fit their needs, and avoid vendor lock-in. This level of transparency also allows for greater security, as anyone can inspect the code for vulnerabilities or malicious elements. As a result, users are not solely dependent on a single company for updates, bug fixes, or continued support.",
},
{
type: "paragraph",
content:
"Additionally, open development fosters innovation and collaboration. Developers can build upon existing projects, share improvements, and learn from each other, accelerating the pace of technological advancement. The open nature of these projects often leads to higher quality software, as bugs are identified and fixed more quickly by a diverse group of contributors. Furthermore, using open source can reduce costs for individuals, businesses, and governments, as it is often available for free and can be tailored to specific requirements without expensive licensing fees.",
},
],
});
const ai = getAIExtension(editor);
useEffect(() => {
// update the default model in the extension
// Add the model string to the request body
ai.options.setState({
chatRequestOptions: {
body: {
model,
},
},
});
}, [model, ai.options]);
const themePreference = usePrefersColorScheme();
const existingContext = useBlockNoteContext();
const theme =
existingContext?.colorSchemePreference ||
(themePreference === "no-preference" ? "light" : themePreference);
return (
<div>
<MantineProvider
cssVariablesSelector=".model-settings"
getRootElement={() => undefined}
>
<div className="model-settings" data-mantine-color-scheme={theme}>
<Fieldset legend="Model settings" style={{ maxWidth: "500px" }}>
<BasicAutocomplete
error={!model ? "Unknown model" : undefined}
value={model}
onChange={setModel}
/>
</Fieldset>
</div>
</MantineProvider>
<BlockNoteView
editor={editor}
formattingToolbar={false}
slashMenu={false}
>
{/* Add the AI Command menu to the editor */}
<AIMenuController />
{/* We disabled the default formatting toolbar with `formattingToolbar=false`
and replace it for one with an "AI button" (defined below).
(See "Formatting Toolbar" in docs)
*/}
<FormattingToolbarWithAI />
{/* We disabled the default SlashMenu with `slashMenu=false`
and replace it for one with an AI option (defined below).
(See "Suggestion Menus" in docs)
*/}
<SuggestionMenuWithAI editor={editor} />
</BlockNoteView>
</div>
);
}
// Formatting toolbar with the `AIToolbarButton` added
function FormattingToolbarWithAI() {
return (
<FormattingToolbarController
formattingToolbar={() => (
<FormattingToolbar>
{...getFormattingToolbarItems()}
<AIToolbarButton />
</FormattingToolbar>
)}
/>
);
}
// Slash menu with the AI option added
function SuggestionMenuWithAI(props: {
editor: BlockNoteEditor<any, any, any>;
}) {
return (
<SuggestionMenuController
triggerCharacter="/"
getItems={async (query) =>
filterSuggestionItems(
[
...getDefaultReactSlashMenuItems(props.editor),
...getAISlashMenuItems(props.editor),
],
query,
)
}
/>
);
}
import { Combobox, TextInput, useCombobox } from "@mantine/core";
import { AI_MODELS } from "./data/aimodels";
// https://mantine.dev/combobox/?e=BasicAutocomplete
// This is used for the AI Model selector in the example
export function BasicAutocomplete(props: {
value: string;
onChange: (value: string) => void;
error?: string;
}) {
const { value, onChange } = props;
const combobox = useCombobox();
const shouldFilterOptions = !AI_MODELS.some((item) => item === value);
const filteredOptions = shouldFilterOptions
? AI_MODELS.filter((item) =>
item.toLowerCase().includes(value.toLowerCase().trim()),
)
: AI_MODELS;
const options = filteredOptions.map((item) => (
<Combobox.Option value={item} key={item}>
{item}
</Combobox.Option>
));
return (
<Combobox
onOptionSubmit={(optionValue) => {
onChange(optionValue);
combobox.closeDropdown();
}}
store={combobox}
withinPortal={false}
>
<Combobox.Target>
<TextInput
label="Select model or type `<provider>/<model>`:"
placeholder="Select model or type `<provider>/<model>`"
value={value}
onChange={(event) => {
onChange(event.currentTarget.value);
combobox.openDropdown();
combobox.updateSelectedOptionIndex();
}}
onClick={() => combobox.openDropdown()}
onFocus={() => combobox.openDropdown()}
onBlur={() => combobox.closeDropdown()}
error={props.error}
/>
</Combobox.Target>
<Combobox.Dropdown>
<Combobox.Options mah={200} style={{ overflowY: "auto" }}>
{options.length === 0 ? (
<Combobox.Empty>Nothing found</Combobox.Empty>
) : (
options
)}
</Combobox.Options>
</Combobox.Dropdown>
</Combobox>
);
}
.root {
position: relative;
padding: var(--mantine-spacing-md);
transition: border-color 150ms ease;
&[data-checked] {
border-color: var(--mantine-primary-color-filled);
}
@mixin hover {
@mixin light {
background-color: var(--mantine-color-gray-0);
}
@mixin dark {
background-color: var(--mantine-color-dark-6);
}
}
}
.label {
font-family: var(--mantine-font-family-monospace);
font-weight: bold;
font-size: var(--mantine-font-size-md);
line-height: 1.3;
color: var(--mantine-color-bright);
}
.description {
margin-top: 8px;
color: var(--mantine-color-dimmed);
font-size: var(--mantine-font-size-xs);
}
import { Radio, Stack } from "@mantine/core";
import React from "react";
interface RadioGroupComponentProps {
label: string;
items: Array<{
name: string;
description: string;
value: string;
}>;
value: string;
onChange: (value: string) => void;
}
const RadioGroupComponent: React.FC<RadioGroupComponentProps> = ({
label,
items,
value,
onChange,
}) => (
<Radio.Group label={label} value={value} onChange={onChange}>
<Stack pt="md" gap="xs">
{items.map((item) => (
<Radio value={item.value} label={item.name} key={item.value} />
// TODO: doesn't work well with our mantine version or styles
// <Radio.Card
// className={styles.root}
// radius="md"
// value={item.value}
// key={item.value}>
// <Group wrap="nowrap" align="flex-start">
// <Radio.Indicator />
// <div>
// <Text className={styles.label}>{item.name}</Text>
// <Text className={styles.description}>{item.description}</Text>
// </div>
// </Group>
// </Radio.Card>
))}
</Stack>
</Radio.Group>
);
export default RadioGroupComponent;
export const AI_MODELS = [
"openai.chat/gpt-4o",
"openai.chat/gpt-4o-mini",
"openai.chat/gpt-4.1",
"groq.chat/llama-3.3-70b-versatile",
"groq.chat/llama-3.1-8b-instant",
"groq.chat/llama3-70b-8192",
"groq.chat/deepseek-r1-distill-llama-70b",
"groq.chat/qwen-qwq-32b",
"mistral.chat/mistral-large-latest",
"mistral.chat/mistral-medium-latest",
"mistral.chat/ministral-3b-latest",
"mistral.chat/ministral-8b-latest",
"anthropic.chat/claude-opus-4-1",
"anthropic.chat/claude-sonnet-4-0",
"anthropic.chat/claude-3-7-sonnet-latest",
"anthropic.chat/claude-3-5-haiku-latest",
"albert-etalab.chat/albert-large",
"google.generative-ai/gemini-1.5-pro",
"google.generative-ai/gemini-1.5-flash",
"google.generative-ai/gemini-2.5-pro",
"google.generative-ai/gemini-2.5-flash",
];
// helper function to get env variables across next / vite
// only needed so this example works in BlockNote demos and docs
export function getEnv(key: string) {
const env = (import.meta as any).env
? {
BLOCKNOTE_AI_SERVER_API_KEY: (import.meta as any).env
.VITE_BLOCKNOTE_AI_SERVER_API_KEY,
BLOCKNOTE_AI_SERVER_BASE_URL: (import.meta as any).env
.VITE_BLOCKNOTE_AI_SERVER_BASE_URL,
}
: {
BLOCKNOTE_AI_SERVER_API_KEY:
process.env.NEXT_PUBLIC_BLOCKNOTE_AI_SERVER_API_KEY,
BLOCKNOTE_AI_SERVER_BASE_URL:
process.env.NEXT_PUBLIC_BLOCKNOTE_AI_SERVER_BASE_URL,
};
const value = env[key as keyof typeof env];
return value;
}