syncfusion-react-ai-assistview

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Syncfusion React AI AssistView Component

Syncfusion React AI AssistView组件

Component Overview

组件概述

The Syncfusion React AI AssistView component is a comprehensive interactive chat component designed for building AI-powered conversational interfaces. It provides:
Syncfusion React AI AssistView组件是一款功能全面的交互式聊天组件,专为构建AI驱动的对话界面而设计。它提供以下能力:

Core Capabilities

核心功能

  • Prompt-Response Management: Manage conversation history with automatic data collection
  • Real-time Streaming: Stream AI responses character-by-character for live typing effects
  • Template System: Customize every UI element (banners, prompt items, responses, suggestions, footer)
  • Multi-View Support: Switch between conversation assist view and custom content views
  • Voice Integration: Built-in Speech-to-Text (voice input) and Text-to-Speech (voice output)
  • File Attachments: Upload and include files with prompts
  • Advanced Toolbars: Configurable toolbars for header, footer, responses, and prompts
  • AI Service Integration: Direct integration with OpenAI, Azure OpenAI, and other AI services
  • Event-Driven Architecture: Hooks for prompt submission, changes, and component lifecycle
  • 对话请求-响应管理:自动收集并管理对话历史
  • 实时流输出:逐字符流式输出AI响应,实现实时打字效果
  • 模板系统:自定义所有UI元素(横幅、请求项、响应内容、建议、页脚)
  • 多视图支持:在对话辅助视图与自定义内容视图之间切换
  • 语音集成:内置语音转文字(语音输入)和文字转语音(语音输出)功能
  • 文件附件:支持上传并在请求中附带文件
  • 高级工具栏:可配置头部、页脚、响应栏和请求栏四种工具栏
  • AI服务集成:直接对接OpenAI、Azure OpenAI及其他AI服务
  • 事件驱动架构:提供请求提交、内容变更和组件生命周期的钩子函数

Key Features

关键特性

  • Markdown Support: Render AI responses as formatted HTML via markdown parsing
  • Conversation History: Automatic tracking of all prompts and responses
  • Suggestion System: Display helpful prompt suggestions to guide users
  • Avatar Customization: Customize user and AI icons/avatars
  • Scroll Management: Auto-scroll or manual scroll-to-bottom button
  • Clear Functionality: Clear current prompt or entire conversation
  • Responsive Design: Works on desktop and mobile with responsive layouts
  • Markdown支持:通过Markdown解析将AI响应渲染为格式化HTML
  • 对话历史追踪:自动记录所有请求与响应内容
  • 建议系统:显示实用的请求建议,引导用户交互
  • 头像定制:自定义用户与AI的图标/头像
  • 滚动管理:支持自动滚动或手动滚动到底部按钮
  • 清空功能:支持清空当前请求或整个对话历史
  • 响应式设计:适配桌面与移动设备的响应式布局

Documentation and Navigation Guide

文档与导航指南

Getting Started

快速入门

📄 Read: references/getting-started.md
  • Install @syncfusion/ej2-react-interactive-chat package
  • Add CSS theme imports
  • Create basic component initialization
  • Render component to DOM
  • First working functional component example
📄 阅读文档references/getting-started.md
  • 安装@syncfusion/ej2-react-interactive-chat包
  • 引入CSS主题样式
  • 完成基础组件初始化
  • 将组件渲染到DOM中
  • 实现第一个可运行的功能组件示例

Configuration Essentials

配置要点

📄 Read: references/configuration-essentials.md
  • Set initial prompt text and placeholders
  • Configure prompt suggestions and suggestion headers
  • Customize user and AI avatar icons
  • Control clear button visibility
  • Enable/disable scroll-to-bottom functionality
  • Manage component instance via refs
  • Set component dimensions (height and width)
  • Apply custom CSS classes for styling
  • Control header visibility
  • Configure globalization (locale, RTL support)
  • Enable state persistence across sessions
📄 阅读文档references/configuration-essentials.md
  • 设置初始请求文本和占位符
  • 配置请求建议及建议头部
  • 自定义用户与AI的头像图标
  • 控制清空按钮的可见性
  • 启用/禁用滚动到底部功能
  • 通过refs管理组件实例
  • 设置组件尺寸(高度与宽度)
  • 应用自定义CSS类进行样式定制
  • 控制头部的可见性
  • 配置全球化支持(语言、RTL布局)
  • 启用会话间的状态持久化

Conversation Management

对话管理

📄 Read: references/conversation-management.md
  • Initialize with pre-configured conversation data
  • Add responses (string or object format)
  • Access and manage conversation history
  • Work with PromptModel data structure
  • Render markdown in responses
  • Persist and restore conversations
📄 阅读文档references/conversation-management.md
  • 使用预配置的对话数据初始化组件
  • 添加响应内容(字符串或对象格式)
  • 访问并管理对话历史
  • 运用PromptModel数据结构
  • 在响应中渲染Markdown内容
  • 持久化与恢复对话数据

Events and Interactions

事件与交互

📄 Read: references/events-and-interactions.md
  • Handle component lifecycle (created event)
  • Respond to prompt submissions (promptRequest event)
  • Track prompt text changes (promptChanged event)
  • Access detailed event arguments (PromptChangedEventArgs, PromptRequestEventArgs)
  • Cancel prompt submissions programmatically
  • Handle stop responding events for long operations
  • Modify suggestions and toolbar items dynamically
  • Implement event-driven workflows
  • Integrate with AI services via event handlers
📄 阅读文档references/events-and-interactions.md
  • 处理组件生命周期(created事件)
  • 响应请求提交(promptRequest事件)
  • 追踪请求文本变更(promptChanged事件)
  • 访问详细的事件参数(PromptChangedEventArgs、PromptRequestEventArgs)
  • 通过代码方式取消请求提交
  • 处理长操作的停止响应事件
  • 动态修改建议与工具栏项
  • 实现事件驱动的工作流
  • 通过事件处理器集成AI服务

Toolbar Customization

工具栏定制

📄 Read: references/toolbar-customization.md
  • Configure four toolbar types (header, footer, response, prompt)
  • Add custom toolbar items
  • Control toolbar positioning (Inline vs Bottom)
  • Customize toolbar icons
  • Handle item click events
  • Configure all ToolbarItemModel properties (align, cssClass, disabled, tabIndex, template, type, visible)
  • Create custom toolbar item templates
  • Control item visibility and enabled state dynamically
  • Set tab order for keyboard navigation
  • Manage attachment button behavior
📄 阅读文档references/toolbar-customization.md
  • 配置四种工具栏类型(头部、页脚、响应栏、请求栏)
  • 添加自定义工具栏项
  • 控制工具栏位置(内联式 vs 底部式)
  • 自定义工具栏图标
  • 处理项点击事件
  • 配置所有ToolbarItemModel属性(对齐方式、CSS类、禁用状态、Tab索引、模板、类型、可见性)
  • 创建自定义工具栏项模板
  • 动态控制项的可见性与启用状态
  • 设置键盘导航的Tab顺序
  • 管理附件按钮的行为

File Attachments

文件附件

📄 Read: references/file-attachments.md
  • Enable file attachment support
  • Configure upload endpoints (saveUrl, removeUrl)
  • Restrict file types (allowedFileType)
  • Set file size limits (maxFileSize)
  • Limit number of attachments (maximumCount)
  • Access attached files via attachedFiles array (FileInfo interface)
  • Handle attachment lifecycle events (beforeAttachmentUpload, attachmentUploadSuccess, attachmentUploadFailure, attachmentRemoved)
  • Validate files before upload
  • Initialize prompts with pre-attached files
  • Handle server-side file processing
📄 阅读文档references/file-attachments.md
  • 启用文件附件支持
  • 配置上传端点(saveUrl、removeUrl)
  • 限制文件类型(allowedFileType)
  • 设置文件大小限制(maxFileSize)
  • 限制附件数量(maximumCount)
  • 通过attachedFiles数组访问附件(FileInfo接口)
  • 处理附件生命周期事件(beforeAttachmentUpload、attachmentUploadSuccess、attachmentUploadFailure、attachmentRemoved)
  • 在上传前验证文件
  • 初始化时附带预上传的文件
  • 处理服务端文件逻辑

Custom Views

自定义视图

📄 Read: references/custom-views.md
  • Create multiple views (Assist and Custom types)
  • Set view names and icons
  • Define view-specific templates
  • Configure activeView property to set initial view
  • Switch between views programmatically
  • Persist active view across sessions
  • Conditionally set initial view based on user role or state
  • Display side-by-side content panels
  • Use cases for multi-view layouts
📄 阅读文档references/custom-views.md
  • 创建多种视图类型(辅助视图与自定义视图)
  • 设置视图名称与图标
  • 定义视图专属模板
  • 配置activeView属性设置初始视图
  • 通过代码方式切换视图
  • 在会话间持久化活跃视图
  • 根据用户角色或状态条件设置初始视图
  • 显示并排内容面板
  • 多视图布局的使用场景

Templating System

模板系统

📄 Read: references/templating-system.md
  • Customize banner templates (welcome content)
  • Create prompt item templates (user message display)
  • Design response item templates (AI response display)
  • Build suggestion item templates
  • Create custom footer templates
  • Access template context data
📄 阅读文档references/templating-system.md
  • 自定义横幅模板(欢迎内容)
  • 创建请求项模板(用户消息展示)
  • 设计响应项模板(AI响应展示)
  • 构建建议项模板
  • 创建自定义页脚模板
  • 访问模板上下文数据

AI Service Integration

AI服务集成

📄 Read: references/ai-integration-setup.md
  • Integrate with Azure OpenAI, OpenAI, Gemini, Claude
  • Configure API credentials and authentication
  • Handle real-time prompt processing
  • Stream responses for live typing effects
  • Parse markdown responses with marked library
  • Error handling and rate limiting
  • Security considerations for API keys
📄 阅读文档references/ai-integration-setup.md
  • 集成Azure OpenAI、OpenAI、Gemini、Claude等服务
  • 配置API凭证与认证方式
  • 处理实时请求逻辑
  • 流式输出响应以实现实时打字效果
  • 使用marked库解析Markdown响应
  • 错误处理与速率限制
  • API密钥的安全注意事项

Speech Capabilities

语音功能

📄 Read: references/speech-capabilities.md
  • Enable Speech-to-Text (voice input)
  • Configure speech recognition language
  • Handle interim transcripts while speaking
  • Implement Text-to-Speech (voice output)
  • Customize button labels and icons
  • Handle speech events (start, stop, transcript, error)
  • Browser compatibility notes
📄 阅读文档references/speech-capabilities.md
  • 启用语音转文字(语音输入)功能
  • 配置语音识别语言
  • 处理语音输入过程中的临时转录内容
  • 实现文字转语音(语音输出)功能
  • 自定义按钮标签与图标
  • 处理语音事件(开始、停止、转录、错误)
  • 浏览器兼容性说明

Methods and APIs

方法与API

📄 Read: references/methods-and-apis.md
  • Use addPromptResponse() method
  • Execute prompts dynamically with executePrompt()
  • Scroll to bottom programmatically
  • Access component instance via refs
  • Manage component state
  • Common patterns and gotchas

📄 阅读文档references/methods-and-apis.md
  • 使用addPromptResponse()方法
  • 通过executePrompt()动态执行请求
  • 通过代码方式滚动到底部
  • 通过refs访问组件实例
  • 管理组件状态
  • 常见模式与注意事项

Quick Start Example

快速入门示例

tsx
import { AIAssistViewComponent, PromptRequestEventArgs } from '@syncfusion/ej2-react-interactive-chat';
import * as React from 'react';
import * as ReactDOM from "react-dom";

function App() {
    const assistInstance = React.useRef<AIAssistViewComponent>(null);
    
    const onPromptRequest = (args: PromptRequestEventArgs) => {
        setTimeout(() => {
            let defaultResponse = 'For real-time AI processing, connect to your preferred service (OpenAI, Azure OpenAI, etc.).';
            assistInstance.current.addPromptResponse(defaultResponse);
        }, 1000);
    };
  
    return (
        <AIAssistViewComponent 
            id="aiAssistView" 
            ref={assistInstance} 
            promptRequest={onPromptRequest}
            prompt={'Welcome! How can I help?'}
            promptSuggestions={['Ask about features', 'Get started guide']}
        />
    );
}

ReactDOM.render(<App />, document.getElementById('container'));

tsx
import { AIAssistViewComponent, PromptRequestEventArgs } from '@syncfusion/ej2-react-interactive-chat';
import * as React from 'react';
import * as ReactDOM from "react-dom";

function App() {
    const assistInstance = React.useRef<AIAssistViewComponent>(null);
    
    const onPromptRequest = (args: PromptRequestEventArgs) => {
        setTimeout(() => {
            let defaultResponse = 'For real-time AI processing, connect to your preferred service (OpenAI, Azure OpenAI, etc.).';
            assistInstance.current.addPromptResponse(defaultResponse);
        }, 1000);
    };
  
    return (
        <AIAssistViewComponent 
            id="aiAssistView" 
            ref={assistInstance} 
            promptRequest={onPromptRequest}
            prompt={'Welcome! How can I help?'}
            promptSuggestions={['Ask about features', 'Get started guide']}
        />
    );
}

ReactDOM.render(<App />, document.getElementById('container'));

Common Patterns

常见模式

Pattern 1: Basic Chat with Suggestions

模式1:带建议的基础聊天

Create a simple conversational interface with predefined suggestions:
  • Enable prompt suggestions to guide user interactions
  • Handle promptRequest event with simple responses
  • Display conversation history automatically
创建带有预定义建议的简单对话界面:
  • 启用请求建议以引导用户交互
  • 通过promptRequest事件处理简单响应
  • 自动显示对话历史

Pattern 2: AI Service Integration

模式2:AI服务集成

Connect to real AI services for intelligent responses:
  • Use promptRequest event to capture user input
  • Call AI API with prompt text
  • Stream response character-by-character for live effect
  • Parse markdown responses for formatted output
对接真实AI服务以获取智能响应:
  • 使用promptRequest事件捕获用户输入
  • 将请求文本调用AI API
  • 逐字符流式输出响应以实现实时效果
  • 解析Markdown响应以展示格式化内容

Pattern 3: Multi-View Dashboard

模式3:多视图仪表板

Combine chat with supporting content:
  • Create Assist view for conversation
  • Add Custom view for settings/sidebar
  • Switch activeView based on user interaction
  • Share data between views
将聊天功能与辅助内容结合:
  • 创建对话用的辅助视图
  • 添加用于设置/侧边栏的自定义视图
  • 根据用户交互切换activeView
  • 在视图间共享数据

Pattern 4: Voice-Enabled Chat

模式4:语音支持的聊天

Enable hands-free interaction with speech:
  • Enable speechToTextSettings to capture voice
  • Configure Text-to-Speech for response audio
  • Use toolbar for voice control buttons
  • Handle speech events for status feedback
启用免提语音交互:
  • 启用speechToTextSettings以捕获语音
  • 配置文字转语音的工具栏按钮
  • 使用工具栏进行语音控制
  • 处理语音事件以提供状态反馈

Pattern 5: File-Attached Prompts

模式5:带文件附件的请求

Support file uploads with prompts:
  • Enable attachments with enableAttachments property
  • Configure attachment endpoints and file restrictions
  • Include file data in prompt context
  • Send files to backend API

支持在请求中附带文件:
  • 启用附件功能
  • 配置附件端点与文件限制
  • 将文件与请求一起发送到后端
  • 在对话中展示文件信息

Key Props & Configuration

关键属性与配置

Essential Props

核心属性

  • promptRequest
    : Event handler when user submits prompt
  • prompt
    : Initial/default text in prompt input
  • promptPlaceholder
    : Placeholder text for input area
  • promptSuggestions
    : Array of suggested prompts
  • prompts
    : Pre-configured conversation data
  • promptRequest
    :用户提交请求时的事件处理器
  • prompt
    :请求输入框的初始/默认文本
  • promptPlaceholder
    :请求输入框的占位符文本
  • promptSuggestions
    :预定义的请求建议数组
  • prompts
    :预配置的对话数据

Customization Props

定制属性

  • promptIconCss
    : CSS class for user avatar
  • responseIconCss
    : CSS class for AI avatar
  • showClearButton
    : Show/hide clear button (default: false)
  • showHeader
    : Show/hide component header (default: true)
  • enableScrollToBottom
    : Show scroll-to-bottom button (default: true)
  • height
    : Component height (string | number, default: '100%')
  • width
    : Component width (string | number, default: '100%')
  • cssClass
    : Custom CSS classes for styling
  • activeView
    : Currently displayed view index (number, default: 0)
  • promptIconCss
    :用户头像的CSS类
  • responseIconCss
    :AI头像的CSS类
  • showClearButton
    :显示/隐藏清空按钮(默认:false)
  • showHeader
    :显示/隐藏组件头部(默认:true)
  • enableScrollToBottom
    :显示滚动到底部按钮(默认:true)
  • height
    :组件高度(字符串 | 数字,默认:'100%')
  • width
    :组件宽度(字符串 | 数字,默认:'100%')
  • cssClass
    :用于样式定制的自定义CSS类
  • activeView
    :当前显示的视图索引(数字,默认:0)

Template Props

模板属性

  • bannerTemplate
    : Welcome banner content
  • promptItemTemplate
    : User message display
  • responseItemTemplate
    : AI response display
  • promptSuggestionItemTemplate
    : Suggestion styling
  • footerTemplate
    : Custom prompt input area
  • bannerTemplate
    :欢迎横幅内容模板
  • promptItemTemplate
    :用户消息展示模板
  • responseItemTemplate
    :AI响应展示模板
  • promptSuggestionItemTemplate
    :建议项样式模板
  • footerTemplate
    :自定义请求输入区域模板

Advanced Props

高级属性

  • enableAttachments
    : Enable file uploads (default: false)
  • attachmentSettings
    : File upload configuration
  • speechToTextSettings
    : Voice input configuration
  • toolbarSettings
    : Header toolbar configuration
  • footerToolbarSettings
    : Footer toolbar configuration
  • responseToolbarSettings
    : Response action toolbar
  • promptToolbarSettings
    : Prompt toolbar configuration
  • locale
    : Localization/globalization setting (default: 'en-US')
  • enableRtl
    : Enable right-to-left rendering (default: false)
  • enablePersistence
    : Enable state persistence (default: false)
  • enableAttachments
    :启用文件上传功能(默认:false)
  • attachmentSettings
    :文件上传配置
  • speechToTextSettings
    :语音输入配置
  • toolbarSettings
    :头部工具栏配置
  • footerToolbarSettings
    :页脚工具栏配置
  • responseToolbarSettings
    :响应操作工具栏配置
  • promptToolbarSettings
    :请求工具栏配置
  • locale
    :本地化/全球化设置(默认:'en-US')
  • enableRtl
    :启用从右到左的渲染布局(默认:false)
  • enablePersistence
    :启用状态持久化(默认:false)

Event Props

事件属性

  • created
    : Component lifecycle event
  • promptRequest
    : Prompt submission event
  • promptChanged
    : Prompt text change event
  • stopRespondingClick
    : Stop button click event
  • beforeAttachmentUpload
    : Before file upload event
  • attachmentUploadSuccess
    : File upload success event
  • attachmentUploadFailure
    : File upload failure event
  • attachmentRemoved
    : File removal event

  • created
    :组件生命周期事件
  • promptRequest
    :请求提交事件
  • promptChanged
    :请求文本变更事件
  • stopRespondingClick
    :停止按钮点击事件
  • beforeAttachmentUpload
    :文件上传前事件
  • attachmentUploadSuccess
    :文件上传成功事件
  • attachmentUploadFailure
    :文件上传失败事件
  • attachmentRemoved
    :文件移除事件

Common Use Cases

常见使用场景

Chat Bot with AI Integration

集成AI的聊天机器人

Build a customer service chatbot connected to OpenAI or Azure services:
  1. Set up component with suggestions
  2. Handle promptRequest to send to AI API
  3. Stream responses for real-time feedback
  4. Use templates for branded appearance
构建对接OpenAI或Azure服务的客服聊天机器人:
  1. 配置组件并添加建议内容
  2. 通过promptRequest事件将请求发送到AI API
  3. 流式输出响应以提供实时反馈
  4. 使用模板实现品牌化外观

Voice-Enabled Assistant

语音支持的助手

Create hands-free voice interaction:
  1. Enable speechToTextSettings
  2. Configure Text-to-Speech toolbar button
  3. Handle speech events for status
  4. Provide visual feedback during voice capture
创建免提语音交互功能:
  1. 启用speechToTextSettings
  2. 配置文字转语音的工具栏按钮
  3. 处理语音事件以展示状态
  4. 在语音捕获过程中提供视觉反馈

File Analysis Chat

文件分析聊天

Allow users to upload and discuss files:
  1. Enable attachments
  2. Configure file restrictions (type, size, count)
  3. Send files with prompts to backend
  4. Display file information in conversation
允许用户上传并讨论文件:
  1. 启用附件功能
  2. 配置文件限制(类型、大小、数量)
  3. 将文件与请求一起发送到后端
  4. 在对话中展示文件信息

Multi-Feature Dashboard

多功能仪表板

Combine chat with settings and content:
  1. Create multiple views (Assist + Custom)
  2. Use templates for custom view content
  3. Implement view switching logic
  4. Share conversation state between views

将聊天功能与设置、内容结合:
  1. 创建多种视图(辅助视图 + 自定义视图)
  2. 使用模板定义自定义视图内容
  3. 实现视图切换逻辑
  4. 在视图间共享对话状态