AI

Add "Ask AI" to your Fumapress app.

Installation

npm i @fumapress/ai

Add the plugin, it requires a model option, set this to an AI model you prefer (e.g. GPT).

npm i @ai-sdk/openai
press.config.tsx
import { defineConfig } from "fumapress";
import { openai } from "@ai-sdk/openai";
import { aiPlugin } from "@fumapress/ai";

export default defineConfig({
  // ...
})
  .plugins(
    aiPlugin({
      model: openai("gpt-5"),
    }),
  );

See AI SDK docs for all available models.

Finally, initialize the src/app.css file and add the following:

src/app.css
@import "tailwindcss";
@import "fumadocs-ui/css/neutral.css";
@import "fumadocs-ui/css/preset.css";
@import "fumapress/css/preset.css";
@import "@fumapress/ai/css/preset.css";

The plugin adds an "Ask AI" trigger to the docs, notebook, and glass layouts, backed by a /api/ai endpoint that searches your documentation to answer. The endpoint needs a server, so the plugin is not compatible with mode: "static".

Options

systemPrompt

Overrides the default system prompt, which instructs the model to search your docs and cite sources as links:

press.config.tsx
aiPlugin({
  model: openai("gpt-5"),
  systemPrompt:
    "You are the assistant for the Acme docs. Search the docs before answering, and keep answers short with source links.",
});

beforeRequest

Runs before each request to /api/ai, return a Response to reject it. Since the endpoint calls your model provider, add rate limiting or other validation before exposing it publicly:

press.config.tsx
aiPlugin({
  model: openai("gpt-5"),
  async beforeRequest(req) {
    if (await isRateLimited(req)) {
      return new Response("Too Many Requests", { status: 429 });
    }
  },
});

pageToIndex

Controls how pages are indexed for the model's search tool, return null to exclude a page. Same as the MCP plugin option.

configureUI

Whether to add the built-in chat UI to layouts, defaults to true. Set it to false to integrate the endpoint with your own UI.

Last updated on

On this page