syncfusion-angular-inline-ai-assist

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Syncfusion Angular Inline AI Assist Component

Syncfusion Angular Inline AI Assist组件

Component Overview

组件概述

The Inline AI Assist component provides intelligent text processing capabilities that enhance user productivity. It leverages advanced natural language processing to enable AI-powered text suggestions, content generation, and editing features directly within Angular applications.
Key Capabilities:
  • Response Modes - Popup (floating) or Inline (in-place) response display with configurable dimensions
  • Command System - Predefined AI operations with icons, grouping, and custom command items
  • Response Actions - Custom response toolbar items for accept/reject workflows
  • Template System - Flexible editor and response templates for custom layouts
  • Events & Interactions - Comprehensive events for lifecycle (created, open, close) and user interactions
  • Toolbar Configuration - Inline toolbar with custom items, positioning, and alignment
  • Methods - Programmatically add prompts, update responses, open/close popups, and control behavior
  • Globalization - Multi-language support with RTL capabilities and locale-based formatting
  • Customizable UI - CSS classes, z-index control, popup dimensions, and theme integration
Inline AI Assist组件提供智能文本处理能力,可提升用户工作效率。它利用先进的自然语言处理技术,在Angular应用中直接实现AI驱动的文本建议、内容生成与编辑功能。
核心功能:
  • 响应模式 - 弹出式(悬浮)或内嵌式(原位)响应显示,支持配置尺寸
  • 命令系统 - 带有图标、分组功能的预定义AI操作,以及自定义命令项
  • 响应操作 - 用于接受/拒绝工作流的自定义响应工具栏项
  • 模板系统 - 灵活的编辑器与响应模板,支持自定义布局
  • 事件与交互 - 覆盖生命周期(创建、打开、关闭)与用户交互的全面事件
  • 工具栏配置 - 带有自定义项、定位与对齐设置的内嵌工具栏
  • 方法 - 以编程方式添加提示、更新响应、打开/关闭弹窗并控制行为
  • 全球化 - 多语言支持,包含RTL能力与基于区域设置的格式化
  • 可自定义UI - CSS类、z-index控制、弹窗尺寸与主题集成

Documentation and Navigation Guide

文档与导航指南

Getting Started

快速开始

📄 Read: references/getting-started.md
  • Installation and package setup
  • Angular environment configuration
  • Basic component implementation
  • CSS imports and theme setup
  • Initial configuration with relateTo and target properties
📄 阅读: references/getting-started.md
  • 安装与包设置
  • Angular环境配置
  • 基础组件实现
  • CSS导入与主题设置
  • 使用relateTo和target属性进行初始配置

Core Configuration

核心配置

📄 Read: references/core-configuration.md
  • Prompt text and placeholder configuration
  • Prompt/response collection management
  • Response display modes (Popup vs Inline)
  • Popup dimensions (width, height, z-index)
  • CSS customization and styling
📄 阅读: references/core-configuration.md
  • 提示文本与占位符配置
  • 提示/响应集合管理
  • 响应显示模式(弹出式 vs 内嵌式)
  • 弹窗尺寸(宽度、高度、z-index)
  • CSS自定义与样式设置

Commands and Responses

命令与响应

📄 Read: references/commands-and-responses.md
  • Command settings and command items
  • Adding preset AI operations with grouping
  • Response settings and response items
  • Built-in accept/reject actions
  • Custom response toolbar items and event handling
📄 阅读: references/commands-and-responses.md
  • 命令设置与命令项
  • 添加带分组功能的预设AI操作
  • 响应设置与响应项
  • 内置接受/拒绝操作
  • 自定义响应工具栏项与事件处理

Templates and Toolbars

模板与工具栏

📄 Read: references/templates-and-toolbars.md
  • Editor template customization
  • Response template layout
  • Inline toolbar configuration and items
  • Toolbar positioning, alignment, and styling
  • Tab key navigation in toolbars
📄 阅读: references/templates-and-toolbars.md
  • 编辑器模板自定义
  • 响应模板布局
  • 内嵌工具栏配置与项设置
  • 工具栏定位、对齐与样式
  • 工具栏中的Tab键导航

Events and Methods

事件与方法

📄 Read: references/events-and-methods.md
  • Lifecycle events (created, open, close)
  • Prompt request event handling
  • Component methods (addResponse, executePrompt, showPopup, hidePopup)
  • Event arguments and callback patterns
📄 阅读: references/events-and-methods.md
  • 生命周期事件(创建、打开、关闭)
  • 提示请求事件处理
  • 组件方法(addResponse、executePrompt、showPopup、hidePopup)
  • 事件参数与回调模式

Localization and Styling

本地化与样式

📄 Read: references/localization-and-styling.md
  • Localization and multi-language support
  • Right-to-left (RTL) text direction
  • Custom CSS class styling
  • Theme integration
  • Text content customization
📄 阅读: references/localization-and-styling.md
  • 本地化与多语言支持
  • 从右到左(RTL)文本方向
  • 自定义CSS类样式
  • 主题集成
  • 文本内容自定义

Quick Start Example

快速开始示例

typescript
import { Component, ViewChild } from '@angular/core';
import { InlineAIAssistModule, InlineAIAssistComponent, InlinePromptRequestEventArgs, ResponseSettingsModel, ResponseItemSelectEventArgs } from '@syncfusion/ej2-angular-interactive-chat';

@Component({
    imports: [InlineAIAssistModule],
    standalone: true,
    selector: 'app-root',
    template: `
        <div id="container" style="height: 350px; width: 650px;">
            <button id="summarizeBtn" class="e-btn e-primary" (click)="onClick()">Content Summarize</button>
            <div id="editableText" contenteditable="true">
                <p>Inline AI Assist component provides intelligent text processing capabilities that enhance user productivity.</p>
            </div>
            <ejs-inlineaiassist id="inlineAssist" #inlineAssistComponent
                [relateTo]="'#summarizeBtn'"
                [responseSettings]="responseSetting"
                popupWidth="500px"
                (promptRequest)="onPromptRequest($event)">
            </ejs-inlineaiassist>
        </div>
    `,
    styles: [`#editableText { width: 100%; min-height: 120px; padding: 12px; border: 1px solid; }`]
})
export class AppComponent {
    @ViewChild('inlineAssistComponent')
    public inlineAssistComponent!: InlineAIAssistComponent;

    public itemSelect = (args: ResponseItemSelectEventArgs) => {
        if (args.command.label === 'Accept') {
            const editable = document.getElementById('editableText') as HTMLElement;
            if (editable && this.inlineAssistComponent.prompts.length > 0) {
                const lastResponse = this.inlineAssistComponent.prompts[this.inlineAssistComponent.prompts.length - 1].response;
                editable.innerHTML = '<p>' + lastResponse + '</p>';
            }
            this.inlineAssistComponent.hidePopup();
        }
    }

    public responseSetting: ResponseSettingsModel = {
        itemSelect: this.itemSelect
    }

    onClick(): void {
        this.inlineAssistComponent.showPopup();
    }

    public onPromptRequest = (args: InlinePromptRequestEventArgs) => {
        setTimeout(() => {
            let response = 'Connect this component to OpenAI or Azure AI services for real-time prompt processing.';
            this.inlineAssistComponent.addResponse(response);
        }, 1000);
    };
}
typescript
import { Component, ViewChild } from '@angular/core';
import { InlineAIAssistModule, InlineAIAssistComponent, InlinePromptRequestEventArgs, ResponseSettingsModel, ResponseItemSelectEventArgs } from '@syncfusion/ej2-angular-interactive-chat';

@Component({
    imports: [InlineAIAssistModule],
    standalone: true,
    selector: 'app-root',
    template: `
        <div id="container" style="height: 350px; width: 650px;">
            <button id="summarizeBtn" class="e-btn e-primary" (click)="onClick()">Content Summarize</button>
            <div id="editableText" contenteditable="true">
                <p>Inline AI Assist component provides intelligent text processing capabilities that enhance user productivity.</p>
            </div>
            <ejs-inlineaiassist id="inlineAssist" #inlineAssistComponent
                [relateTo]="'#summarizeBtn'"
                [responseSettings]="responseSetting"
                popupWidth="500px"
                (promptRequest)="onPromptRequest($event)">
            </ejs-inlineaiassist>
        </div>
    `,
    styles: [`#editableText { width: 100%; min-height: 120px; padding: 12px; border: 1px solid; }`]
})
export class AppComponent {
    @ViewChild('inlineAssistComponent')
    public inlineAssistComponent!: InlineAIAssistComponent;

    public itemSelect = (args: ResponseItemSelectEventArgs) => {
        if (args.command.label === 'Accept') {
            const editable = document.getElementById('editableText') as HTMLElement;
            if (editable && this.inlineAssistComponent.prompts.length > 0) {
                const lastResponse = this.inlineAssistComponent.prompts[this.inlineAssistComponent.prompts.length - 1].response;
                editable.innerHTML = '<p>' + lastResponse + '</p>';
            }
            this.inlineAssistComponent.hidePopup();
        }
    }

    public responseSetting: ResponseSettingsModel = {
        itemSelect: this.itemSelect
    }

    onClick(): void {
        this.inlineAssistComponent.showPopup();
    }

    public onPromptRequest = (args: InlinePromptRequestEventArgs) => {
        setTimeout(() => {
            let response = 'Connect this component to OpenAI or Azure AI services for real-time prompt processing.';
            this.inlineAssistComponent.addResponse(response);
        }, 1000);
    };
}

Common Patterns

常见模式

Pattern 1: Response Handling with Item Selection

模式1:基于项选择的响应处理

typescript
// Handle accept/reject responses
public itemSelect = (args: ResponseItemSelectEventArgs) => {
    if (args.command.label === 'Accept') {
        // Apply the AI response to your content
        const content = this.inlineAssistComponent.prompts[this.inlineAssistComponent.prompts.length - 1].response;
        this.applyResponse(content);
        this.inlineAssistComponent.hidePopup();
    } else if (args.command.label === 'Discard') {
        this.inlineAssistComponent.hidePopup();
    }
}
typescript
// Handle accept/reject responses
public itemSelect = (args: ResponseItemSelectEventArgs) => {
    if (args.command.label === 'Accept') {
        // Apply the AI response to your content
        const content = this.inlineAssistComponent.prompts[this.inlineAssistComponent.prompts.length - 1].response;
        this.applyResponse(content);
        this.inlineAssistComponent.hidePopup();
    } else if (args.command.label === 'Discard') {
        this.inlineAssistComponent.hidePopup();
    }
}

Pattern 2: Executing Predefined Prompts

模式2:执行预定义提示

typescript
// Execute a specific prompt with custom command
public executeCommand(prompt: string) => {
    this.inlineAssistComponent.showPopup();
    this.inlineAssistComponent.executePrompt(prompt);
}

// Example usage: Summarize, Translate, or Make Professional
this.executeCommand('Summarize the content');
typescript
// Execute a specific prompt with custom command
public executeCommand(prompt: string) => {
    this.inlineAssistComponent.showPopup();
    this.inlineAssistComponent.executePrompt(prompt);
}

// Example usage: Summarize, Translate, or Make Professional
this.executeCommand('Summarize the content');

Pattern 3: Command Groups for Organization

模式3:按组组织命令

typescript
// Organize commands into logical groups
public commandSetting: CommandSettingsModel = {
    commands: [
        { label: 'Summarize', prompt: 'Summarize...', groupBy: 'Improve content' },
        { label: 'Shorten', prompt: 'Shorten...', groupBy: 'Improve content' },
        { label: 'Translate', prompt: 'Translate...', groupBy: 'Edit content' },
    ]
}
typescript
// Organize commands into logical groups
public commandSetting: CommandSettingsModel = {
    commands: [
        { label: 'Summarize', prompt: 'Summarize...', groupBy: 'Improve content' },
        { label: 'Shorten', prompt: 'Shorten...', groupBy: 'Improve content' },
        { label: 'Translate', prompt: 'Translate...', groupBy: 'Edit content' },
    ]
}

Pattern 4: Inline vs Popup Modes

模式4:内嵌式 vs 弹出式模式

typescript
// Toggle between response display modes
public responseMode: string = 'Popup'; // or 'Inline'

// Use Inline for seamless in-place editing
// Use Popup for review-based workflows
typescript
// Toggle between response display modes
public responseMode: string = 'Popup'; // or 'Inline'

// Use Inline for seamless in-place editing
// Use Popup for review-based workflows

Key Properties and Configuration

核心属性与配置

PropertyPurposeExample
relateTo
Position relative to DOM element
[relateTo]="'#button'"
target
Append location in DOM
[target]="'#container'"
responseMode
Display mode (Popup/Inline)
[responseMode]="'Popup'"
popupWidth
/
popupHeight
Popup dimensions
popupWidth="500px"
placeholder
Prompt textarea placeholder
[placeholder]="'Ask AI...'"
cssClass
Custom CSS styling
[cssClass]="'custom'"
enableStreaming
Real-time streaming responses
[enableStreaming]="true"
enablePersistence
Preserve state across reloads
[enablePersistence]="true"
commandSettings
Predefined AI commands
[commandSettings]="cmdSettings"
responseSettings
Response action items
[responseSettings]="respSettings"
inlineToolbarSettings
Inline toolbar items
[inlineToolbarSettings]="toolbar"
editorTemplate
Custom prompt input template
[editorTemplate]="template"
responseTemplate
Custom response display template
[responseTemplate]="template"
locale
Language/localization
[locale]="'de'"
enableRtl
Right-to-left text direction
[enableRtl]="true"
属性用途示例
relateTo
相对于DOM元素定位
[relateTo]="'#button'"
target
在DOM中的追加位置
[target]="'#container'"
responseMode
显示模式(Popup/Inline)
[responseMode]="'Popup'"
popupWidth
/
popupHeight
弹窗尺寸
popupWidth="500px"
placeholder
提示文本框占位符
[placeholder]="'Ask AI...'"
cssClass
自定义CSS样式
[cssClass]="'custom'"
enableStreaming
实时流式响应
[enableStreaming]="true"
enablePersistence
重载后保留状态
[enablePersistence]="true"
commandSettings
预定义AI命令
[commandSettings]="cmdSettings"
responseSettings
响应操作项
[responseSettings]="respSettings"
inlineToolbarSettings
内嵌工具栏项
[inlineToolbarSettings]="toolbar"
editorTemplate
自定义提示输入模板
[editorTemplate]="template"
responseTemplate
自定义响应显示模板
[responseTemplate]="template"
locale
语言/本地化
[locale]="'de'"
enableRtl
从右到左文本方向
[enableRtl]="true"

Common Use Cases

常见使用场景

  1. Text Summarization: Create a button that triggers content summarization via AI
  2. Grammar & Style: Help users improve writing with grammar and style suggestions
  3. Content Translation: Add quick translation options for multiple languages
  4. Code Generation: Assist users in generating code snippets based on descriptions
  5. Email Composition: Enhance email writing with AI suggestions and rephrasing
  6. Document Enhancement: Improve document quality with AI-powered editing
  7. Accessibility Support: Provide AI assistance for users with accessibility needs
  8. Multilingual Support: Enable global applications with localized AI assistance
  1. 文本摘要:创建按钮,通过AI触发内容摘要生成
  2. 语法与风格优化:帮助用户通过语法和风格建议提升写作质量
  3. 内容翻译:添加多语言快速翻译选项
  4. 代码生成:根据描述辅助用户生成代码片段
  5. 邮件撰写:通过AI建议与改写增强邮件写作体验
  6. 文档优化:利用AI驱动的编辑功能提升文档质量
  7. 无障碍支持:为有无障碍需求的用户提供AI辅助
  8. 多语言支持:为全球化应用提供本地化AI辅助