配置 AI 生成扩展
Tiptap 的内容 AI 扩展接受不同的设置,用以配置扩展和命令的全局行为。
| 设置 | 类型 | 默认值 | 定义 |
|---|---|---|---|
appId | string | '' | 你的应用程序 ID,可通过访问 Tiptap Cloud 的 AI 设置获得 |
token | string | '' | 为了验证我们的 AI 后端服务,你需要使用你的 JWT 密钥生成一个 JWT(采用 HS256),该密钥也可在你的团队 AI 设置页面中获取 AI 设置页面 |
autocompletion | boolean | false | 启用自动补全功能。编写文本时,按 Tab 触发自动补全,再按一次 Tab 接受补全内容。我们会使用你已写文本的一部分来生成为 OpenAI 生成提示语。 |
autocompletionOptions | object | { trigger: 'Tab', accept: 'Tab', debounce: 0, inputLength: 4000, modelName: 'gpt-3.5-turbo' } | 定义触发自动补全的按键和用于生成建议文本的文本长度。若未显式设置,accept 默认为 trigger。debounce 是触发按键后的请求去抖时间(毫秒)。你也可以选择用于自动补全的 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 是新增的字符串部分,response 是至目前为止生成的完整响应(包含 chunk)。 |
onError | (error: Error, context: { editor: Editor, action: TextAction | 'image', isStreaming: boolean}) => void | undefined | 当生成响应时发生错误的回调。 |
showDecorations | boolean | true | 若为 false,则不会在流式模式下装饰 AI 建议。这会减少你对建议样式的控制,但可以解决撤销历史的一些问题。 |