### Initialize DXAICHAT with OpenAI Assistant Setup Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/02-dxaichat-component.md This example demonstrates initializing the DXAICHAT component by creating an OpenAI assistant and thread, then configuring the chat to use them via SetupAssistantAsync. It also includes cleanup logic. ```razor @implements IAsyncDisposable @inject AIAssistantManager assistantManager @code { string? assistantId; string? threadId; string? fileId; async Task Initialized(IAIChat chat) { (assistantId, threadId, fileId) = await assistantManager.CreateAssistantAsync( Assembly.GetExecutingAssembly() .GetManifestResourceStream("App.Data.menu.pdf")!, "menu.pdf", "You are a restaurant assistant. Answer questions about the menu."); await chat.SetupAssistantAsync(assistantId, threadId); } public async ValueTask DisposeAsync() { await assistantManager.CleanUpAssistantAsync(assistantId, threadId, fileId); } } ``` -------------------------------- ### WPF Main Window Setup Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/COMPLETION_SUMMARY.txt The MainWindow.xaml.cs file for WPF applications, demonstrating how to initialize and use the AI Chat component. ```csharp using System.Windows; using DevExpress.Xpf.AI; public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); // Configure AI Chat service (example) var aiChatService = new AIChatService(new AIChatServiceOptions { AzureOpenAIEndpoint = "YOUR_AZURE_OPENAI_ENDPOINT", AzureOpenAIKey = "YOUR_AZURE_OPENAI_API_KEY", AzureOpenAIDEploymentName = "YOUR_AZURE_OPENAI_DEPLOYMENT_NAME" }); // Assign the service to the DxAIChat control in XAML // Example: // In code-behind, you might set DataContext or directly assign if not using MVVM // this.DataContext = new MainViewModel(aiChatService); } } ``` -------------------------------- ### WinForms Form Setup Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/COMPLETION_SUMMARY.txt The Form1.cs file for WinForms applications, showing the setup and integration of the AI Chat component. ```csharp using System.Windows.Forms; using DevExpress.WinForms.AI; public partial class Form1 : Form { public Form1() { InitializeComponent(); // Configure AI Chat service (example) var aiChatService = new AIChatService(new AIChatServiceOptions { AzureOpenAIEndpoint = "YOUR_AZURE_OPENAI_ENDPOINT", AzureOpenAIKey = "YOUR_AZURE_OPENAI_API_KEY", AzureOpenAIDEploymentName = "YOUR_AZURE_OPENAI_DEPLOYMENT_NAME" }); // Assign the service to the DxAIChat control dxAIChat1.Service = aiChatService; } } ``` -------------------------------- ### MAUI Program Setup Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/COMPLETION_SUMMARY.txt The MauiProgram.cs file configures the MAUI application, including DevExpress and AI Chat services. ```csharp using Microsoft.Maui.Hosting; using DevExpress.Maui.Core; using DevExpress.Maui.AI; public static class MauiProgram { public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); builder .UseMauiApp() .ConfigureFonts(fonts => { fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); }) .UseDevExpress(configure => { configure.UseAzureOpenAI("YOUR_AZURE_OPENAI_ENDPOINT", "YOUR_AZURE_OPENAI_API_KEY", "YOUR_AZURE_OPENAI_DEPLOYMENT_NAME"); }); // Register AI Chat services builder.Services.AddAIChat(options => { options.UseStreaming = true; options.ResponseContentFormat = ResponseContentFormat.Markdown; }); return builder.Build(); } } ``` -------------------------------- ### MAUI App Initialization Example Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/03-maui-chat-integration.md Demonstrates how to create a MAUI application instance using the `MauiProgram.CreateMauiApp()` method within the application's entry point. ```csharp // In App.xaml.cs namespace MyMauiApp; public partial class App : Application { public App() { InitializeComponent(); MainPage = new AppShell(); } } // Create the app var app = MauiProgram.CreateMauiApp(); ``` -------------------------------- ### Access Deployed Assets with Essentials Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/CS/DevExpress.AI.Samples.MAUIBlazor/Resources/Raw/AboutAssets.txt Access raw assets deployed with your application package using `FileSystem.OpenAppPackageFileAsync`. This example demonstrates reading the contents of an asset file. ```csharp async Task LoadMauiAsset() { using var stream = await FileSystem.OpenAppPackageFileAsync("AboutAssets.txt"); using var reader = new StreamReader(stream); var contents = reader.ReadToEnd(); } ``` -------------------------------- ### Setting Control Dock Style Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/07-types-and-enums.md Example of setting a control's DockStyle property to fill its parent container. ```csharp var control = new AIChatControl() { Dock = DockStyle.Fill // Fills entire form }; ``` -------------------------------- ### Configure and Setup AI Assistant with Document Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/README.md Handle the Initialized event of the DxAIChat component to set up your AI assistant. This involves creating an assistant with supplementary documents and initializing a new thread. ```razor @code { const string DocumentResourceName = "DevExpress.AI.Samples.Blazor.Data.Restaurant Menu.pdf"; const string prompt = "..."; async Task Initialized(IAIChat chat) { (string assistantId, string threadId) = await assistantManager.CreateAssistantAsync( Assembly.GetExecutingAssembly().GetManifestResourceStream(DocumentResourceName) !, $ירת"{Guid.NewGuid().ToString("N")}.pdf", prompt); await chat.SetupAssistantAsync(assistantId, threadId); } } ``` -------------------------------- ### Basic DxAIChat Component Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/02-dxaichat-component.md A minimal example of integrating the DxAIChat component into a Blazor application. ```razor @using DevExpress.AIIntegration.Blazor.Chat ``` -------------------------------- ### Main Method with AI Chat Client Setup Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/05-winforms-ai-chat.md Initializes the WinForms application, creates an Azure OpenAI chat client, registers it, and runs the main form. Requires the STAThread attribute for COM interop. ```csharp [STAThread] static void Main() { ApplicationConfiguration.Initialize(); IChatClient asChatClient = new Azure.AI.OpenAI.AzureOpenAIClient( new Uri(AzureOpenAIEndpoint), new System.ClientModel.ApiKeyCredential(AzureOpenAIKey)) .GetChatClient("demo").AsIChatClient(); AIExtensionsContainerDesktop.Default.RegisterChatClient(asChatClient); Application.Run(new Form1()); } ``` -------------------------------- ### MAUI MVVM Integration Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/COMPLETION_SUMMARY.txt Example of integrating the AI Chat component using the MVVM pattern in a MAUI application. ```csharp using CommunityToolkit.Mvvm.ComponentModel; using DevExpress.Maui.AI; public partial class MainViewModel : ObservableObject { private readonly IAIChatService _aiChatService; public MainViewModel(IAIChatService aiChatService) { _aiChatService = aiChatService; } // Properties and commands for interacting with the AI Chat component } ``` -------------------------------- ### CreateAssistantAsync Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/01-ai-assistant-manager.md Creates a new OpenAI assistant with file support, tool resources, and returns the assistant ID, thread ID, and file ID. This method handles the complete setup workflow including file upload, vector store creation, tool configuration, assistant creation, and thread initialization. ```APIDOC ## CreateAssistantAsync ### Description Creates a new OpenAI assistant with file support, tool resources, and returns the assistant ID, thread ID, and file ID. This method performs the complete setup workflow: uploading a file, creating vector stores for file search, configuring tool resources (code interpreter and file search), creating an assistant with specified instructions, and initializing a conversation thread. ### Method `public async Task<(string assistantId, string threadId, string fileId)> CreateAssistantAsync( Stream data, string fileName, string instructions, bool useFileSearchTool = true, CancellationToken ct = default) ` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **data** (`Stream`) - Required - Stream containing file data (PDF, text, etc.) to upload - **fileName** (`string`) - Required - Name for the uploaded file (e.g., "document.pdf") - **instructions** (`string`) - Required - System instructions/prompt for the assistant behavior - **useFileSearchTool** (`bool`) - Optional - Enable file search tool for semantic document retrieval (default: `true`) - **ct** (`CancellationToken`) - Optional - Cancellation token for async operation (default: `default`) ### Request Example ```csharp var assistantManager = new AIAssistantManager(openAIClient, "gpt-4"); // Load PDF or document stream using var fileStream = new FileStream("menu.pdf", FileMode.Open); var (assistantId, threadId, fileId) = await assistantManager.CreateAssistantAsync( data: fileStream, fileName: "restaurant-menu.pdf", instructions: "You are a helpful restaurant assistant. Answer questions about the menu.", useFileSearchTool: true); Console.WriteLine($"Created assistant: {assistantId}"); Console.WriteLine($"Thread ID: {threadId}"); ``` ### Response #### Success Response (200) - **assistantId** (`string`) - Unique identifier of the created assistant - **threadId** (`string`) - Unique identifier of the initial thread for conversation - **fileId** (`string`) - Unique identifier of the uploaded file for reference and cleanup #### Response Example ```json { "assistantId": "asst_abc123", "threadId": "thread_xyz789", "fileId": "file-abcdef" } ``` ### Error Handling - `System.ClientModel.ClientResultException`: API request fails (invalid credentials, rate limits, server errors) - `System.IO.IOException`: Stream cannot be read or is null - `System.ArgumentNullException`: fileName or instructions are null ``` -------------------------------- ### Advanced Custom Empty State with Suggestions Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/09-razor-components-reference.md Enhances the empty state by including a welcome message, introductory text, and interactive buttons for suggested prompts. This guides users on how to start interacting with the AI. ```razor

Welcome to AI Chat

Start a conversation by typing a message or selecting a suggestion below.

@code { async Task SendSuggestion(string message) { await chat.SendMessage(message, ChatRole.User); } } ``` -------------------------------- ### Handling Initialized Event Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/02-dxaichat-component.md Example of handling the Initialized event to set up an assistant and thread before the chat component renders. ```razor @code { async Task OnInitialized(IAIChat chat) { // Setup assistant var (aid, tid, _) = await CreateAssistantAsync(); await chat.SetupAssistantAsync(aid, tid); } } ``` -------------------------------- ### Chat Component Usage (Razor) Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/COMPLETION_SUMMARY.txt Example of integrating the DxAIChat component in a Razor file for Blazor applications. ```razor @page "/chat" @inject IAIChatService AIChatService @code { // Component logic can be added here } ``` -------------------------------- ### Custom Logging Configuration in appsettings.json Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/08-configuration-reference.md Customize logging levels for your application. This example sets the default to 'Debug' and 'Microsoft.AspNetCore' to 'Information'. ```json { "Logging": { "LogLevel": { "Default": "Debug", "Microsoft.AspNetCore": "Information" } } } ``` -------------------------------- ### Initialized Event Parameter Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/02-dxaichat-component.md Defines the Initialized event parameter for the DxAIChat component. Use this to perform setup before the first render. ```csharp [Parameter] public EventCallback Initialized { get; set; } ``` -------------------------------- ### Initialize AIAssistantManager Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/01-ai-assistant-manager.md Initializes the AIAssistantManager with an Azure OpenAI client and deployment name. Ensure you have the necessary Azure OpenAI client setup. ```csharp using Azure.AI.OpenAI; using OpenAI; var azureClient = new AzureOpenAIClient( new Uri("https://your-resource.openai.azure.com/"), new AzureKeyCredential("your-api-key")); // Convert Azure client to OpenAI client var openAIClient = azureClient.GetOpenAIClient(); var assistantManager = new AIAssistantManager(openAIClient, "gpt-4-deployment"); ``` -------------------------------- ### Markdown Syntax Example Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/09-razor-components-reference.md Illustrates various markdown elements that can be used in AI responses, including headings, emphasis, lists, links, and code. ```markdown # Heading 1 ## Heading 2 **Bold text** *Italic text* - List item 1 - List item 2 1. Numbered item [Link text](https://example.com) `inline code` ```csharp code block ``` ``` -------------------------------- ### HTML Output for Markdown Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/09-razor-components-reference.md Shows the resulting HTML structure generated from the example markdown syntax, suitable for rendering in a web page. ```html

Heading 1

Heading 2

Bold text

Italic text

  • List item 1
  • List item 2
  1. Numbered item

Link text

inline code

code block
``` -------------------------------- ### Streaming Chat Component Usage (Razor) Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/COMPLETION_SUMMARY.txt Example of using the DxAIChat component with streaming responses enabled in a Razor file. ```razor @page "/chat-streaming" @inject IAIChatService AIChatService @code { // Component logic can be added here } ``` -------------------------------- ### MessageSent: Injecting Context into Prompt Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/09-razor-components-reference.md This example demonstrates how to inject additional context into the user's prompt before it's sent to the AI. This can be useful for providing user-specific information or session details. ```csharp async Task MessageSent(MessageSentEventArgs args) { string context = "Current user: John Doe"; string fullPrompt = $"{context}\n\nUser: {args.Content}"; await args.Chat.SendMessage(fullPrompt, ChatRole.Assistant); } ``` -------------------------------- ### AI Assistant Manager Service Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/COMPLETION_SUMMARY.txt The AIAssistantManager.cs file contains the service class for managing AI Assistant interactions, including setup and cleanup. ```csharp using DevExpress.Blazor.AI.Internal; using System.Threading.Tasks; public class AIAssistantManager { private readonly IOpenAIAssistantService _assistantService; public AIAssistantManager(IOpenAIAssistantService assistantService) { _assistantService = assistantService; } public async Task SetupAssistantAsync(string assistantId) { await _assistantService.CreateAssistantAsync(assistantId); } public async Task CleanUpAssistantAsync(string assistantId) { await _assistantService.DeleteAssistantAsync(assistantId); } } ``` -------------------------------- ### Build and Run Solution Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/10-project-structure.md Use these commands to build the entire solution and run the Blazor project from the root directory. ```bash dotnet build dotnet run --project CS/DevExpress.AI.Samples.Blazor ``` -------------------------------- ### Create and Clean Up Assistant with File Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/00-index.md Demonstrates how to create an assistant with a file, use file search, and clean up resources using AIAssistantManager. ```csharp var manager = new AIAssistantManager(openAIClient, "gpt-4"); // Create assistant with file var (assistantId, threadId, fileId) = await manager.CreateAssistantAsync( fileStream, "document.pdf", "You are helpful.", useFileSearchTool: true); // Clean up resources await manager.CleanUpAssistantAsync(assistantId, threadId, fileId); ``` -------------------------------- ### MessageSent Event Handler Example Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/07-types-and-enums.md An example of an event handler for the MessageSent event. It retrieves user message content, processes it, and sends a response back using the provided chat component reference. ```csharp async Task MessageSent(MessageSentEventArgs args) { string userMessage = args.Content; // Process the message string processed = ProcessMessage(userMessage); // Send response via the component reference await args.Chat.SendMessage($"Processed: {processed}", ChatRole.Assistant); } ``` -------------------------------- ### Blazor Entry Point Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/COMPLETION_SUMMARY.txt The Program.cs file serves as the entry point for Blazor applications, setting up the necessary services and configurations. ```csharp using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using DevExpress.Blazor.AI; var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add("#app"); builder.RootComponents.Add("head::after"); // Configure DevExpress services builder.Services.AddDevExpressBlazor(configure => { configure.BootstrapVersion = DevExpress.Blazor.BootstrapVersion.v5; configure.IconProvider = DevExpress.Blazor.IconProvider.FontAwesome; }); // Configure AI Chat services builder.Services.AddAIChat(options => { options.AzureOpenAI.Endpoint = "YOUR_AZURE_OPENAI_ENDPOINT"; options.AzureOpenAI.ApiKey = "YOUR_AZURE_OPENAI_API_KEY"; options.AzureOpenAI.DeploymentName = "YOUR_AZURE_OPENAI_DEPLOYMENT_NAME"; options.UseStreaming = true; options.ResponseContentFormat = ResponseContentFormat.Markdown; }); await builder.Build().RunAsync(); ``` -------------------------------- ### Configure DXAICHAT with an OpenAI Assistant Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/02-dxaichat-component.md Use SetupAssistantAsync to integrate the chat component with a specific OpenAI assistant and thread. This enables advanced features like file retrieval and code execution. ```csharp public Task SetupAssistantAsync(string assistantId, string threadId) ``` -------------------------------- ### Run Individual Projects Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/10-project-structure.md Navigate to the specific project directory and use 'dotnet run' or 'dotnet build' with the appropriate target framework for MAUI. ```bash # Blazor cd CS/DevExpress.AI.Samples.Blazor dotnet run # MAUI cd CS/DevExpress.AI.Samples.MAUIBlazor dotnet build -f net8.0-android # or -f net8.0-ios, etc. # WPF cd CS/DevExpress.AI.Samples.WPFBlazor dotnet build # WinForms cd CS/DevExpress.AI.Samples.WinBlazor dotnet build ``` -------------------------------- ### Handling MessageSent Event Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/02-dxaichat-component.md Example of handling the MessageSent event to process user input and send a custom AI response. ```razor @code { async Task OnMessageSent(MessageSentEventArgs args) { string userMessage = args.Content; // Custom processing string processed = ProcessMessage(userMessage); // Add custom response await args.Chat.SendMessage($"Processed: {processed}", ChatRole.Assistant); } } ``` -------------------------------- ### Create Assistant with File Search Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/01-ai-assistant-manager.md Creates a new OpenAI assistant, uploads a file, configures tools (code interpreter and file search), and initializes a conversation thread. Use this method for setting up a new assistant that can semantically retrieve information from uploaded documents. ```csharp public async Task<(string assistantId, string threadId, string fileId)> CreateAssistantAsync( Stream data, string fileName, string instructions, bool useFileSearchTool = true, CancellationToken ct = default) { // Method implementation details omitted for brevity throw new NotImplementedException(); } ``` ```csharp var assistantManager = new AIAssistantManager(openAIClient, "gpt-4"); // Load PDF or document stream using var fileStream = new FileStream("menu.pdf", FileMode.Open); var (assistantId, threadId, fileId) = await assistantManager.CreateAssistantAsync( data: fileStream, fileName: "restaurant-menu.pdf", instructions: "You are a helpful restaurant assistant. Answer questions about the menu.", useFileSearchTool: true); Console.WriteLine($"Created assistant: {assistantId}"); Console.WriteLine($"Thread ID: {threadId}"); ``` -------------------------------- ### SetupAssistantAsync Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/02-dxaichat-component.md Configures the chat component to use a specific OpenAI assistant and thread for conversation processing. ```APIDOC ## SetupAssistantAsync ### Description Configures the chat component to use a specific OpenAI assistant and thread for conversation processing. This enables advanced features like file-based knowledge retrieval and code execution. ### Method Signature `public Task SetupAssistantAsync(string assistantId, string threadId)` ### Parameters #### Parameters - **assistantId** (`string`) - Required - OpenAI assistant ID created via `AIAssistantManager.CreateAssistantAsync` - **threadId** (`string`) - Required - OpenAI thread ID for the conversation ### Return Type `Task` ### Example ```csharp @implements IAsyncDisposable @inject AIAssistantManager assistantManager @code { string? assistantId; string? threadId; string? fileId; async Task Initialized(IAIChat chat) { (assistantId, threadId, fileId) = await assistantManager.CreateAssistantAsync( Assembly.GetExecutingAssembly() .GetManifestResourceStream("App.Data.menu.pdf")!, "menu.pdf", "You are a restaurant assistant. Answer questions about the menu."); await chat.SetupAssistantAsync(assistantId, threadId); } public async ValueTask DisposeAsync() { await assistantManager.CleanUpAssistantAsync(assistantId, threadId, fileId); } } ``` ``` -------------------------------- ### Register Chat Client in Blazor Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/00-index.md Register the chat client service in Blazor applications. Ensure the `DevExpress.AIIntegration` package is installed. ```csharp builder.Services.AddChatClient(chatClient); ``` -------------------------------- ### PromptSuggestion Constructor Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/05-winforms-ai-chat.md Defines a suggested prompt template for the AI chat. Use this to create predefined user prompts with titles, descriptions, and actions. ```csharp public PromptSuggestion( string title, string text, string prompt, bool sendOnClick) ``` -------------------------------- ### DxAIChat Component with File Knowledge Assistant Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/02-dxaichat-component.md Integrates an AI assistant with knowledge from a specific file. Requires the AIAssistantManager service and sets up the assistant upon initialization. ```razor @inject AIAssistantManager assistantManager @code { string? assistantId; string? threadId; string? fileId; async Task SetupAssistant(IAIChat chat) { (assistantId, threadId, fileId) = await assistantManager.CreateAssistantAsync( new FileStream("document.pdf", FileMode.Open), "document.pdf", "Answer questions based on the provided document." ); await chat.SetupAssistantAsync(assistantId, threadId); } } ``` -------------------------------- ### Setting Prompt Suggestions Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/05-winforms-ai-chat.md Configures predefined prompt suggestions that users can select to initiate conversations with the AI. ```csharp chat.SetPromptSuggestions(new List(){ new PromptSuggestion( title: "Birthday Wish", text: "A warm and cheerful birthday greeting message.", prompt: "Write a heartfelt birthday message for a close friend.", sendOnClick: false), new PromptSuggestion( "Thank You Note", "A polite thank you note to express gratitude.", "Compose a short thank you note to a colleague who helped with a project.", false) }); ``` -------------------------------- ### Include Raw Assets with MauiAsset Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/CS/DevExpress.AI.Samples.MAUIBlazor/Resources/Raw/AboutAssets.txt Use the MauiAsset Build Action in your .csproj file to deploy raw assets with your application. The `LogicalName` metadata ensures assets are accessible with their original paths. ```xml ``` -------------------------------- ### WPF AIChatControl XAML Configuration Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/06-wpf-ai-chat.md Basic XAML setup for the AIChatControl in a WPF application. Enables Markdown content, streaming responses, and file uploads. ```xaml ``` -------------------------------- ### Configure Prompt Suggestions Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/08-configuration-reference.md Use the `SetPromptSuggestions` method to define a list of `PromptSuggestion` objects. Each suggestion includes a title, hover text, the prompt to send, and whether to auto-send or insert the prompt. ```csharp chat.SetPromptSuggestions(new List{ new PromptSuggestion( title: "Summary", text: "Summarize the content", prompt: "Please summarize the key points.", sendOnClick: true), new PromptSuggestion( title: "Questions", text: "Generate questions", prompt: "What are the main questions about this?", sendOnClick: false) }); ``` -------------------------------- ### AIChatControl Creation and Basic Configuration Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/05-winforms-ai-chat.md Instantiates the AIChatControl and sets essential properties like name, docking, content format, streaming, and file upload enablement. ```csharp AIChatControl chat = new AIChatControl() { Name = "aiChatControl1", Dock = DockStyle.Fill, ContentFormat = AIIntegration.Blazor.Chat.ResponseContentFormat.Markdown, UseStreaming = DefaultBoolean.True, FileUploadEnabled = DefaultBoolean.True }; ``` -------------------------------- ### Create Azure OpenAI Client with Deployment Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/04-blazor-program-setup.md Creates an Azure OpenAI client and retrieves a chat client for a specific deployment. This is useful for direct chat interactions. ```csharp string endpoint = "https://my-resource.openai.azure.com/"; string key = "abc123..."; string deployment = "gpt-4-turbo"; var azureClient = new AzureOpenAIClient( new Uri(endpoint), new AzureKeyCredential(key)); var chatClient = azureClient.GetChatClient(deployment).AsIChatClient(); ``` -------------------------------- ### Send User Message in MVVM Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/07-types-and-enums.md Example of sending a user's message using the `DxChatUI` service in an MVVM pattern. Utilizes the `ChatRole` enum (aliased from `ChatMessageRole`). ```csharp await service.DxChatUI.SendMessage(userMessage, ChatRole.User); ``` -------------------------------- ### WinForms Program Entry Point Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/COMPLETION_SUMMARY.txt The Program.cs file for WinForms applications, serving as the entry point and setting up the application's main form. ```csharp using System.Windows.Forms; static class Program { [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } ``` -------------------------------- ### WPF App Directory Structure Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/10-project-structure.md Outlines the file organization for the DevExpress AI Samples WPF application, including XAML files, code-behind, and project configuration. ```text DevExpress.AI.Samples.WPFBlazor/ ├── App.xaml # App-level resources ├── App.xaml.cs # App code-behind ├── MainWindow.xaml # Main window UI ├── MainWindow.xaml.cs # Main window code-behind ├── AssemblyInfo.cs # Assembly metadata └── DevExpress.AI.Samples.WPFBlazor.csproj # Project file ``` -------------------------------- ### Send Assistant Message in Blazor Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/07-types-and-enums.md Example of sending an assistant's response within a Blazor component's event handler. Requires the `ChatRole` enum (aliased from `ChatMessageRole`). ```razor @code { async Task OnMessageSent(MessageSentEventArgs args) { // User message is already sent // Send an assistant response await args.Chat.SendMessage("Hello!", ChatRole.Assistant); } } ``` -------------------------------- ### Program Entry Point Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/05-winforms-ai-chat.md Defines the entry point for the WinForms application and sets up static properties for Azure OpenAI configuration. ```csharp static class Program { static string AzureOpenAIEndpoint { get; } static string AzureOpenAIKey { get; } [STAThread] static void Main() } ``` -------------------------------- ### DxAIChat Component with Custom Message Templates Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/02-dxaichat-component.md Allows customization of how individual chat messages are displayed using the MessageTemplate. This example shows custom styling based on message role. ```razor
@context.Role
@context.Content
@code { string GetMessageClasses(BlazorChatMessage msg) { return $"message message-{msg.Role.ToString().ToLower()}"; } } ``` -------------------------------- ### Inject AI Services in Blazor Components Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/04-blazor-program-setup.md Inject `IChatClient` and `AIAssistantManager` into Blazor components to utilize AI functionalities. These services are available after proper setup in the application's service collection. ```razor @page "/chat" @using Microsoft.Extensions.AI @using DevExpress.AIIntegration.Blazor.Chat @inject IChatClient ChatClient @inject AIAssistantManager AssistantManager @code { protected override async Task OnInitializedAsync() { // ChatClient and AssistantManager are available for use } } ``` -------------------------------- ### MainWindow Constructor Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/06-wpf-ai-chat.md Initializes the UI components of the MainWindow by calling the auto-generated InitializeComponent() method. This method parses the XAML, builds the UI tree, and sets up event handlers. ```csharp public MainWindow() { InitializeComponent(); } ``` -------------------------------- ### AI Chat Markdown Conversion Event Handler Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/07-types-and-enums.md An example event handler for the MarkdownConvert event. It converts markdown text to HTML using the Markdown.ToHtml method and assigns it to the HtmlText property. ```csharp void Control_MarkdownConvert(object sender, AIChatControlMarkdownConvertEventArgs e) { // Convert markdown to HTML e.HtmlText = (MarkupString)Markdown.ToHtml(e.MarkdownText); } ``` -------------------------------- ### Repository Layout Overview Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/10-project-structure.md This tree structure outlines the main directories and files in the DevExpress AI Chat Samples repository, including C#/.NET samples, documentation, and configuration files. ```tree devexpress-ai-chat-samples/ ├── CS/ # C# / .NET samples │ ├── DevExpress.AI.Samples.sln # Visual Studio solution file │ ├── DevExpress.AI.Samples.Blazor/ # Blazor web application │ ├── DevExpress.AI.Samples.MAUIBlazor/ # MAUI cross-platform app │ ├── DevExpress.AI.Samples.WPFBlazor/ # WPF desktop application │ └── DevExpress.AI.Samples.WinBlazor/ # WinForms desktop application ├── README.md # Documentation and examples ├── LICENSE # License file ├── CODEOWNERS # Repository maintainers ├── config.json # Configuration file └── .gitignore # Git ignore rules ``` -------------------------------- ### Set Prompt Suggestions for AIChatControl Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/07-types-and-enums.md Illustrates how to set a list of PromptSuggestion objects for an AIChatControl. This configures the quick-access prompt buttons available to the user. ```csharp chat.SetPromptSuggestions(new List(){ new PromptSuggestion( title: "Birthday Wish", text: "Generate a birthday message", prompt: "Write a heartfelt birthday message for a close friend.", sendOnClick: false), new PromptSuggestion( title: "Code Review", text: "Ask for code review suggestions", prompt: "Please review this code for improvements.", sendOnClick: true) }); ``` -------------------------------- ### Configure Azure OpenAI Connection Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/00-index.md Set environment variables for Azure OpenAI endpoint and API key, then run your application. ```bash # Set environment variables export AZURE_OPENAI_ENDPOINT="https://your-resource.openai.azure.com/" export AZURE_OPENAI_API_KEY="your-api-key-here" # Run application dotnet run ``` -------------------------------- ### Styling the Empty Message Area Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/09-razor-components-reference.md Applies custom CSS to style the empty message area, controlling its appearance and layout. This example centers the text and sets a specific color and font size. ```css .my-chat-ui-description { display: flex; align-items: center; justify-content: center; height: 200px; color: #666; font-size: 16px; text-align: center; } ``` -------------------------------- ### MAUI Application Builder Configuration Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/03-maui-chat-integration.md This is the main entry point for configuring a MAUI application. It sets up essential services including DevExpress controls, Blazor Hybrid, AI extensions, and the Azure OpenAI client. ```csharp public static class MauiProgram { public static MauiApp CreateMauiApp() { } } ``` -------------------------------- ### Apply Theme to System Bars Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/08-configuration-reference.md Set `ThemeManager.ApplyThemeToSystemBars` to `true` to apply the DevExpress theme to native MAUI system UI bars. This configuration should be done within the `CreateMauiApp` method. ```csharp public static class MauiProgram { public static MauiApp CreateMauiApp() { ThemeManager.ApplyThemeToSystemBars = true; // ... rest of configuration } } ``` -------------------------------- ### CSS Styling for Custom AI Chat Messages Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/09-razor-components-reference.md Define CSS rules to style the custom message bubbles generated by the `MessageTemplate`. This example shows how to apply distinct background colors and borders based on the message role (Assistant, User, Error) and general message styling. ```css .my-chat-message { margin: 10px 0; padding: 10px; border-radius: 8px; } .my-assistant-message { background-color: #e3f2fd; border-left: 4px solid #2196f3; } .my-user-message { background-color: #f5f5f5; border-left: 4px solid #888; margin-left: 20px; } .my-error-message { background-color: #ffebee; border-left: 4px solid #f44336; } ``` -------------------------------- ### Create Azure OpenAI Client Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/04-blazor-program-setup.md Initializes an Azure OpenAI client using the provided endpoint and API key. This client is essential for interacting with Azure OpenAI services like chat and assistants. ```csharp var azureClient = new AzureOpenAIClient( new Uri(azureOpenAIEndpoint), new AzureKeyCredential(azureOpenAIKey)); ``` -------------------------------- ### Configure Azure OpenAI Endpoint and Key Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/README.md Set environment variables for Azure OpenAI endpoint and API key. Ensure these are correctly configured before running the application. ```bash export AZURE_OPENAI_ENDPOINT="https://your-resource.openai.azure.com/" export AZURE_OPENAI_API_KEY="your-api-key-here" ``` -------------------------------- ### Initialize Chat UI Wrapper Reference Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/03-maui-chat-integration.md Stores the reference to the chat UI wrapper component, making it accessible via the singleton instance. This method is crucial for enabling communication between MAUI and the Blazor chat component. ```csharp public void Initialize(MauiChatUIWrapper dxChatUI) { Instance.DxChatUI = dxChatUI; } ``` -------------------------------- ### Initialize and Register Azure OpenAI Chat Client Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/06-wpf-ai-chat.md Register an Azure OpenAI chat client during application startup. Ensure you have the Azure OpenAI endpoint and key available. ```csharp public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); // Initialize AI services IChatClient chatClient = new AzureOpenAIClient( new Uri(azureOpenAIEndpoint), new AzureKeyCredential(azureOpenAIKey)) .GetChatClient("demo").AsIChatClient(); AIExtensionsContainerDesktop.Default.RegisterChatClient(chatClient); } } ``` -------------------------------- ### Blazor Appsettings Configuration Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/10-project-structure.md Standard logging and host settings for Blazor applications. ```json { "Logging": { "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning" } }, "AllowedHosts": "*" } ``` -------------------------------- ### MAUI Blazor Project Directory Structure Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/10-project-structure.md Illustrates the file and folder organization for the MAUI Blazor application, highlighting configuration files, UI elements, platform-specific code, and web resources. ```tree DevExpress.AI.Samples.MAUIBlazor/ ├── MauiProgram.cs # MAUI application configuration ├── App.xaml # App-level XAML resources ├── App.xaml.cs # App code-behind ├── MainPage.xaml # Main page UI ├── MainPage.xaml.cs # Main page code-behind ├── MainViewModel.cs # MVVM view model for message sending ├── MauiChatUIWrapper.cs # Blazor component wrapper for MAUI ├── Resources/ │ ├── Fonts/ # Custom fonts │ └── Styles/ # Theme and style resources ├── Platforms/ │ ├── Android/ │ │ ├── MainActivity.cs │ │ └── MainApplication.cs │ ├── iOS/ │ │ └── AppDelegate.cs │ └── Windows/ # Windows-specific code ├── wwwroot/ # Blazor web resources (CSS, JS) └── DevExpress.AI.Samples.MAUIBlazor.csproj # Project file ``` -------------------------------- ### Enable Streaming Response for Improved Responsiveness Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/README.md Set UseStreaming to true to receive AI responses in parts as they become available, making the chat appear more responsive. ```razor ``` -------------------------------- ### Configure Azure OpenAI API Key Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/04-blazor-program-setup.md Reads the AZURE_OPENAI_API_KEY environment variable or defaults to "DEMO". For production use, this should be set to an actual API key. ```csharp string azureOpenAIKey = Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY"); if (string.IsNullOrEmpty(azureOpenAIKey)) azureOpenAIKey = "DEMO"; ``` -------------------------------- ### Initialize AIChatControl in WinForms Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/README.md Create and configure an AIChatControl instance for WinForms applications. Set docking style and enable streaming. ```csharp var chat = new AIChatControl() { Dock = DockStyle.Fill, UseStreaming = DefaultBoolean.True }; ``` -------------------------------- ### Form1 Constructor Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/05-winforms-ai-chat.md Initializes the form components and calls the method to set up the AI Chat control. ```csharp public Form1() { InitializeComponent(); InitializeBlazorAIChat(); } ``` -------------------------------- ### AIChatControl Configuration for WinForms/WPF Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/00-index.md Illustrates configuring the AIChatControl for WinForms/WPF with markdown support, streaming, file uploads, and prompt suggestions. ```csharp var chat = new AIChatControl() { Dock = DockStyle.Fill, ContentFormat = ResponseContentFormat.Markdown, UseStreaming = DefaultBoolean.True, FileUploadEnabled = DefaultBoolean.True }; chat.MarkdownConvert += (s, e) => e.HtmlText = (MarkupString)Markdown.ToHtml(e.MarkdownText); chat.OptionsFileUpload.FileTypeFilter.AddRange(new[] { "application/pdf" }); chat.SetPromptSuggestions(...); ``` -------------------------------- ### Blazor Web App Directory Structure Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/10-project-structure.md This tree structure details the organization of the DevExpress.AI.Samples.Blazor project, including application configuration, static files, components, services, and data resources. ```tree DevExpress.AI.Samples.Blazor/ ├── Program.cs # Application configuration and DI ├── app.db # SQLite database ├── appsettings.json # Configuration settings ├── wwwroot/ # Static files (CSS, JS, images) ├── Components/ │ ├── App.razor # Root component │ ├── Routes.razor # Routing configuration │ ├── _Imports.razor # Global imports │ ├── Layout/ │ │ └── MainLayout.razor # Shared layout template │ └── Pages/ │ ├── Chat.razor # Basic chat (route: /) │ ├── Chat-Streaming.razor # Streaming chat (route: /streaming) │ ├── Chat-CustomMessage.razor # Custom templates (route: /custommessage) │ ├── Chat-CustomEmptyState.razor # Custom welcome (route: /emptystate) │ ├── Chat-Markdown.razor # Markdown rendering (route: /markdown) │ ├── Chat-MessageSent.razor # Message interception (route: /messagesent) │ └── Chat-Assistant.razor # Document assistant (route: /assistant) ├── Services/ │ └── AIAssistantManager.cs # OpenAI assistant management ├── Data/ │ └── Restaurant Menu.pdf # Embedded resource for assistant demo └── DevExpress.AI.Samples.Blazor.csproj # Project file ``` -------------------------------- ### DxAIChat Component Configuration Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/00-index.md Shows how to configure the DxAIChat Blazor component with streaming, markdown format, file uploads, and event handlers. ```razor ... ... ... ``` -------------------------------- ### Configuring File Upload Options Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/05-winforms-ai-chat.md Sets constraints for file uploads, including allowed MIME types, file extensions, maximum file count, and maximum file size. ```csharp chat.OptionsFileUpload.FileTypeFilter.AddRange(new List { "text/plain", "application/pdf", "image/png" }); chat.OptionsFileUpload.AllowedFileExtensions.AddRange(new List { ".txt", ".pdf", ".png" }); chat.OptionsFileUpload.MaxFileCount = 5; chat.OptionsFileUpload.MaxFileSize = 5 * 1024 * 1024; // 5 MB ``` -------------------------------- ### WinForms App Directory Structure Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/10-project-structure.md Details the file organization for the DevExpress AI Samples WinForms application, including the program entry point, form code-behind, and project file. ```text DevExpress.AI.Samples.WinBlazor/ ├── Program.cs # Application entry point ├── Form1.cs # Main form code-behind ├── Form1.Designer.cs # Designer-generated UI └── DevExpress.AI.Samples.WinBlazor.csproj # Project file ``` -------------------------------- ### Using MarkupString for HTML Rendering Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/07-types-and-enums.md Demonstrates how to use MarkupString to render HTML safely in Blazor. Shows the difference between encoded text and rendered HTML, and how to cast markdown conversion results. ```csharp // Without MarkupString (encoded as text) var text = "Bold"; // Displays literally // With MarkupString (rendered as HTML) var html = (MarkupString)"Bold"; // Renders bold // From markdown conversion var markdown = Markdown.ToHtml("**Bold**"); // Returns "

Bold

" var html = (MarkupString)markdown; // Cast to MarkupString for safe rendering ``` -------------------------------- ### InitializeBlazorAIChat Method Signature Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/05-winforms-ai-chat.md Signature for the method responsible for creating and configuring the AIChatControl. ```csharp void InitializeBlazorAIChat() ``` -------------------------------- ### Configure Core HTTP Middleware Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/04-blazor-program-setup.md Sets up essential HTTP middleware for a Blazor application, including HTTPS redirection, static file serving, and antiforgery token validation. ```csharp app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseAntiforgery(); ``` -------------------------------- ### Add Document-Based Q&A to Blazor Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/00-index.md Set up an AI assistant with a document and thread for Q&A functionality. ```razor @implements IAsyncDisposable @inject AIAssistantManager assistantManager @code { string? assistantId, threadId, fileId; async Task OnInitialized(IAIChat chat) { (assistantId, threadId, fileId) = await assistantManager.CreateAssistantAsync( fileStream, "document.pdf", "Your instructions here"); await chat.SetupAssistantAsync(assistantId, threadId); } public async ValueTask DisposeAsync() { await assistantManager.CleanUpAssistantAsync(assistantId, threadId, fileId); } } ``` -------------------------------- ### Configure Azure OpenAI Credentials in WPF Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/06-wpf-ai-chat.md Retrieve Azure OpenAI service endpoint and API key from environment variables. Provides default values if variables are not set. ```csharp string endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? "https://api.devexpress.com/demo-openai"; string key = Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY") ?? "DEMO"; ``` -------------------------------- ### BuildRenderTree Method Implementation Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/03-maui-chat-integration.md Rendering method to build the component's render tree. Registers DevExpress Blazor resource scripts for Blazor Hybrid compatibility before rendering. ```csharp protected override void BuildRenderTree(RenderTreeBuilder builder) { DxResourceManager.RegisterScripts(); base.BuildRenderTree(builder); } ``` -------------------------------- ### Set AZURE_OPENAI_API_KEY for Development/Production Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/08-configuration-reference.md Set the authentication key for the Azure OpenAI service. Use the demo key for the DevExpress proxy or your actual Azure key for production. ```bash AZURE_OPENAI_API_KEY="DEMO" ``` ```bash AZURE_OPENAI_API_KEY="abc123def456abc123def456abc123de" ``` -------------------------------- ### Register OpenAI Assistants Functionality Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/08-configuration-reference.md Enables assistant-based chat functionality by registering the necessary services with DevExpress AI. This provides the assistant client required for operations like file uploads and assistant creation, and is needed for the SetupAssistantAsync() method. ```csharp builder.Services.AddDevExpressAI(config => { config.RegisterOpenAIAssistants(azureClient, deploymentName); }); ``` -------------------------------- ### Azure OpenAI Client Configuration Source: https://github.com/devexpress-examples/devexpress-ai-chat-samples/blob/26.1.3+/_autodocs/03-maui-chat-integration.md Configures the Azure OpenAI client by retrieving endpoint and key from environment variables or using a demo proxy. It then registers the `IChatClient` with the service collection. ```csharp string azureOpenAIEndpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? "https://api.devexpress.com/demo-openai"; string azureOpenAIKey = Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY") ?? "DEMO"; IChatClient chatClient = new AzureOpenAIClient( new Uri(azureOpenAIEndpoint), new AzureKeyCredential(azureOpenAIKey) ).GetChatClient("demo").AsIChatClient(); builder.Services.AddChatClient(chatClient); builder.Services.AddSingleton(); ```