syncfusion-blazor-ai-assistview

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Syncfusion Blazor AI AssistView

Syncfusion Blazor AI AssistView

Build conversational AI interfaces with the Syncfusion Blazor AI AssistView component. This skill provides complete guidance for creating interactive chat applications, AI assistant UIs, and prompt-response systems in Blazor Server, WebAssembly, and Web App projects.
使用Syncfusion Blazor AI AssistView组件构建对话式AI界面。本教程为你在Blazor Server、WebAssembly和Web App项目中创建交互式聊天应用、AI助手UI和提示词响应系统提供完整指导。

Component Overview

组件概览

The SfAIAssistView component is a specialized UI control for building AI-powered chat applications. It manages the presentation and interaction model for prompt-response conversations with built-in support for:
  • Prompt Management: Input text, suggestions, placeholder text
  • Response Handling: Async processing, markdown rendering, streaming support
  • Customization: Avatar icons, styling, theme integration
  • UX Features: Scroll-to-bottom indicator, conversation history
  • Event Integration: PromptRequested events for AI service callbacks
SfAIAssistView 组件是专门用于构建AI驱动聊天应用的UI控件,它管理提示词-响应对话的展示和交互模型,内置支持以下功能:
  • 提示词管理: 输入文本、建议内容、占位符文本
  • 响应处理: 异步处理、markdown渲染、流式输出支持
  • 自定义配置: 头像图标、样式、主题集成
  • 用户体验功能: 滚动到底部指示器、对话历史记录
  • 事件集成: 用于AI服务回调的PromptRequested事件

Navigation Guide

导航指南

Getting Started

入门指南

📄 Read: references/getting-started.md
  • Installation and NuGet package setup
  • Basic component structure and initialization
  • PromptRequested event handler implementation
  • Minimal working example with async responses
📄 阅读: references/getting-started.md
  • 安装与NuGet包配置
  • 基础组件结构与初始化
  • PromptRequested事件处理实现
  • 支持异步响应的最小可运行示例

Prompt Configuration

提示词配置

📄 Read: references/prompt-configuration.md
  • Setting initial prompt text
  • Configuring prompt placeholder text
  • Managing prompt-response collections
  • Handling prompt events asynchronously
📄 阅读: references/prompt-configuration.md
  • 设置初始提示词文本
  • 配置提示词占位符文本
  • 管理提示词-响应集合
  • 异步处理提示词事件

Prompt Suggestions

提示词建议

📄 Read: references/prompt-suggestions.md
  • Adding suggestion lists for user guidance
  • Customizing suggestion headers
  • Building suggestion-response mappings
  • User interaction patterns with suggestions
📄 阅读: references/prompt-suggestions.md
  • 为用户添加引导性建议列表
  • 自定义建议内容头部
  • 构建建议-响应映射关系
  • 建议功能的用户交互模式

Customization & Icons

自定义配置与图标

📄 Read: references/customization-styling.md
  • Customizing user avatar with PromptIconCss
  • Customizing AI avatar with ResponseIconCss
  • Applying theme-specific icons
  • CSS class and icon integration
📄 阅读: references/customization-styling.md
  • 用PromptIconCss自定义用户头像
  • 用ResponseIconCss自定义AI头像
  • 应用主题专属图标
  • CSS类与图标集成

Advanced Features

高级功能

📄 Read: references/advanced-features.md
  • Markdown rendering in AI responses
  • Scroll-to-bottom navigation (EnableScrollToBottom)
  • Managing conversation history with Prompts collection
  • Common patterns and use cases
📄 阅读: references/advanced-features.md
  • AI响应中的markdown渲染
  • 滚动到底部导航(EnableScrollToBottom)
  • 通过Prompts集合管理对话历史
  • 通用模式与使用场景

AI Service Integration

AI服务集成

📄 Read: references/ai-service-integration.md
  • OpenAI API integration (non-streaming and streaming)
  • Azure OpenAI deployment
  • Local Ollama LLM hosting
  • Custom backend patterns
  • Error handling and rate limiting strategies
📄 阅读: references/ai-service-integration.md
  • OpenAI API集成(非流式与流式输出)
  • Azure OpenAI部署
  • 本地Ollama LLM托管
  • 自定义后端模式
  • 错误处理与限流策略

Attachments

附件功能

📄 Read: references/attachments.md
  • Enabling file attachments
  • Configuring attachment settings (file types, size limits)
  • Handling attachment events (upload, click, remove)
  • Server-side upload implementation
  • Security and validation best practices
📄 阅读: references/attachments.md
  • 启用文件附件功能
  • 配置附件设置(文件类型、大小限制)
  • 处理附件事件(上传、点击、移除)
  • 服务端上传实现
  • 安全与验证最佳实践

Multi-View Support

多视图支持

📄 Read: references/multi-view-support.md
  • Creating multiple specialized AI views
  • Active view management and switching
  • View-specific configuration
  • Separate conversation histories per view
  • Role-based and workspace-based views
📄 阅读: references/multi-view-support.md
  • 创建多个专用AI视图
  • 活跃视图管理与切换
  • 视图专属配置
  • 每个视图独立的对话历史
  • 基于角色和工作区的视图

Toolbars

工具栏

📄 Read: references/toolbars.md
  • Prompt toolbar customization
  • Response toolbar actions (copy, like, regenerate)
  • Footer toolbar configuration
  • Custom toolbar items and templates
  • Handling toolbar events
📄 阅读: references/toolbars.md
  • 提示词工具栏自定义
  • 响应工具栏操作(复制、点赞、重新生成)
  • 底部工具栏配置
  • 自定义工具栏项与模板
  • 处理工具栏事件

Templates

模板

📄 Read: references/templates.md
  • BannerTemplate for initial/empty state
  • PromptItemTemplate for custom prompt rendering
  • ResponseItemTemplate for custom response rendering
  • PromptSuggestionItemTemplate for custom suggestions
  • FooterTemplate and ViewTemplate customization
  • Template contexts and available properties
📄 阅读: references/templates.md
  • 用于初始/空状态的BannerTemplate
  • 用于自定义提示词渲染的PromptItemTemplate
  • 用于自定义响应渲染的ResponseItemTemplate
  • 用于自定义建议内容的PromptSuggestionItemTemplate
  • FooterTemplate和ViewTemplate自定义
  • 模板上下文与可用属性

Streaming Responses

流式响应

📄 Read: references/streaming.md
  • Enabling streaming mode
  • UpdateResponseAsync for progressive updates
  • Real-time response rendering
  • Integration with OpenAI, Azure, and Ollama streaming APIs
  • Stop responding functionality
  • Performance optimization
📄 阅读: references/streaming.md
  • 启用流式模式
  • 用于渐进式更新的UpdateResponseAsync
  • 实时响应渲染
  • 与OpenAI、Azure和Ollama流式API集成
  • 停止响应功能
  • 性能优化

Methods & Programmatic API

方法与编程式API

📄 Read: references/methods-api.md
  • ExecutePromptAsync for automated prompts
  • UpdateResponseAsync for streaming updates
  • RefreshUIAsync for manual UI refresh
  • ScrollToBottomAsync for scroll control
  • Automated workflows and batch processing
📄 阅读: references/methods-api.md
  • 用于自动生成提示词的ExecutePromptAsync
  • 用于流式更新的UpdateResponseAsync
  • 用于手动UI刷新的RefreshUIAsync
  • 用于滚动控制的ScrollToBottomAsync
  • 自动化工作流与批量处理

Quick Start

快速开始

csharp
@using Syncfusion.Blazor.InteractiveChat

<div style="height: 400px; width: 600px;">
    <SfAIAssistView 
        Prompt="What is Blazor?" 
        PromptRequested="@OnPromptRequested">
    </SfAIAssistView>
</div>

@code {
    private async Task OnPromptRequested(AssistViewPromptRequestedEventArgs args)
    {
        // Add delay to simulate AI processing
        await Task.Delay(1000);
        
        // Connect to your AI service here (OpenAI, Azure, etc.)
        var response = await GetAIResponse(args.Prompt);
        args.Response = response;
    }
    
    private async Task<string> GetAIResponse(string prompt)
    {
        // Call your AI service API
        // For testing: return a simple response
        return $"<div>Processing your prompt: {prompt}</div>";
    }
}
csharp
@using Syncfusion.Blazor.InteractiveChat

<div style="height: 400px; width: 600px;">
    <SfAIAssistView 
        Prompt="What is Blazor?" 
        PromptRequested="@OnPromptRequested">
    </SfAIAssistView>
</div>

@code {
    private async Task OnPromptRequested(AssistViewPromptRequestedEventArgs args)
    {
        // Add delay to simulate AI processing
        await Task.Delay(1000);
        
        // Connect to your AI service here (OpenAI, Azure, etc.)
        var response = await GetAIResponse(args.Prompt);
        args.Response = response;
    }
    
    private async Task<string> GetAIResponse(string prompt)
    {
        // Call your AI service API
        // For testing: return a simple response
        return $"<div>Processing your prompt: {prompt}</div>";
    }
}

Common Patterns

通用模式

Pattern 1: Pre-Initialized Conversation

模式1:预初始化对话

Load the component with existing conversation history:
csharp
<SfAIAssistView 
    Prompts="@conversationHistory" 
    PromptRequested="@OnPromptRequested">
</SfAIAssistView>

@code {
    private List<AssistViewPrompt> conversationHistory = new()
    {
        new AssistViewPrompt { 
            Prompt = "What is C#?", 
            Response = "<div>C# is a modern object-oriented programming language...</div>" 
        }
    };
}
加载组件时自带已有的对话历史:
csharp
<SfAIAssistView 
    Prompts="@conversationHistory" 
    PromptRequested="@OnPromptRequested">
</SfAIAssistView>

@code {
    private List<AssistViewPrompt> conversationHistory = new()
    {
        new AssistViewPrompt { 
            Prompt = "What is C#?", 
            Response = "<div>C# is a modern object-oriented programming language...</div>" 
        }
    };
}

Pattern 2: Guided Suggestions

模式2:引导式建议

Use suggestions to help users refine their prompts:
csharp
<SfAIAssistView 
    PromptSuggestions="@suggestions"
    PromptSuggestionsHeader="Try asking about:"
    PromptRequested="@OnPromptRequested">
</SfAIAssistView>

@code {
    private List<string> suggestions = new()
    {
        "How does dependency injection work?",
        "Explain async/await patterns",
        "What are Blazor components?"
    };
}
使用建议功能帮助用户优化提示词:
csharp
<SfAIAssistView 
    PromptSuggestions="@suggestions"
    PromptSuggestionsHeader="Try asking about:"
    PromptRequested="@OnPromptRequested">
</SfAIAssistView>

@code {
    private List<string> suggestions = new()
    {
        "How does dependency injection work?",
        "Explain async/await patterns",
        "What are Blazor components?"
    };
}

Pattern 3: Custom Avatars

模式3:自定义头像

Personalize user and AI identities with custom icons:
csharp
<SfAIAssistView 
    PromptIconCss="e-icons e-user"
    ResponseIconCss="e-icons e-bullet-2"
    PromptRequested="@OnPromptRequested">
</SfAIAssistView>
使用自定义图标个性化用户和AI身份标识:
csharp
<SfAIAssistView 
    PromptIconCss="e-icons e-user"
    ResponseIconCss="e-icons e-bullet-2"
    PromptRequested="@OnPromptRequested">
</SfAIAssistView>

Key Props

核心属性

PropertyTypePurpose
Prompt
stringInitial prompt text to display
PromptPlaceholder
stringPlaceholder text in input field (default: "Type prompt for assistance...")
PromptSuggestions
List<string>List of suggested prompts for user guidance
PromptSuggestionsHeader
stringHeader text above suggestions
Prompts
List<AssistViewPrompt>Collection of prompt-response pairs (conversation history)
PromptIconCss
stringCSS classes for user avatar icon
ResponseIconCss
stringCSS classes for AI avatar icon (default: "e-assistview-icon")
EnableScrollToBottom
boolShow scroll-to-bottom indicator (default: true)
EnableStreaming
boolEnable streaming mode for progressive responses
AttachmentSettings
AssistViewAttachmentSettingsFile attachment configuration
ActiveView
intIndex of currently active view (for multi-view)
ShowHeader
boolShow/hide component header (default: true)
Width
stringComponent width (default: "100%")
Height
stringComponent height (default: "100%")
CssClass
stringCustom CSS classes for styling
EnableRtl
boolEnable right-to-left layout (default: false)
ID
stringSets the id attribute for the component
属性类型用途
Prompt
string要展示的初始提示词文本
PromptPlaceholder
string输入框的占位符文本(默认值:"Type prompt for assistance...")
PromptSuggestions
List<string>用于引导用户的提示词建议列表
PromptSuggestionsHeader
string建议内容上方的头部文本
Prompts
List<AssistViewPrompt>提示词-响应对集合(对话历史)
PromptIconCss
string用户头像图标的CSS类
ResponseIconCss
stringAI头像图标的CSS类(默认值:"e-assistview-icon")
EnableScrollToBottom
bool展示滚动到底部指示器(默认值:true)
EnableStreaming
bool启用渐进式响应的流式模式
AttachmentSettings
AssistViewAttachmentSettings文件附件配置
ActiveView
int当前活跃视图的索引(用于多视图场景)
ShowHeader
bool展示/隐藏组件头部(默认值:true)
Width
string组件宽度(默认值:"100%")
Height
string组件高度(默认值:"100%")
CssClass
string用于样式自定义的CSS类
EnableRtl
bool启用从右到左布局(默认值:false)
ID
string设置组件的id属性

Common Use Cases

常见使用场景

  1. Customer Support Chatbot - Combine with knowledge base to answer FAQs
  2. Coding Assistant - Real-time code suggestions and explanations
  3. Content Generator - Interactive writing and editing assistant
  4. Learning Interface - Q&A system for educational content
  5. API Documentation - Interactive API helper with examples
  1. 客户支持聊天机器人 - 结合知识库解答常见问题
  2. 编程助手 - 实时代码建议与解释
  3. 内容生成器 - 交互式写作与编辑助手
  4. 学习界面 - 教育内容的问答系统
  5. API文档 - 带示例的交互式API助手