---
title: "配置 AI 生成扩展"
description: "在编辑器中配置 AI 生成扩展，并了解与 AI 相关的所有可能选项。"
canonical_url: "https://tiptap.zhcndoc.com/content-ai/capabilities/generation/configure"
---

# 配置 AI 生成扩展

在编辑器中配置 AI 生成扩展，并了解与 AI 相关的所有可能选项。

Tiptap 的内容 AI 扩展接受不同的设置，用以配置扩展和命令的全局行为。

| Setting                 | Type                                                                                                                          | Default                                                                                       | Definition                                                                                                                                              |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `token`                 | `string`                                                                                                                      | `''`                                                                                          | 用于向 AI 服务验证该扩展身份的签名令牌。请使用 `aud: "AI"` 和 `AI:Generation` 权限对其进行签名。参见 [Authentication](https://tiptap.zhcndoc.com/authentication.md)。不能是你的 OpenAI API 密钥。 |
| `autocompletion`        | `boolean`                                                                                                                     | `false`                                                                                       | 启用自动补全功能。编写文本时，只需按 **Tab** 即可触发自动补全，再按一次 **Tab** 接受补全。我们会使用你已经写好的部分文本来为 OpenAI 构建提示词。                                                                   |
| `autocompletionOptions` | `object`                                                                                                                      | `{ trigger: 'Tab', accept: 'Tab', debounce: 0, inputLength: 4000, modelName: 'gpt-4o-mini' }` | 定义用于生成自动补全建议的触发方式和文本长度。如果未显式设置，accept 默认与 trigger 相同。trigger 按下后请求的延迟时间，单位为毫秒。你还可以选择用于执行自动补全任务的 OpenAI 模型。                                              |
| `onLoading`             | `(context: { editor: Editor, action: TextAction \| 'image', isStreaming: boolean }) => void`                                  | `undefined`                                                                                   | AI 开始生成响应时的回调。                                                                                                                                          |
| `onSuccess`             | `(context: { editor: Editor, action: TextAction \| 'image', isStreaming: boolean, response: string }) => void`                | `undefined`                                                                                   | AI 成功完成响应生成时的回调。                                                                                                                                        |
| `onChunk`               | `(context: { editor: Editor, action: TextAction \| 'image', isStreaming: boolean, response: string, chunk: string }) => void` | `undefined`                                                                                   | 响应生成出一个块时的回调。chunk 为新增的字符串部分响应，即截至目前已生成的响应（包含该 chunk）。                                                                                                  |
| `onError`               | `(error: Error, context: { editor: Editor, action: TextAction \| 'image', isStreaming: boolean}) => void`                     | `undefined`                                                                                   | 生成响应时发生错误的回调。                                                                                                                                           |
| `showDecorations`       | `boolean`                                                                                                                     | `true`                                                                                        | 如果为 `false`，则不会尝试在流式模式下为 AI 建议添加装饰。这会降低你对建议进行样式设置的能力，但可以修复与撤销历史相关的问题。                                                                                   |
