syncfusion-react-inline-ai-assist
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSyncfusion React Syncfusion React Inline AI Assist Component
Syncfusion React Inline AI Assist组件
Component Overview
组件概述
The Inline AI Assist component provides intelligent text processing capabilities for your React applications. It enables AI-powered suggestions, content generation, and interactive prompt-response workflows with support for multiple AI service integrations.
Inline AI Assist组件为你的React应用提供智能文本处理能力。它支持多AI服务集成,可实现AI驱动的建议、内容生成以及交互式提示-响应工作流。
Key Capabilities
核心功能
- Multi-AI Service Integration: Connect to OpenAI, Google Gemini, Lite-LLM, and Ollama for flexible AI backend options
- Real-Time Response Streaming: Enable for progressive response updates during content generation
enableStreaming - Command & Response Actions: Configure predefined commands for quick AI tasks and custom response actions
- Inline Toolbar: Add custom toolbar items with icons, buttons, and separators for enhanced user interactions
- Inline & Popup Modes: Display AI responses inline with existing content or in a floating popup window
- Flexible Template Customization: Customize prompt input and response display using string, function, or JSX templates
- Internationalization (i18n) & RTL: Support for multiple languages and right-to-left text direction
- Event Handling: Lifecycle events including ,
created,promptRequest, andopenfor precise controlclose - Public Methods: Programmatic access with ,
addResponse(),executePrompt(), and moreshowPopup() - Prompt History: Track prompt-response conversations with persistent history management
- Accessibility & Theming: Compatible with Material, Bootstrap, Fluent, and Tailwind CSS themes
- 多AI服务集成:连接OpenAI、Google Gemini、Lite-LLM和Ollama,灵活选择AI后端
- 实时响应流:启用可在内容生成过程中逐步更新响应
enableStreaming - 命令与响应操作:配置预定义命令以快速完成AI任务,支持自定义响应操作
- 嵌入式工具栏:添加带有图标、按钮和分隔符的自定义工具栏项,增强用户交互
- 嵌入式与弹窗模式:AI响应可与现有内容内联显示,或在浮动弹窗中展示
- 灵活的模板自定义:使用字符串、函数或JSX模板自定义提示输入和响应显示
- 国际化(i18n)与RTL支持:支持多语言和从右到左的文本方向
- 事件处理:提供、
created、promptRequest和open等生命周期事件,实现精准控制close - 公共方法:通过、
addResponse()、executePrompt()等方法实现程序化访问showPopup() - 提示历史:通过持久化历史管理跟踪提示-响应对话
- 无障碍与主题支持:兼容Material、Bootstrap、Fluent和Tailwind CSS主题
Documentation and Navigation Guide
文档与导航指南
Getting Started
快速入门
📄 Read: references/getting-started.md
- Installation via npm
- CSS theme imports (Material, Bootstrap, Fluent, Tailwind)
- Component rendering
- Custom styling with property
cssClass - Running your first example
📄 阅读: references/getting-started.md
- 通过npm安装
- CSS主题导入(Material、Bootstrap、Fluent、Tailwind)
- 组件渲染
- 使用属性自定义样式
cssClass - 运行你的第一个示例
Template Customization
模板自定义
📄 Read: references/template-customization.md
- property: Customize prompt input area
editorTemplate - property: Customize response display
responseTemplate - String templates, function templates, JSX.Element templates
- Rich text editor integration
- Voice input integration
- Code syntax highlighting
- Markdown rendering
📄 阅读: references/template-customization.md
- 属性:自定义提示输入区域
editorTemplate - 属性:自定义响应显示
responseTemplate - 字符串模板、函数模板、JSX.Element模板
- 富文本编辑器集成
- 语音输入集成
- 代码语法高亮
- Markdown渲染
Internationalization (i18n) and RTL
国际化(i18n)与RTL支持
📄 Read: references/internationalization.md
- property: Set language and regional formatting
locale - property: Enable right-to-left text direction
enableRtl - Available locale codes and setup
- Arabic, Hebrew, Persian support
- Multi-language applications
- Browser language detection
- Custom localization strings
📄 阅读: references/internationalization.md
- 属性:设置语言和区域格式
locale - 属性:启用从右到左的文本方向
enableRtl - 可用的区域代码及设置
- 阿拉伯语、希伯来语、波斯语支持
- 多语言应用
- 浏览器语言检测
- 自定义本地化字符串
Positioning and Targeting
定位与目标设置
📄 Read: references/positioning-and-targeting.md
- property: Position relative to DOM elements
relateTo - property: Specify where to append the component
target - property: Inline vs Popup display modes
responseMode - Practical positioning scenarios
📄 阅读: references/positioning-and-targeting.md
- 属性:相对于DOM元素定位
relateTo - 属性:指定组件的挂载目标
target - 属性:嵌入式 vs 弹窗显示模式
responseMode - 实用定位场景
Command Settings
命令设置
📄 Read: references/command-settings.md
- Configure command items for quick actions
- Command properties: id, label, iconCss, disabled, prompt, tooltip
- Group commands with property
groupBy - Handle events
itemSelect - Set popup dimensions
📄 阅读: references/command-settings.md
- 配置命令项以实现快速操作
- 命令属性:id、label、iconCss、disabled、prompt、tooltip
- 使用属性对命令分组
groupBy - 处理事件
itemSelect - 设置弹窗尺寸
Response Settings
响应设置
📄 Read: references/response-settings.md
- Built-in response items (accept, reject)
- Adding custom response actions
- Response item properties and configuration
- Group response items with
groupBy - Handle response events
itemSelect
📄 阅读: references/response-settings.md
- 内置响应项(接受、拒绝)
- 添加自定义响应操作
- 响应项属性与配置
- 使用对响应项分组
groupBy - 处理响应事件
itemSelect
Inline Toolbar Customization
嵌入式工具栏自定义
📄 Read: references/inline-toolbar.md
- Configure toolbar items (buttons, separators, inputs)
- Built-in items and custom items
- Item properties: text, iconCss, type, visible, disabled, align
- Tab key navigation with
tabIndex - Custom item templates
- Toolbar positioning: Inline vs Bottom
- event handling with complete event args
itemClick
📄 阅读: references/inline-toolbar.md
- 配置工具栏项(按钮、分隔符、输入框)
- 内置项与自定义项
- 项属性:text、iconCss、type、visible、disabled、align
- 使用实现Tab键导航
tabIndex - 自定义项模板
- 工具栏定位:嵌入式 vs 底部
- 带有完整事件参数的事件处理
itemClick
Events
事件
📄 Read: references/events.md
- event: Component render complete
created - event: Prompt submitted by user
promptRequest - event: Popup opened
open - event: Popup closed
close - Event handler patterns and examples
📄 阅读: references/events.md
- 事件:组件渲染完成
created - 事件:用户提交提示
promptRequest - 事件:弹窗打开
open - 事件:弹窗关闭
close - 事件处理模式与示例
Methods
方法
📄 Read: references/methods.md
- : Add AI response to component
addResponse(response) - : Execute prompt dynamically
executePrompt(prompt) - : Open the popup
showPopup(coordinates) - : Close the popup
hidePopup() - : Show command actions
showCommandPopup() - : Hide command actions
hideCommandPopup()
📄 阅读: references/methods.md
- :向组件添加AI响应
addResponse(response) - :动态执行提示
executePrompt(prompt) - :打开弹窗
showPopup(coordinates) - :关闭弹窗
hidePopup() - :显示命令操作
showCommandPopup() - :隐藏命令操作
hideCommandPopup()
AI Service Integrations
AI服务集成
📄 Read: references/ai-integrations.md
- property: Real-time response streaming
enableStreaming - OpenAI API integration with streaming
- Google Gemini AI integration with streaming
- Lite-LLM service integration
- Ollama local LLM integration with streaming
- API credential setup
- Prompt handling and response streaming
- Performance optimization and error handling
📄 阅读: references/ai-integrations.md
- 属性:实时响应流
enableStreaming - 带流功能的OpenAI API集成
- 带流功能的Google Gemini AI集成
- Lite-LLM服务集成
- 带流功能的Ollama本地LLM集成
- API凭证设置
- 提示处理与响应流
- 性能优化与错误处理
Quick Start
快速开始
jsx
import { InlineAIAssistComponent } from '@syncfusion/ej2-react-interactive-chat';
import React from 'react';
function App() {
const assistRef = React.useRef(null);
const handlePromptRequest = () => {
// Simulate AI response
setTimeout(() => {
const response = 'Your AI-generated response here';
assistRef.current?.addResponse(response);
}, 1000);
};
const handleShowPopup = () => {
assistRef.current?.showPopup();
};
return (
<div>
<button onClick={handleShowPopup} className="e-btn e-primary">
Ask AI
</button>
<InlineAIAssistComponent
id="inlineAssist"
ref={assistRef}
relateTo="button"
promptRequest={handlePromptRequest}
popupWidth="500px"
/>
</div>
);
}
export default App;jsx
import { InlineAIAssistComponent } from '@syncfusion/ej2-react-interactive-chat';
import React from 'react';
function App() {
const assistRef = React.useRef(null);
const handlePromptRequest = () => {
// Simulate AI response
setTimeout(() => {
const response = 'Your AI-generated response here';
assistRef.current?.addResponse(response);
}, 1000);
};
const handleShowPopup = () => {
assistRef.current?.showPopup();
};
return (
<div>
<button onClick={handleShowPopup} className="e-btn e-primary">
Ask AI
</button>
<InlineAIAssistComponent
id="inlineAssist"
ref={assistRef}
relateTo="button"
promptRequest={handlePromptRequest}
popupWidth="500px"
/>
</div>
);
}
export default App;Common Patterns
常见模式
Pattern 1: AI-Assisted Text Editing
模式1:AI辅助文本编辑
Combine the component with a contentEditable div to enable AI-powered suggestions while editing:
jsx
const handleResponseItemSelect = (args) => {
if (args.command.label === 'Accept') {
const lastResponse = assistRef.current.prompts?.[assistRef.current.prompts.length - 1]?.response;
if (lastResponse && editableRef.current) {
editableRef.current.innerHTML = lastResponse;
}
}
};
<InlineAIAssistComponent
responseSettings={{
itemSelect: handleResponseItemSelect
}}
/>将组件与contentEditable div结合,实现AI驱动的编辑建议:
jsx
const handleResponseItemSelect = (args) => {
if (args.command.label === 'Accept') {
const lastResponse = assistRef.current.prompts?.[assistRef.current.prompts.length - 1]?.response;
if (lastResponse && editableRef.current) {
editableRef.current.innerHTML = lastResponse;
}
}
};
<InlineAIAssistComponent
responseSettings={{
itemSelect: handleResponseItemSelect
}}
/>Pattern 2: Command-Based Actions
模式2:基于命令的操作
Set up predefined commands for common AI tasks:
jsx
const commandSettings = {
commands: [
{ id: 'summarize', label: 'Summarize', iconCss: 'e-icons e-compress', prompt: 'Summarize this text' },
{ id: 'expand', label: 'Expand', iconCss: 'e-icons e-expand', prompt: 'Expand this text' },
{ id: 'fix', label: 'Fix Grammar', iconCss: 'e-icons e-check-box', prompt: 'Fix grammar and spelling' }
]
};
<InlineAIAssistComponent commandSettings={commandSettings} />为常见AI任务设置预定义命令:
jsx
const commandSettings = {
commands: [
{ id: 'summarize', label: 'Summarize', iconCss: 'e-icons e-compress', prompt: 'Summarize this text' },
{ id: 'expand', label: 'Expand', iconCss: 'e-icons e-expand', prompt: 'Expand this text' },
{ id: 'fix', label: 'Fix Grammar', iconCss: 'e-icons e-check-box', prompt: 'Fix grammar and spelling' }
]
};
<InlineAIAssistComponent commandSettings={commandSettings} />Pattern 3: Custom Toolbar Actions
模式3:自定义工具栏操作
Add custom toolbar items to trigger component methods:
jsx
const handleToolbarItemClick = (args) => {
if (args.item.id === 'customAction') {
assistRef.current?.executePrompt('User-defined prompt');
}
};
const inlineToolbarSettings = {
items: [
{ id: 'customAction', text: 'Custom', iconCss: 'e-icons e-settings' }
],
itemClick: handleToolbarItemClick
};添加自定义工具栏项以触发组件方法:
jsx
const handleToolbarItemClick = (args) => {
if (args.item.id === 'customAction') {
assistRef.current?.executePrompt('User-defined prompt');
}
};
const inlineToolbarSettings = {
items: [
{ id: 'customAction', text: 'Custom', iconCss: 'e-icons e-settings' }
],
itemClick: handleToolbarItemClick
};Pattern 4: Response Display Modes
模式4:响应显示模式
Switch between inline editing and popup responses:
jsx
// Inline mode: Response appears inline
<InlineAIAssistComponent responseMode="Inline" />
// Popup mode: Response in floating popup
<InlineAIAssistComponent responseMode="Popup" popupWidth="400px" />在嵌入式编辑与弹窗响应之间切换:
jsx
// 嵌入式模式:响应内联显示
<InlineAIAssistComponent responseMode="Inline" />
// 弹窗模式:响应在浮动弹窗中显示
<InlineAIAssistComponent responseMode="Popup" popupWidth="400px" />Pattern 5: Lifecycle Management
模式5:生命周期管理
Use events to coordinate component state:
jsx
const handleCreated = () => {
console.log('Component initialized');
};
const handlePromptRequest = (args) => {
console.log('Prompt submitted:', args.prompt);
};
<InlineAIAssistComponent
created={handleCreated}
promptRequest={handlePromptRequest}
open={() => console.log('Popup opened')}
close={() => console.log('Popup closed')}
/>使用事件协调组件状态:
jsx
const handleCreated = () => {
console.log('Component initialized');
};
const handlePromptRequest = (args) => {
console.log('Prompt submitted:', args.prompt);
};
<InlineAIAssistComponent
created={handleCreated}
promptRequest={handlePromptRequest}
open={() => console.log('Popup opened')}
close={() => console.log('Popup closed')}
/>Key Configuration Properties
关键配置属性
| Property | Type | Default | Purpose |
|---|---|---|---|
| string | function | JSX.Element | '' | Custom prompt input template |
| string | function | JSX.Element | '' | Custom response display template |
| boolean | false | Enable real-time response streaming |
| string | 'en-US' | Language and regional formatting |
| boolean | false | Enable right-to-left text direction |
| boolean | false | Persist component state across reloads |
| string | '' | Custom CSS classes for styling |
| string | HTMLElement | - | Position component relative to element |
| string | HTMLElement | 'body' | Specify append target |
| string | 'Popup' | 'Inline' or 'Popup' |
| string | number | '400px' | Popup width (CSS value) |
| string | number | 'auto' | Popup height |
| number | 1000 | Popup z-index |
| string | 'Ask or generate AI content..' | Prompt textarea placeholder |
| string | '' | Default prompt text |
| array | [] | Prompt-response collection |
| CommandSettingsModel | null | Command configuration |
| ResponseSettingsModel | null | Response action configuration |
| InlineToolbarSettingsModel | null | Toolbar customization |
For complete examples and advanced scenarios, explore individual reference files above.
| 属性 | 类型 | 默认值 | 用途 |
|---|---|---|---|
| string | function | JSX.Element | '' | 自定义提示输入模板 |
| string | function | JSX.Element | '' | 自定义响应显示模板 |
| boolean | false | 启用实时响应流 |
| string | 'en-US' | 语言与区域格式 |
| boolean | false | 启用从右到左的文本方向 |
| boolean | false | 在页面重载时持久化组件状态 |
| string | '' | 用于样式自定义的CSS类 |
| string | HTMLElement | - | 相对于指定元素定位组件 |
| string | HTMLElement | 'body' | 指定组件挂载目标 |
| string | 'Popup' | 可选值:'Inline'或'Popup' |
| string | number | '400px' | 弹窗宽度(CSS值) |
| string | number | 'auto' | 弹窗高度 |
| number | 1000 | 弹窗层级 |
| string | 'Ask or generate AI content..' | 提示文本框占位符 |
| string | '' | 默认提示文本 |
| array | [] | 提示-响应集合 |
| CommandSettingsModel | null | 命令配置 |
| ResponseSettingsModel | null | 响应操作配置 |
| InlineToolbarSettingsModel | null | 工具栏自定义配置 |
如需完整示例和高级场景,请探索上述各参考文档。