Skip to content

Commit 952c067

Browse files
Merge branch 'development' into 983366-dashboard
2 parents 13b390e + e1969cb commit 952c067

File tree

246 files changed

+3807
-3705
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

246 files changed

+3807
-3705
lines changed

blazor-toc.html

Lines changed: 110 additions & 156 deletions
Large diffs are not rendered by default.

blazor/ai-assistview/accessibility.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ control: AI AssistView
77
documentation: ug
88
---
99

10-
# Accessibility in Blazor AI AssistView component
10+
# Accessibility in the Blazor AI AssistView component
1111

12-
The Blazor AI AssistView component followed the accessibility guidelines and standards, including [ADA](https://www.ada.gov/), [Section 508](https://www.section508.gov/), [WCAG 2.2](https://www.w3.org/TR/WCAG22/) standards, and [WCAG roles](https://www.w3.org/TR/wai-aria/#roles) that are commonly used to evaluate accessibility.
12+
The Blazor AI AssistView component follows established accessibility guidelines and standards, including [ADA](https://www.ada.gov/), [Section 508](https://www.section508.gov/), [WCAG 2.2](https://www.w3.org/TR/WCAG22/) standards, and [WCAG roles](https://www.w3.org/TR/wai-aria/#roles) that are commonly used to evaluate accessibility.
1313

14-
The accessibility compliance for the Blazor AI AssistView component is outlined below.
14+
The component’s accessibility compliance is summarized below.
1515

1616
| Accessibility Criteria | Compatibility |
1717
| -- | -- |
@@ -45,7 +45,7 @@ The following ARIA attributes are used in the AI AssistView component:
4545
| ------------ | ----------------------- |
4646
| `role=button` | Indicates that the element is clickable and triggers an action when activated by the user. |
4747
| `role=toolbar` | Specifies that the element is a toolbar. |
48-
| `aria-label` | Defines a string value that labels an interactive element for accessibility. |
48+
| `aria-label` | Provides an accessible name for interactive elements (for example, buttons, toolbar, or prompt input). |
4949
| `aria-orientation` | Specifies the orientation of the toolbar. |
5050
| `aria-disabled` | Indicates whether the toolbar or element is currently disabled and not interactive. |
5151
| `aria-multiline` | Indicates that a textbox accepts multiple lines of input or only a single line. |
@@ -57,19 +57,19 @@ The following keyboard shortcuts are supported by the AI AssistView component.
5757
| Windows | Mac | Actions |
5858
| --- | --- | --- |
5959
| <kbd>Enter</kbd> | <kbd>Enter</kbd> | Select the focused item. |
60-
| <kbd>Tab</kbd> | <kbd>Tab</kbd> | Moves focus forward through the interactive elements. |
61-
| <kbd>Shift</kbd> + <kbd>Tab</kbd> | <kbd>⇧</kbd> + <kbd>Tab</kbd> | Moves focus backward through the interactive elements. |
62-
<b>AI AssistView Toolbars</b>|||
63-
| <kbd>←</kbd> | <kbd>←</kbd> | Focuses the previous toolbar element. |
64-
| <kbd>→</kbd> | <kbd>→</kbd> | Focuses the next toolbar element. |
60+
| <kbd>Tab</kbd> | <kbd>Tab</kbd> | Move focus forward through interactive elements. |
61+
| <kbd>Shift</kbd> + <kbd>Tab</kbd> | <kbd>⇧</kbd> + <kbd>Tab</kbd> | Move focus backward through interactive elements. |
62+
<b>AI AssistView toolbar</b>|||
63+
| <kbd>←</kbd> | <kbd>←</kbd> | Move focus to the previous toolbar element. |
64+
| <kbd>→</kbd> | <kbd>→</kbd> | Move focus to the next toolbar element. |
6565
| <kbd>Enter</kbd> / <kbd>Space</kbd> | <kbd>Enter</kbd> / <kbd>Space</kbd> | Select the focused item or activate the selected option. |
66-
| <kbd>Home</kbd> | <kbd>Home</kbd> | Moves focus to the first toolbar element. |
67-
| <kbd>End</kbd> | <kbd>End</kbd> | Moves focus to the last toolbar element. |
66+
| <kbd>Home</kbd> | <kbd>Home</kbd> | Move focus to the first toolbar element. |
67+
| <kbd>End</kbd> | <kbd>End</kbd> | Move focus to the last toolbar element. |
6868

6969
## Ensuring accessibility
7070

7171
The Blazor AI AssistView component's accessibility levels are ensured through an [axe-core](https://www.nuget.org/packages/Deque.AxeCore.Playwright) with playwright tests.
7272

7373
## See also
7474

75-
* [Accessibility in Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor components](https://blazor.syncfusion.com/documentation/common/accessibility)
75+
* Accessibility in Syncfusion<sup style="font-size:70%">&reg;</sup> Blazor components (https://blazor.syncfusion.com/documentation/common/accessibility)

blazor/ai-assistview/ai-integrations/gemini-integration.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@ documentation: ug
99

1010
# Integration of Gemini AI With Blazor AI AssistView component
1111

12-
The Syncfusion AI AssistView supports integration with [Gemini](https://ai.google.dev/gemini-api/docs/quickstart), enabling advanced conversational AI features in your applications.
12+
The Syncfusion AI AssistView supports integration with [Gemini](https://ai.google.dev/gemini-api/docs/quickstart), enabling advanced conversational AI features in applications.
1313

1414
## Prerequisites
1515

16-
* Google account to generate API key on accessing `Gemini AI`
17-
* Syncfusion AI AssistView for Blazor `Syncfusion.Blazor.InteractiveChat` installed in your project.
16+
* Google account to generate an API key for accessing Gemini AI
17+
* Syncfusion AI AssistView for Blazor package (Syncfusion.Blazor.InteractiveChat) installed in the project
18+
* Markdig package available in the project for Markdown-to-HTML conversion (required by the sample code)
1819

1920
## Getting Started with the AI AssistView Component
2021

21-
Before integrating Gemini AI, ensure that the Syncfusion AI AssistView is correctly rendered in your application:
22+
Before integrating Gemini AI, ensure that the Syncfusion AI AssistView renders correctly in the application and that prerequisites are met:
2223

23-
[ Blazor Getting Started Guide](../getting-started)
24+
[Blazor Getting Started Guide](../getting-started)
2425

2526
## Install Dependencies
2627

@@ -42,19 +43,19 @@ Install-Package Mscc.GenerativeAI
4243

4344
## Generate API Key
4445

45-
1. Go to [Google AI Studio](https://aistudio.google.com/app/apikey) and sign in with your Google account. If you don’t have one, create a new account.
46+
1. Go to [Google AI Studio](https://aistudio.google.com/app/apikey) and sign in with a Google account. Create a new account if needed.
4647

47-
2. Once logged in, click on `Get API Key` from the left-hand menu or the top-right corner of the dashboard.
48+
2. Select Get API Key from the left menu or the top-right of the dashboard.
4849

49-
3. Click the `Create API Key` button. You’ll be prompted to either select an existing Google Cloud project or create a new one. Choose the appropriate option and proceed.
50+
3. Choose Create API Key. Select an existing Google Cloud project or create a new one, then proceed.
5051

51-
4. After selecting or creating a project, your API key will be generated and displayed. Copy the key and store it securely, as it will only be shown once.
52+
4. After creating or selecting a project, an API key is generated and displayed. Copy the key and store it securely, as it may be shown only once.
5253

53-
> `Security Note`: Never commit the API key to version control. Use environment variables or a secret manager for production.
54+
> Security note: Do not commit API keys to version control. Use environment variables, a secret manager, or a server-side proxy in production.
5455
5556
## Integration Gemini AI with AI AssistView
5657

57-
* Add your generated `API Key` at the line
58+
* Add the generated API key in the following line.
5859

5960
```bash
6061

@@ -128,4 +129,4 @@ const string GeminiApiKey = 'Place your API key here';
128129
{% endhighlight %}
129130
{% endtabs %}
130131

131-
![Blazor AI AssistView Gemini Integration](./images/gemini-integration.png)
132+
![Blazor AI AssistView Gemini Integration](../images/gemini-integration.png)
Lines changed: 157 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,80 @@
11
---
22
layout: post
3-
title: Open AI Integration with Blazor AI AssistView Component | Syncfusion
4-
description: Checkout and learn about Open AI integration with Blazor AI AssistView component in Blazor WebAssembly Application.
3+
title: Azure Open AI with Blazor AI AssistView Component | Syncfusion
4+
description: Checkout and learn about Azure Open AI with Blazor AI AssistView component in Blazor WebAssembly Application.
55
platform: Blazor
66
control: AI AssistView
77
documentation: ug
88
---
99

10-
# Integration of Open AI With Blazor AI AssistView component
10+
# Integration of Azure OpenAI With Blazor AI AssistView component
1111

12-
The Syncfusion AI AssistView supports integration with [OpenAI](https://platform.openai.com/docs/overview), enabling advanced conversational AI features in your applications.
12+
The Syncfusion AI AssistView supports integration with [Azure Open AI](https://microsoft.github.io/PartnerResources/skilling/ai-ml-academy/resources/openai), enabling advanced conversational AI features in your applications.
1313

1414
## Prerequisites
1515

16-
* OpenAI account to generate an API key for accessing the `OpenAI` API
17-
* Syncfusion AI AssistView for Blazor `Syncfusion.Blazor.InteractiveChat` installed in your project.
16+
- An Azure account with access to `Azure Open AI` services and a generated API key.
17+
- Syncfusion AI AssistView for Blazor `Syncfusion.Blazor.InteractiveChat` installed in the project
1818

1919
## Getting Started with the AI AssistView Component
2020

21-
Before integrating Open AI, ensure that the Syncfusion AI AssistView is correctly rendered in your application:
21+
Before integrating Azure OpenAI, ensure the Syncfusion AI AssistView component renders correctly in the application:
2222

23-
[ Blazor Getting Started Guide](../getting-started)
23+
[Blazor Getting Started Guide](../getting-started)
2424

2525
## Install Dependencies
2626

2727
Install the Syncfusion Blazor package in the application.
2828

2929
```bash
3030

31-
Install-Package Syncfusion.Blazor.InteractiveChat
31+
Nuget\Install-Package Syncfusion.Blazor.InteractiveChat
3232

3333
```
3434

35-
Install the Open AI AI package in the application.
35+
Install the `Open AI` and `Markdig` nuget packages in the application.
3636

3737
```bash
3838

39-
Install-Package OpenAI
39+
NuGet\Install-Package OpenAI
40+
NuGet\Install-Package Azure.AI.OpenAI
41+
NuGet\Install-Package Azure.Core
42+
Nuget\Install-Package Markdig
4043

4144
```
4245

43-
## Generate API Key
46+
Note: The sample below uses HttpClient directly and does not require the Azure/OpenAI SDKs.
4447

45-
1. Go to [Open AI](https://platform.openai.com/docs/overview) and sign in with your Google account. If you don’t have one, create a new account.
48+
## Configure Azure Open AI
4649

47-
2. Once logged in, click on your profile icon in the top-right corner and select `API Keys` from the dropdown menu.
50+
1. Log in to the [Azure Portal](https://portal.azure.com/#home) and navigate to your Azure Open AI resource.
4851

49-
3. Click the `+ Create new secret key` button. You’ll be prompted to name the key (optional). Confirm to generate the key.
52+
2. Under Resource Management, select Keys and Endpoint to retrieve your API key and endpoint URL.
5053

51-
4. Your API key will be displayed once. Copy it and store it securely, as it won’t be shown again.
54+
3. Copy the API key, endpoint, and deployment name (e.g., gpt-4o-mini). Ensure the API version (e.g., 2024-07-01-preview) matches your resource configuration.
5255

53-
> `Security Note`: Never commit the API key to version control. Use environment variables or a secret manager for production.
56+
4. Store these values securely, as they will be used in your application.
5457

55-
## Integration Open AI with AI AssistView
58+
> `Security Note`: expose your API key in client-side code for production applications. Use a server-side proxy or environment variables to manage sensitive information securely.
5659
57-
* Add your generated `API Key` at the line
60+
## Integration Azure OpenAI with AI AssistView
5861

59-
```bash
62+
- Configure your Azure OpenAI endpoint, API key, and deployment name in your **Program.cs** (or using your preferred configuration mechanism).
6063

61-
const string openaiApiKey = 'Place your API key here';
64+
- Register the service for dependency injection.
6265

63-
```
66+
- Inject and use the service in your Razor component.
6467

6568
{% tabs %}
66-
{% highlight razor %}
69+
{% highlight c# tabtitle="razor" %}
70+
71+
@using AIAssistView_AzureAI.Components.Services
72+
@using Syncfusion.Blazor.InteractiveChat
73+
@using Syncfusion.Blazor.Navigations
74+
@inject AzureOpenAIService OpenAIService
6775

68-
<div class="aiassist-container" style="height: 350px; width: 650px;">
69-
<SfAIAssistView @ref="sfAIAssistView" ID="aiAssistView" PromptSuggestions="@promptSuggestions" PromptRequested="@OnPromptRequest">
76+
<div class="aiassist-container" style="height: 450px; width: 650px;">
77+
<SfAIAssistView @ref="assistView" ID="aiAssistView" PromptSuggestions="@promptSuggestions" PromptRequested="@PromptRequest">
7078
<AssistViews>
7179
<AssistView>
7280
<BannerTemplate>
@@ -86,47 +94,150 @@ const string openaiApiKey = 'Place your API key here';
8694
</div>
8795

8896
@code {
89-
private SfAIAssistView sfAIAssistView = new SfAIAssistView();
97+
private SfAIAssistView assistView;
98+
private string finalResponse { get; set; }
9099
private List<string> promptSuggestions = new List<string>
91100
{
92101
"What are the best tools for organizing my tasks?",
93102
"How can I maintain work-life balance effectively?"
94103
};
95-
private string openaiApiKey = "";
96-
private async Task OnPromptRequest(AssistViewPromptRequestedEventArgs args)
104+
105+
private async Task PromptRequest(AssistViewPromptRequestedEventArgs args)
97106
{
107+
// Reset the response for this prompt
108+
var lastIdx = assistView.Prompts.Count - 1;
109+
assistView.Prompts[lastIdx].Response = string.Empty;
110+
finalResponse = string.Empty;
98111
try
99112
{
100-
var openAiClient = new OpenAIClient(openaiApiKey);
101-
var chatClient = openAiClient.GetChatClient("gpt-4o-mini");
102-
103-
OpenAI.Chat.ChatCompletion completion = await chatClient.CompleteChatAsync(args.Prompt);
104-
string responseText = completion.Content[0].Text;
105-
var pipeline = new MarkdownPipelineBuilder()
106-
.UseAdvancedExtensions()
107-
.UsePipeTables()
108-
.UseTaskLists()
109-
.Build();
110-
// Add the response to the AIAssistView
111-
await Task.Delay(1000); // Simulate delay as in original code
112-
args.Response = Markdown.ToHtml(responseText, pipeline);
113+
await foreach (var chunk in OpenAIService.GetChatResponseStreamAsync(args.Prompt))
114+
{
115+
await UpdateResponse(args, chunk);
116+
}
117+
118+
args.Response = finalResponse;
113119
}
114120
catch (Exception ex)
115121
{
116-
Console.WriteLine($"Error fetching Open AI response: {ex.Message}");
117-
await Task.Delay(1000);
118-
args.Response = "⚠️ Something went wrong while connecting to the AI service. Please check your API key or try again later.";
122+
args.Response = $"Error: {ex.Message}";
119123
}
120124
}
121125

126+
private async Task UpdateResponse(AssistViewPromptRequestedEventArgs args, string response)
127+
{
128+
var lastIdx = assistView.Prompts.Count - 1;
129+
await Task.Delay(10); // Small delay for UI updates
130+
assistView.Prompts[lastIdx].Response += response.Replace("\n", "<br>");
131+
finalResponse = assistView.Prompts[lastIdx].Response;
132+
StateHasChanged();
133+
}
134+
122135
private void ToolbarItemClicked(AssistViewToolbarItemClickedEventArgs args)
123136
{
124-
sfAIAssistView.Prompts.Clear();
137+
assistView.Prompts.Clear();
125138
StateHasChanged();
126139
}
127140
}
128141

142+
{% endhighlight %}
143+
{% highlight c# tabtitle="cs" %}
144+
145+
using System.Text.Json;
146+
using Markdig;
147+
using System.Text.RegularExpressions;
148+
149+
namespace AIAssistView_AzureAI.Components.Services
150+
{
151+
public class AzureOpenAIService
152+
{
153+
private readonly HttpClient _httpClient;
154+
private readonly string _endpoint;
155+
private readonly string _apiKey;
156+
private readonly string _deploymentName;
157+
158+
public AzureOpenAIService(HttpClient httpClient, string endpoint, string apiKey, string deploymentName)
159+
{
160+
_httpClient = httpClient;
161+
_endpoint = endpoint;
162+
_apiKey = apiKey;
163+
_deploymentName = deploymentName;
164+
}
165+
166+
public async IAsyncEnumerable<string> GetChatResponseStreamAsync(string prompt)
167+
{
168+
var request = new
169+
{
170+
messages = new[] { new { role = "user", content = prompt } },
171+
max_tokens = 500,
172+
};
173+
174+
var url = $"{_endpoint}/openai/deployments/{_deploymentName}/chat/completions?api-version=2024-02-15-preview";
175+
_httpClient.DefaultRequestHeaders.Add("api-key", _apiKey);
176+
177+
Stream responseStream = null;
178+
List<string> results = new List<string>();
179+
180+
try
181+
{
182+
var response = await _httpClient.PostAsJsonAsync(url, request);
183+
184+
if (response.IsSuccessStatusCode)
185+
{
186+
responseStream = await response.Content.ReadAsStreamAsync();
187+
using var jsonDocument = JsonDocument.Parse(responseStream);
188+
var choices = jsonDocument.RootElement.GetProperty("choices");
189+
if (choices.GetArrayLength() > 0)
190+
{
191+
var content = choices[0].GetProperty("message").GetProperty("content").GetString();
192+
var htmlContent = Markdown.ToHtml(content);
193+
htmlContent = Regex.Replace(htmlContent, @"\s+", " ").Trim();
194+
// Collect each character to the results list before yielding
195+
foreach (var chunk in htmlContent)
196+
{
197+
results.Add(chunk.ToString());
198+
}
199+
}
200+
else
201+
{
202+
results.Add("Error: No choices returned in the response.");
203+
}
204+
}
205+
else
206+
{
207+
var error = await response.Content.ReadAsStringAsync();
208+
results.Add($"Error: {error}");
209+
}
210+
}
211+
catch (Exception ex)
212+
{
213+
// Collect the error message to be yielded later
214+
results.Add($"Error: {ex.Message}");
215+
}
216+
finally
217+
{
218+
if (responseStream != null)
219+
{
220+
responseStream.Dispose();
221+
}
222+
}
223+
224+
// Now yield each collected result
225+
foreach (var result in results)
226+
{
227+
yield return result;
228+
}
229+
}
230+
}
231+
}
232+
233+
{% endhighlight %}
234+
{% highlight c# tabtitle="Server(~/_Program.cs)" %}
235+
236+
var endpoint = "https://azure-testresource.openai.azure.com";
237+
var apiKey = "<Your API Key>"; // Replace with your API key;
238+
var deploymentName = "gpt-4o-mini";
239+
129240
{% endhighlight %}
130241
{% endtabs %}
131242

132-
![Blazor AI AssistView Open AI Integration](./images/openai-integration.png)
243+
![Blazor AI AssistView Azure Open AI Integration](../images/openai-integration.png)

0 commit comments

Comments
 (0)