diff --git a/blazor-toc.html b/blazor-toc.html index 6abe23d80f..e869304e59 100644 --- a/blazor-toc.html +++ b/blazor-toc.html @@ -3471,6 +3471,47 @@ +
|
+| [Screen Reader Support](../common/accessibility#screen-reader-support) |
|
+| [Right-To-Left Support](../common/accessibility#right-to-left-support) |
|
+| [Color Contrast](../common/accessibility#color-contrast) |
|
+| [Mobile Device Support](../common/accessibility#mobile-device-support) |
|
+| [Keyboard Navigation Support](../common/accessibility#keyboard-navigation-support) |
|
+| [Axe-core Accessibility Validation](../common/accessibility#ensuring-accessibility) |
|
+
+
+
+
- All features of the component meet the requirement.
- Some features of the component do not meet the requirement.
- The component does not meet the requirement.Inline AI Assist component provides intelligent text processing capabilities that enhance user productivity. + It leverages advanced natural language processing to understand context and deliver precise suggestions. + Users can seamlessly integrate AI-powered features into their applications.
+With real-time response streaming and customizable prompts, developers can create interactive experiences. + The component supports multiple response modes including inline editing and popup-based interactions.
+Inline AI Assist component provides intelligent text processing capabilities that enhance user productivity. It leverages advanced natural language processing to understand context and deliver precise suggestions. Users can seamlessly integrate AI-powered features into their applications.
+With real-time response streaming and customizable prompts, developers can create interactive experiences. The component supports multiple response modes including inline editing and popup-based interactions.
"; + + private async Task OnPromptRequestAsync(PromptRequestedEventArgs args) + { + try + { + stopStreaming = false; + var url = $"{liteLlmHost.TrimEnd('/')}/v1/chat/completions"; + + Http.DefaultRequestHeaders.Clear(); + Http.DefaultRequestHeaders.Add("Accept", "application/json"); + if (!string.IsNullOrEmpty(liteLlmApiKey)) + { + Http.DefaultRequestHeaders.Add("Authorization", $"Bearer {liteLlmApiKey}"); + } + + var requestBody = new + { + model = "openai/gpt-4o-mini", // Must match model_name in config.yaml + messages = new[] { new { role = "user", content = args.Prompt } }, + temperature = 0.7, + max_tokens = 300, + stream = false + }; + + var json = JsonSerializer.Serialize(requestBody); + var content = new StringContent(json, Encoding.UTF8, "application/json"); + + var response = await Http.PostAsync(url, content); + if (!response.IsSuccessStatusCode) + { + throw new Exception($"HTTP {response.StatusCode}"); + } + + var responseContent = await response.Content.ReadAsStringAsync(); + using var document = JsonDocument.Parse(responseContent); + var responseText = document.RootElement + .GetProperty("choices")[0] + .GetProperty("message") + .GetProperty("content") + .GetString()?.Trim() ?? "No response received."; + + var pipeline = new MarkdownPipelineBuilder() + .UseAdvancedExtensions() + .UsePipeTables() + .UseTaskLists() + .Build(); + + if (!stopStreaming) + { + await inlineAssist.UpdateResponseAsync(Markdown.ToHtml(responseText, pipeline)); + } + } + catch (Exception ex) + { + Console.WriteLine($"Error fetching LiteLLM response: {ex.Message}"); + await inlineAssist.UpdateResponseAsync("⚠️ Something went wrong while connecting to the AI service. Please check your LiteLLM proxy, model name, or try again later."); + stopStreaming = true; + } + } + + private async Task OnItemSelectAsync(ResponseItemSelectEventArgs args) + { + if (args.Item.Label == "Accept") + { + var lastPrompt = inlineAssist?.Prompts.LastOrDefault(); + if (lastPrompt != null && !string.IsNullOrEmpty(lastPrompt.Response)) + { + editableContent = $"{lastPrompt.Response}
"; + } + await inlineAssist!.HidePopupAsync(); + } + else if (args.Item.Label == "Discard") + { + await inlineAssist!.HidePopupAsync(); + } + } + + private async Task OnToolbarItemClickAsync(ToolbarItemClickEventArgs args) + { + if (args.Item.IconCss == "e-icons e-inline-stop") + { + stopStreaming = true; + } + } + + private async Task OnSummarizeClick() + { + await inlineAssist.ShowPopupAsync(); + } +} +{% endhighlight %} +{% endtabs %} + + + +## Run and Test + +### Start the proxy: + +Navigate to your project root and run the following command to start the proxy: + +```bash +pip install "litellm[proxy]" +litellm --config "./config.yaml" --port 4000 --host 0.0.0.0 +``` + +### Start the application: + +In a separate terminal window, navigate to your project folder and start the Blazor application: + +```bash +dotnet run +``` + +Open your app to interact with the Inline AI Assist component integrated with LiteLLM. + +## Troubleshooting + +* `401 Unauthorized`: Verify your `API_KEY` and model deployment name. +* `Model not found`: Ensure model matches `model_name` in `config.yaml`. +* `CORS issues`: Configure `router_settings.cors_allow_origins` properly. \ No newline at end of file diff --git a/blazor/inline-ai-assist/ai-integrations/ollama-llm-integration.md b/blazor/inline-ai-assist/ai-integrations/ollama-llm-integration.md new file mode 100644 index 0000000000..5dece871a2 --- /dev/null +++ b/blazor/inline-ai-assist/ai-integrations/ollama-llm-integration.md @@ -0,0 +1,283 @@ +--- +layout: post +title: LLM Model with Blazor Inline AI Assist Component | Syncfusion® +description: Checkout and learn about Integration of LLM Model with Blazor Inline AI Assist component in Blazor WebAssembly Application. +platform: Blazor +control: Inline AI Assist +documentation: ug +--- + +# Integrate LLM via Ollama with Blazor Inline AI Assist Component + +The Inline AI Assist component integrates with [LLM via Ollama](https://ollama.com) to enable advanced conversational AI features in your Blazor application. The component acts as a user interface where user prompts are sent to the selected LLM model via API calls, providing natural language understanding and context-aware responses. + +## Prerequisites + +Before starting, ensure you have the following: + +* [Ollama](https://ollama.com) installed to run and manage LLM models locally. + +* **Syncfusion Inline AI Assist**: Package [Syncfusion Blazor package](https://www.nuget.org/packages/Syncfusion.Blazor.InteractiveChat) installed. + +* [Markdig](https://www.nuget.org/packages/Markdig) package: For parsing Markdown responses. + +## Set Up the Inline AI Assist Component + +Follow the [Getting Started](../getting-started) guide to configure and render the Inline AI Assist component in the application and that prerequisites are met. + +## Install Dependency + +To install the Markdig package by run `NuGet\Install-Package Markdig` in Package Manager Console. + +## Configuring Ollama + +Install Ollama for your operating system: + +{% tabs %} +{% highlight ts tabtitle="Windows" %} + +1. Visit [Windows](https://ollama.com/download) +2. Click `Download for Windows` to get the `.exe installer`. +3. Run `OllamaSetup.exe` and follow the wizard to install. + +{% endhighlight %} + +{% highlight ts tabtitle="macOS" %} + +1. Visit [macOS](https://ollama.com/download/mac) +2. Click `Download for macOS` to get `.dmg file` +3. Install it by following the wizard. + +{% endhighlight %} + +{% highlight ts tabtitle="Linux" %} + +1. Visit [Linux](https://ollama.com/download/linux) +2. Run the below command to install Ollama in your system + + curl -fsSL https://ollama.com/install.sh | sh + +{% endhighlight %} +{% endtabs %} + +## Download and run an Ollama model + +* Download and run a model using the following command. Replace `deepseek-r1` with your preferred model (e.g., `llama3`, `phi4`). See the [Ollama model](https://ollama.com/search) library for available models. + +```bash + +ollama run deepseek-r1 + +``` + +* After the model download completes, start the Ollama server to make the model accessible: + +```bash + +ollama serve + +``` + +## Configure Inline AI Assist with Ollama + +To integrate Ollama with the Blazor Inline AI Assist component in your Blazor application: + +* Configure the AI services in the `Program.cs` file to register the Ollama client and Blazor services. + +{% tabs %} +{% highlight cs tabtitle="Program.cs" %} + + +using Blazor_InlineAIAssist_Ollama.Components; +using Microsoft.Extensions.AI; +using OllamaSharp; +using Syncfusion.Blazor; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. +builder.Services.AddRazorComponents() + .AddInteractiveServerComponents(); +builder.Services.AddSyncfusionBlazor(); + +builder.Services.AddHttpClient(); + +builder.Services.AddDistributedMemoryCache(); + +// Ollama configuration +builder.Services.AddChatClient(new OllamaApiClient(new Uri("http://localhost:11434/"), "llama3.2")) + .UseDistributedCache() + .UseLogging(); + +var app = builder.Build(); + +if (!app.Environment.IsDevelopment()) +{ + app.UseExceptionHandler("/Error", createScopeForErrors: true); + app.UseHsts(); +} + +app.UseHttpsRedirection(); +app.UseAntiforgery(); +app.MapStaticAssets(); +app.MapRazorComponentsInline AI Assist component provides intelligent text processing capabilities that enhance user productivity. + It leverages advanced natural language processing to understand context and deliver precise suggestions. + Users can seamlessly integrate AI-powered features into their applications.
+With real-time response streaming and customizable prompts, developers can create interactive experiences. + The component supports multiple response modes including inline editing and popup-based interactions.
+Inline AI Assist component provides intelligent text processing capabilities that enhance user productivity. + It leverages advanced natural language processing to understand context and deliver precise suggestions. + Users can seamlessly integrate AI-powered features into their applications.
+With real-time response streaming and customizable prompts, developers can create interactive experiences. + The component supports multiple response modes including inline editing and popup-based interactions.
+Inline AI Assist component provides intelligent text processing capabilities that enhance user productivity. It leverages advanced natural language processing to understand context and deliver precise suggestions. Users can seamlessly integrate AI-powered features into their applications.
+With real-time response streaming and customizable prompts, developers can create interactive experiences. The component supports multiple response modes including inline editing and popup-based interactions.
"; + + private async Task OnPromptRequestAsync(PromptRequestedEventArgs args) + { + await Task.Delay(1000); + string defaultResponse = "For real-time prompt processing, connect the Inline AI Assist component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration."; + await inlineAssist.UpdateResponseAsync(defaultResponse); + } + + private async Task OnItemSelectAsync(ResponseItemSelectEventArgs args) + { + if (args.Item.Label == "Accept") + { + var lastPrompt = inlineAssist?.Prompts.LastOrDefault(); + if (lastPrompt != null && !string.IsNullOrEmpty(lastPrompt.Response)) + { + editableContent = $"{lastPrompt.Response}
"; + } + await inlineAssist!.HidePopupAsync(); + } + else if (args.Item.Label == "Discard") + { + await inlineAssist!.HidePopupAsync(); + } + } + + private async Task OnSummarizeClick() + { + await inlineAssist.ShowPopupAsync(); + } +} +``` + + \ No newline at end of file diff --git a/blazor/inline-ai-assist/command-settings.md b/blazor/inline-ai-assist/command-settings.md new file mode 100644 index 0000000000..f7d1607852 --- /dev/null +++ b/blazor/inline-ai-assist/command-settings.md @@ -0,0 +1,130 @@ +--- +layout: post +title: Commands in Blazor InlineAIAssist Control | Syncfusion +description: Checkout and learn about Command items with Blazor Inline AI Assist component in Blazor Server App and Blazor WebAssembly App. +platform: Blazor +control: Inline AI Assist +documentation: ug +--- + +# Commands configuration in Blazor Inline AI Assist control + +You can render and use the command action popup by using the `commands` property in the `e-inlineaiassist-commandsettings` tag helper. This property helps to supply commands, control popup dimensions, and customize behavior. + +## Configure command items + +You can use the `commandSettings` property to add commands that populate the command popup. Each command item can perform a quick request based on the configured `prompt`. + +Each command item object can include the following properties: + +| Property | Type | Default | Description | +|-------------|---------|---------|--------------------------------------------------------------| +| label | string | '' | Specifies the display label of the command item. | +| prompt | string | '' | Specifies the prompt text executed when the item is selected.| +| iconCss | string | '' | Specifies the CSS class for the item's icon. | +| disabled | boolean | false | Specifies whether the command is disabled and unselectable. | +| groupBy | string | '' | Specifies the group category for organizing related commands.| +| id | string | '' | Specifies a unique identifier for the command item. | +| tooltip | string | '' | Specifies the tooltip text displayed on hover. | + +## Command interactions + +The `itemSelect` event is triggered when a command item is selected from the command popup in the Inline AI Assist control. + +## Customization of AI commands popup + +### Setting popup width + +Control the popup width with `popupWidth` property in the commandSettings. Accepts CSS values or number (px). + +### Setting popup height + +Control the popup height with PopupHeight property in the commandSettings. Use this to enable scrollable lists when many commands exist. + +The below sample demonstrates the `CommandSettings` property. + +```cshtml +@using Syncfusion.Blazor.InteractiveChat +@using Syncfusion.Blazor.Buttons + + + +Inline AI Assist component provides intelligent text processing capabilities that enhance user productivity. It leverages advanced natural language processing to understand context and deliver precise suggestions. Users can seamlessly integrate AI-powered features into their applications.
+With real-time response streaming and customizable prompts, developers can create interactive experiences. The component supports multiple response modes including inline editing and popup-based interactions.
"; + + private List{lastPrompt.Response}
"; + } + await inlineAssist!.HidePopupAsync(); + } + else if (args.Item.Label == "Discard") + { + await inlineAssist!.HidePopupAsync(); + } + } + + private async Task OnCommandItemSelectAsync(CommandItemSelectEventArgs args) + { + // Your required action here + } + + private async Task OnSummarizeClick() + { + await inlineAssist.ShowPopupAsync(); + } +} +``` + + + +## See Also + +- [Response Settings](./response-settings.md) +- [Inline Toolbar](./inline-toolbar.md) +- [Events Documentation](./events.md) \ No newline at end of file diff --git a/blazor/inline-ai-assist/events.md b/blazor/inline-ai-assist/events.md new file mode 100644 index 0000000000..8227b5e20b --- /dev/null +++ b/blazor/inline-ai-assist/events.md @@ -0,0 +1,84 @@ +--- +layout: post +title: Events in Blazor Inline AI Assist Control | Syncfusion +description: Checkout and learn about Events with Blazor Inline AI Assist component in Blazor Server App and Blazor WebAssembly App. +platform: Blazor +control: Inline AI Assist +documentation: ug +--- + +# Events in Blazor Inline AI Assist control + +This section describes the Inline AI Assist events that will be triggered when appropriate actions are performed. The following events are available in the Inline AI Assist control. + +## created + +The Inline AI Assist control triggers the `created` event when the control rendering is completed. + +```cshtml + ++ Inline AI Assist component provides intelligent text processing + capabilities that enhance user productivity. It leverages advanced + natural language processing to understand context and deliver + precise suggestions. Users can seamlessly integrate AI-powered + features into their applications. +
++ With real-time response streaming and customizable prompts, + developers can create interactive experiences. The component + supports multiple response modes including inline editing and + popup-based interactions. +
+Inline AI Assist component provides intelligent text processing capabilities that enhance user productivity. It leverages advanced natural language processing to understand context and deliver precise suggestions. Users can seamlessly integrate AI-powered features into their applications.
+With real-time response streaming and customizable prompts, developers can create interactive experiences. The component supports multiple response modes including inline editing and popup-based interactions.
"; + + private async Task OnPromptRequestAsync(PromptRequestedEventArgs args) + { + await Task.Delay(1000); + string defaultResponse = "For real-time prompt processing, connect the Inline AI Assist component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration."; + await inlineAssist.UpdateResponseAsync(defaultResponse); + } + + private async Task OnItemSelectAsync(ResponseItemSelectEventArgs args) + { + if (args.Item.Label == "Accept") + { + var lastPrompt = inlineAssist?.Prompts.LastOrDefault(); + if (lastPrompt != null && !string.IsNullOrEmpty(lastPrompt.Response)) + { + editableContent = $"{lastPrompt.Response}
"; + } + await inlineAssist!.HidePopupAsync(); + } + else if (args.Item.Label == "Discard") + { + await inlineAssist!.HidePopupAsync(); + } + } + + private async Task OnSummarizeClick() + { + await inlineAssist.ShowPopupAsync(); + } + + private async Task OnResponseModeChangeAsync(ChangeEventArgs args) + { + if (Enum.TryParse+ Inline AI Assist component provides intelligent text processing + capabilities that enhance user productivity. It leverages advanced + natural language processing to understand context and deliver + precise suggestions. Users can seamlessly integrate AI-powered + features into their applications. +
++ With real-time response streaming and customizable prompts, + developers can create interactive experiences. The component + supports multiple response modes including inline editing and + popup-based interactions. +
+Inline AI Assist component provides intelligent text processing capabilities that enhance user productivity. It leverages advanced natural language processing to understand context and deliver precise suggestions. Users can seamlessly integrate AI-powered features into their applications.
+With real-time response streaming and customizable prompts, developers can create interactive experiences. The component supports multiple response modes including inline editing and popup-based interactions.
"; + + private async Task OnPromptRequestAsync(PromptRequestedEventArgs args) + { + await Task.Delay(1000); + string defaultResponse = "For real-time prompt processing, connect the Inline AI Assist component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration."; + await inlineAssist.UpdateResponseAsync(defaultResponse); + } + + private async Task OnItemSelectAsync(ResponseItemSelectEventArgs args) + { + if (args.Item.Label == "Accept") + { + var lastPrompt = inlineAssist?.Prompts.LastOrDefault(); + if (lastPrompt != null && !string.IsNullOrEmpty(lastPrompt.Response)) + { + editableContent = $"{lastPrompt.Response}
"; + } + await inlineAssist!.HidePopupAsync(); + } + else if (args.Item.Label == "Discard") + { + await inlineAssist!.HidePopupAsync(); + } + } + + private async Task OnSummarizeClick() + { + await inlineAssist.ShowPopupAsync(); + } + + private async Task OnResponseModeChangeAsync(ChangeEventArgs args) + { + if (Enum.TryParse+ Inline AI Assist component provides intelligent text processing + capabilities that enhance user productivity. It leverages advanced + natural language processing to understand context and deliver + precise suggestions. Users can seamlessly integrate AI-powered + features into their applications. +
++ With real-time response streaming and customizable prompts, + developers can create interactive experiences. The component + supports multiple response modes including inline editing and + popup-based interactions. +
+Inline AI Assist component provides intelligent text processing capabilities that enhance user productivity. It leverages advanced natural language processing to understand context and deliver precise suggestions. Users can seamlessly integrate AI-powered features into their applications.
+With real-time response streaming and customizable prompts, developers can create interactive experiences. The component supports multiple response modes including inline editing and popup-based interactions.
"; + + private async Task OnPromptRequestAsync(PromptRequestedEventArgs args) + { + await Task.Delay(1000); + string defaultResponse = "For real-time prompt processing, connect the Inline AI Assist component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration."; + await inlineAssist.UpdateResponseAsync(defaultResponse); + } + + private async Task OnItemSelectAsync(ResponseItemSelectEventArgs args) + { + if (args.Item.Label == "Accept") + { + var lastPrompt = inlineAssist?.Prompts.LastOrDefault(); + if (lastPrompt != null && !string.IsNullOrEmpty(lastPrompt.Response)) + { + editableContent = $"{lastPrompt.Response}
"; + } + await inlineAssist!.HidePopupAsync(); + } + else if (args.Item.Label == "Discard") + { + await inlineAssist!.HidePopupAsync(); + } + } + + private async Task OnSummarizeClick() + { + await inlineAssist.ShowPopupAsync(); + } + + private async Task OnResponseModeChangeAsync(ChangeEventArgs args) + { + if (Enum.TryParseInline AI Assist component provides intelligent text processing capabilities that enhance user productivity. It leverages advanced natural language processing to understand context and deliver precise suggestions. Users can seamlessly integrate AI-powered features into their applications.
+With real-time response streaming and customizable prompts, developers can create interactive experiences. The component supports multiple response modes including inline editing and popup-based interactions.
"; + + private List{lastPrompt.Response}
"; + } + await inlineAssist!.HidePopupAsync(); + } + else if (args.Item.Label == "Discard") + { + await inlineAssist!.HidePopupAsync(); + } + } + + private async Task OnToolbarItemClickAsync(ToolbarItemClickEventArgs args) + { + // Your required actions + } + + private async Task OnSummarizeClick() + { + await inlineAssist.ShowPopupAsync(); + } + + private void OnToggleToolbarPosition() + { + currentToolbarPosition = currentToolbarPosition == ToolbarPosition.Inline + ? ToolbarPosition.Bottom + : ToolbarPosition.Inline; + } +} +``` + +{% endhighlight %} +{% endtabs %} + + + +## Built-in toolbar items + +By default, the inline toolbar renders the `send` item which allows users to send the prompt text. + +## Adding custom items + +You can use the `inlineToolbarSettings` property to add custom items for the inline toolbar in the Inline AI Assist. The custom items will be added with the existing built-in items in the inline toolbar. + +Each toolbar item object can include the following properties: + +| Property | Type | Default | Description | +|-------------|---------|----------|--------------------------------------------------------------------| +| `iconCss` | string | '' | Specifies the CSS class for the item's icon. | +| `type` | string | 'Button' | Supports three types of items: `Button`, `Separator`, and `Input`. | +| `text` | string | '' | Specifies the text label for the toolbar item. | +| `template` | string | '' | Specifies a custom template for the toolbar item. | +| `visible` | boolean | true | Specifies whether to show or hide the toolbar item. | +| `id` | string | '' | Specifies a unique identifier for the toolbar item. | +| `disabled` | boolean | false | Specifies whether the toolbar item is disabled and unselectable. | +| `tooltip` | string | '' | Specifies the tooltip text displayed on hover. | +| `cssClass` | string | '' | Specifies custom CSS classes for styling the toolbar item. | +| `align` | string | 'Left' | Specifies the alignment of the toolbar item (Left, Center, Right). | +| `tabIndex` | number | -1 | Specifies the tab order for keyboard navigation. | + +Below sample demonstrates the usage of custom toolbar items in Inline Assist control. + +{% tabs %} +{% highlight razor tabtitle="razor" %} + +```razor +@using Syncfusion.Blazor.InteractiveChat +@using Syncfusion.Blazor.Buttons + + + +Inline AI Assist component provides intelligent text processing capabilities that enhance user productivity. It leverages advanced natural language processing to understand context and deliver precise suggestions. Users can seamlessly integrate AI-powered features into their applications.
+With real-time response streaming and customizable prompts, developers can create interactive experiences. The component supports multiple response modes including inline editing and popup-based interactions.
"; + + private List{lastPrompt.Response}
"; + } + await inlineAssist!.HidePopupAsync(); + } + else if (args.Item.Label == "Discard") + { + await inlineAssist!.HidePopupAsync(); + } + } + + private async Task OnToolbarItemClickAsync(ToolbarItemClickEventArgs args) + { + // Your required actions + } + + private async Task OnSummarizeClick() + { + await inlineAssist.ShowPopupAsync(); + } +} +``` + +{% endhighlight %} +{% endtabs %} + + + +## Toolbar itemClick event + +The `itemClick` event is triggered when the inline toolbar item is clicked. + +```cshtml + +Inline AI Assist component provides intelligent text processing capabilities that enhance user productivity. It leverages advanced natural language processing to understand context and deliver precise suggestions. Users can seamlessly integrate AI-powered features into their applications.
+With real-time response streaming and customizable prompts, developers can create interactive experiences. The component supports multiple response modes including inline editing and popup-based interactions.
"; + + private async Task OnPromptRequestAsync(PromptRequestedEventArgs args) + { + await Task.Delay(1000); + string defaultResponse = "For real-time prompt processing, connect the Inline AI Assist component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration."; + await inlineAssist.UpdateResponseAsync(defaultResponse); + } + + private async Task OnItemSelectAsync(ResponseItemSelectEventArgs args) + { + if (args.Item.Label == "Accept") + { + var lastPrompt = inlineAssist?.Prompts.LastOrDefault(); + if (lastPrompt != null && !string.IsNullOrEmpty(lastPrompt.Response)) + { + editableContent = $"{lastPrompt.Response}
"; + } + await inlineAssist!.HidePopupAsync(); + } + else if (args.Item.Label == "Discard") + { + await inlineAssist!.HidePopupAsync(); + } + } + + private async Task OnAddResponseClickAsync() + { + await inlineAssist.ShowPopupAsync(); + await inlineAssist.UpdateResponseAsync("Dynamic response"); + } +} +``` + +{% endhighlight %} +{% endtabs %} + + + +## Executing prompt + +You can use the `executePrompt` method to execute the prompts dynamically in the Inline AI Assist. It accepts prompts as string values, which triggers the `promptRequest` event and performs the callback actions. + +{% tabs %} +{% highlight razor tabtitle="razor" %} + +```razor +@using Syncfusion.Blazor.InteractiveChat +@using Syncfusion.Blazor.Buttons + + + +Inline AI Assist component provides intelligent text processing capabilities that enhance user productivity. It leverages advanced natural language processing to understand context and deliver precise suggestions. Users can seamlessly integrate AI-powered features into their applications.
+With real-time response streaming and customizable prompts, developers can create interactive experiences. The component supports multiple response modes including inline editing and popup-based interactions.
"; + + private async Task OnPromptRequestAsync(PromptRequestedEventArgs args) + { + await Task.Delay(1000); + string defaultResponse = "For real-time prompt processing, connect the Inline AI Assist component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration."; + await inlineAssist.UpdateResponseAsync(defaultResponse); + } + + private async Task OnItemSelectAsync(ResponseItemSelectEventArgs args) + { + if (args.Item.Label == "Accept") + { + var lastPrompt = inlineAssist?.Prompts.LastOrDefault(); + if (lastPrompt != null && !string.IsNullOrEmpty(lastPrompt.Response)) + { + editableContent = $"{lastPrompt.Response}
"; + } + await inlineAssist!.HidePopupAsync(); + } + else if (args.Item.Label == "Discard") + { + await inlineAssist!.HidePopupAsync(); + } + } + + private async Task OnExecutePromptClickAsync() + { + await inlineAssist.ShowPopupAsync(); + await inlineAssist.ExecutePromptAsync("What is the current temperature?"); + } +} +``` + +{% endhighlight %} +{% endtabs %} + + + +## Showing popup + +You can use `showPopup` method to open the Inline AI Assist popup and optionally position it at specified coordinates. + +## Hiding popup + +You can use `hidePopup` method to close the Inline AI Assist popup. + +{% tabs %} +{% highlight razor tabtitle="razor" %} + +```razor +@using Syncfusion.Blazor.InteractiveChat +@using Syncfusion.Blazor.Buttons + + + +Inline AI Assist component provides intelligent text processing capabilities that enhance user productivity. It leverages advanced natural language processing to understand context and deliver precise suggestions. Users can seamlessly integrate AI-powered features into their applications.
+With real-time response streaming and customizable prompts, developers can create interactive experiences. The component supports multiple response modes including inline editing and popup-based interactions.
"; + + private async Task OnPromptRequestAsync(PromptRequestedEventArgs args) + { + await Task.Delay(1000); + string defaultResponse = "For real-time prompt processing, connect the Inline AI Assist component to your preferred AI service, such as OpenAI or Azure Cognitive Services. Ensure you obtain the necessary API credentials to authenticate and enable seamless integration."; + await inlineAssist.UpdateResponseAsync(defaultResponse); + } + + private async Task OnItemSelectAsync(ResponseItemSelectEventArgs args) + { + if (args.Item.Label == "Accept") + { + var lastPrompt = inlineAssist?.Prompts.LastOrDefault(); + if (lastPrompt != null && !string.IsNullOrEmpty(lastPrompt.Response)) + { + editableContent = $"{lastPrompt.Response}
"; + } + await inlineAssist!.HidePopupAsync(); + } + else if (args.Item.Label == "Discard") + { + await inlineAssist!.HidePopupAsync(); + } + } + + private async Task OnShowPopupClickAsync() + { + await inlineAssist.ShowPopupAsync(); + } + + private async Task OnHidePopupClickAsync() + { + await inlineAssist.HidePopupAsync(); + } +} +``` + +{% endhighlight %} +{% endtabs %} + + + +## Showing command popup + +Use `showCommandPopup` to open the command action popup; it only opens when the Inline AI Assist popup is already opened. + +## Hiding command popup + +You can use `hideCommandPopup` to close the command action popup in the Inline AI Assist control. + +{% tabs %} +{% highlight razor tabtitle="razor" %} + +```razor +@using Syncfusion.Blazor.InteractiveChat +@using Syncfusion.Blazor.Buttons + + + +Inline AI Assist component provides intelligent text processing capabilities that enhance user productivity. It leverages advanced natural language processing to understand context and deliver precise suggestions. Users can seamlessly integrate AI-powered features into their applications.
+With real-time response streaming and customizable prompts, developers can create interactive experiences. The component supports multiple response modes including inline editing and popup-based interactions.
"; + + private List{lastPrompt.Response}
"; + } + await inlineAssist!.HidePopupAsync(); + } + else if (args.Item.Label == "Discard") + { + await inlineAssist!.HidePopupAsync(); + } + } + + private async Task OnClosedAsync() + { + if (showPopup) + { + await inlineAssist.ShowPopupAsync(); + } + } + + private async Task OnShowCommandPopupClickAsync() + { + showPopup = true; + await inlineAssist.ShowPopupAsync(); + await inlineAssist.ShowCommandPopupAsync(); + } + + private async Task OnHideCommandPopupClickAsync() + { + showPopup = false; + await inlineAssist.HideCommandPopupAsync(); + } +} +``` +{% endhighlight %} +{% endtabs %} + + \ No newline at end of file diff --git a/blazor/inline-ai-assist/response-settings.md b/blazor/inline-ai-assist/response-settings.md new file mode 100644 index 0000000000..5092026327 --- /dev/null +++ b/blazor/inline-ai-assist/response-settings.md @@ -0,0 +1,124 @@ +--- +layout: post +title: Response actions in Blazor Inline AI Assist Control | Syncfusion +description: Checkout and learn about Response items with Blazor Inline AI Assist component in Blazor Server App and Blazor WebAssembly App. +platform: Blazor +control: Inline AI Assist +documentation: ug +--- + +# Response actions in ##Platform_Name## Inline AI Assist control + +You can render response action popup by using `items` property in the `e-inlineaiassist-responsesettings` tag helper. + +## Built-in response items + +By default, the response popup displays the built-in `accept` and `discard` items, allowing users to accept or discard the response. The response action popup is shown after a response is generated. This feature enables users to accept, discard, or perform custom actions on AI-generated responses. + +Built-in items appear by default and cannot be removed, but custom items can be added alongside them. + +## Custom response item configuration + +You can use the `responseSettings` property to add custom items for the response popup in Inline AI Assist. The custom items will be added with the existing built-in items in the response popup. The custom items will be displayed together with the existing built-in items in the response popup. + +Each response item object can include the following properties: + +| Property | Type | Default | Description | +|-------------|---------|---------|------------------------------------------------------------------| +| label | string | '' | Specifies the display label of the response item. | +| iconCss | string | '' | Specifies the CSS class for the item's icon. | +| disabled | boolean | false | Specifies whether the response item is disabled and unselectable.| +| groupBy | string | '' | Specifies the group category for organizing related items. | +| id | string | '' | Specifies a unique identifier for the response item. | +| tooltip | string | '' | Specifies the tooltip text displayed on hover. | + +## Response interactions + +The `itemSelect` event is triggered when an item is selected from the response popup in the Inline AI Assist control. + +The below example demonstrates the `ResponseSettings` property + +{% tabs %} +{% highlight razor tabtitle="razor" %} + +```razor +@using Syncfusion.Blazor.InteractiveChat +@using Syncfusion.Blazor.Buttons + + + +Inline AI Assist component provides intelligent text processing capabilities that enhance user productivity. It leverages advanced natural language processing to understand context and deliver precise suggestions. Users can seamlessly integrate AI-powered features into their applications.
+With real-time response streaming and customizable prompts, developers can create interactive experiences. The component supports multiple response modes including inline editing and popup-based interactions.
"; + + private List{lastPrompt.Response}
"; + } + await inlineAssist!.HidePopupAsync(); + } + else if (args.Item.Label == "Discard") + { + await inlineAssist!.HidePopupAsync(); + } + } + + private async Task OnSummarizeClick() + { + await inlineAssist.ShowPopupAsync(); + } +} +``` + +{% endhighlight %} +{% endtabs %} + + + +## See Also + +- [Command Settings](./command-settings.md) +- [Inline Toolbar](./inline-toolbar.md) +- [Events Documentation](./events.md) \ No newline at end of file diff --git a/blazor/inline-ai-assist/templates.md b/blazor/inline-ai-assist/templates.md new file mode 100644 index 0000000000..213e24daac --- /dev/null +++ b/blazor/inline-ai-assist/templates.md @@ -0,0 +1,252 @@ +--- +layout: post +title: Templates in Blazor Inline AI Assist Control | Syncfusion +description: Checkout and learn about Templates with Blazor Inline AI Assist component in Blazor Server App and Blazor WebAssembly App. +platform: Blazor +control: Inline AI Assist +documentation: ug +--- + +# Templates in Blazor Inline AI Assist control + +The Inline AI Assist provides several template options to customize the response and footer items. + +## Editor template + +You can use the `editorTemplate` property to customize the default footer area and manage prompt request actions in the Inline AI Assist. This allows users to create unique footers that meet their specific needs. + +{% tabs %} +{% highlight razor tabtitle="razor" %} + +```cshtml +@using Syncfusion.Blazor.InteractiveChat +@using Syncfusion.Blazor.Buttons + + + +Inline AI Assist component provides intelligent text processing capabilities that enhance user productivity. + It leverages advanced natural language processing to understand context and deliver precise suggestions. + Users can seamlessly integrate AI-powered features into their applications.
+With real-time response streaming and customizable prompts, developers can create interactive experiences. + The component supports multiple response modes including inline editing and popup-based interactions.
+{lastPrompt.Response}
'"); + } + await inlineAssist.HidePopupAsync(); + } + else if (args.Item.Label == "Discard") + { + await inlineAssist.HidePopupAsync(); + } + } +} +``` + +{% endhighlight %} +{% endtabs %} + + + +## Response template + +You can use the `responseTemplate` property to customize response items within the Inline AI Assist. The template context includes the `response` and `toolbarItems` values. + +```cshtml +@using Syncfusion.Blazor.InteractiveChat +@using Syncfusion.Blazor.Buttons + + + +Inline AI Assist component provides intelligent text processing capabilities that enhance user productivity. + It leverages advanced natural language processing to understand context and deliver precise suggestions. + Users can seamlessly integrate AI-powered features into their applications.
+With real-time response streaming and customizable prompts, developers can create interactive experiences. + The component supports multiple response modes including inline editing and popup-based interactions.
+{lastPrompt.Response}
'"); + } + await inlineAssist.HidePopupAsync(); + } + else if (args.Item.Label == "Discard") + { + await inlineAssist.HidePopupAsync(); + } + } +} +``` + + \ No newline at end of file