Skip to content

Commit f6788d3

Browse files
Merge pull request #4559 from syncfusion-content/982586-Azure-ChatUI
982586: added UG for the Azure Open AI integration with the ChatUI component in the Core and MVC platform
2 parents 93ecd91 + 76be7ba commit f6788d3

File tree

17 files changed

+114
-95
lines changed

17 files changed

+114
-95
lines changed

ej2-asp-core-mvc/ai-assistview/EJ2_ASP.MVC/ai-integrations/openai-integration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ documentation: ug
1010

1111
# Integration of Azure Open AI With AI AssistView control
1212

13-
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 Angular applications.
13+
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 MVC applications.
1414

1515
## Getting Started With the AI AssistView control
1616

ej2-asp-core-mvc/ai-assistview/EJ2_ASP.NETCORE/ai-integrations/openai-integration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ documentation: ug
1010

1111
# Integration of Azure Open AI With AI AssistView control
1212

13-
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 Angular applications.
13+
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 Core applications.
1414

1515
## Getting Started With the AI AssistView control
1616

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
---
22
layout: post
3-
title: Open AI in ##Platform_Name## Chat UI Control | Syncfusion
4-
description: Checkout and learn about Integration of Open AI in Syncfusion ##Platform_Name## Chat UI control of Syncfusion Essential JS 2 and more.
3+
title: Azure Open AI in ##Platform_Name## Chat UI Control | Syncfusion
4+
description: Checkout and learn about Integration of Azure Open AI in Syncfusion ##Platform_Name## Chat UI control of Syncfusion Essential JS 2 and more.
55
platform: ej2-asp-core-mvc
6-
control: Open AI
6+
control: Azure Open AI
77
publishingplatform: ##Platform_Name##
88
documentation: ug
99
---
1010

11-
# Integration of Open AI With Chat UI component
11+
# Integration of Azure Open AI With Chat UI component
1212

13-
The Syncfusion Chat UI supports integration with (OpenAI)[https://platform.openai.com/docs/overview], enabling advanced conversational AI features in your Asp MVC applications.
13+
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 MVC applications.
1414

1515
## Getting Started With the Chat UI Component
1616

17-
Before integrating Open AI, ensure that the Syncfusion Chat UI control is correctly rendered in your MVC application:
17+
Before integrating Azure Open AI, ensure that the Syncfusion Chat UI control is correctly rendered in your MVC application:
1818
[ MVC Getting Started Guide](../getting-started)
1919

2020
## Prerequisites
2121

22-
* OpenAI account to generate an API key for accessing the `OpenAI` API
22+
* An Azure account with access to `Azure Open AI` services and a generated API key.
2323

2424
* Syncfusion Chat UI for MVC `Syncfusion.EJ2.MVC5` Install ASP.NET MVC package in the application.
2525

@@ -33,36 +33,40 @@ NuGet\Install-Package Syncfusion.EJ2.MVC5
3333

3434
```
3535

36-
Install the Open AI package in the application using the Package Manager Console.
36+
Install the Open AI and Azure Open AI package in the application using Package Manager Console.
3737

3838
```bash
3939

4040
NuGet\Install-Package OpenAI
41+
NuGet\Install-Package Azure.AI.OpenAI
42+
NuGet\Install-Package Azure.Core
4143

4244
```
4345

4446

4547
## Generate API Key
4648

47-
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.
49+
1. Log in to the [Azure Portal](https://portal.azure.com/#home) and navigate to your Azure Open AI resource.
4850

49-
2. Once logged in, click on your profile icon in the top-right corner and select `API Keys` from the dropdown menu.
51+
2. Under Resource Management, select Keys and Endpoint to retrieve your API key and endpoint URL.
5052

51-
3. Click the `+ Create new secret key` button. You’ll be prompted to name the key (optional). Confirm to generate the key.
53+
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.
5254

53-
4. Your API key will be displayed once. Copy it and store it securely, as it won’t be shown again.
55+
4. Store these values securely, as they will be used in your application.
5456

55-
> `Security Note`: Never commit the API key to version control. Use environment variables or a secret manager for production.
57+
> `Security Note`: Never expose your API key in client-side code for production applications. Use a server-side proxy or environment variables to manage sensitive information securely
5658
57-
## Integration Open AI with Chat UI
59+
## Integration Azure Open AI with Chat UI
5860

5961
You can add the below respective files in your application:
6062

61-
* Add your generated `API Key` at the line
63+
* Update the following configuration values with your Azure Open AI details:
6264

6365
```bash
6466

65-
const openaiApiKey = 'Place your API key here';
67+
string endpoint = "Your_Azure_OpenAI_Endpoint";
68+
string apiKey = "Your_Azure_OpenAI_API_Key";
69+
string deploymentName = "Your_Deployment_Name";
6670

6771
```
6872

@@ -75,12 +79,12 @@ const openaiApiKey = 'Place your API key here';
7579
{% endhighlight %}
7680
{% endtabs %}
7781

78-
![Open AI](../../images/openai.png)
82+
![Azure Open AI](../../images/openai.png)
7983

8084
## Run and Test
8185

8286
Run the application in the browser using the following command.
8387

8488
Build and run the app (Ctrl + F5).
8589

86-
Open `https://localhost:44321` to interact with your Open AI for dynamic response.
90+
Open `https://localhost:44321` to interact with your Azure Open AI for dynamic response.
Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
---
22
layout: post
3-
title: Open AI in ##Platform_Name## Chat UI Control | Syncfusion
4-
description: Checkout and learn about Integration of Open AI in Syncfusion ##Platform_Name## Chat UI control of Syncfusion Essential JS 2 and more.
3+
title: Azure Open AI in ##Platform_Name## Chat UI Control | Syncfusion
4+
description: Checkout and learn about Integration of Azure Open AI in Syncfusion ##Platform_Name## Chat UI control of Syncfusion Essential JS 2 and more.
55
platform: ej2-asp-core-mvc
6-
control: Open AI
6+
control: Azure Open AI
77
publishingplatform: ##Platform_Name##
88
documentation: ug
99
---
1010

11-
# Integration of Open AI With Chat UI component
11+
# Integration of Azure Open AI With Chat UI component
1212

13-
The Syncfusion Chat UI supports integration with (OpenAI)[https://platform.openai.com/docs/overview], enabling advanced conversational AI features in your Asp Core applications.
13+
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 Core applications.
1414

1515
## Getting Started With the Chat UI Component
1616

17-
Before integrating Open AI, ensure that the Syncfusion Chat UI control is correctly rendered in your core application:
17+
Before integrating Azure Open AI, ensure that the Syncfusion Chat UI control is correctly rendered in your core application:
1818
[ Asp Core Getting Started Guide](../getting-started)
1919

2020
## Prerequisites
2121

22-
* OpenAI account to generate an API key for accessing the `OpenAI` API
22+
* An Azure account with access to `Azure Open AI` services and a generated API key.
2323

2424
* Syncfusion Chat UI for Core `Syncfusion.EJ2.AspNet.Core` Install ASP.NET Core package in the application.
2525

@@ -32,36 +32,40 @@ Install the Syncfusion ASP.NET Core package in the application using the Package
3232
NuGet\Install-Package Syncfusion.EJ2.AspNet.Core
3333
```
3434

35-
Install the Open AI package in the application using the Package Manager Console.
35+
Install the Open AI and Azure Open AI package in the application using Package Manager Console.
3636

3737
```bash
3838

3939
NuGet\Install-Package OpenAI
40+
NuGet\Install-Package Azure.AI.OpenAI
41+
NuGet\Install-Package Azure.Core
4042

4143
```
4244

4345

44-
## Generate API Key
46+
## Configure Azure Open AI
4547

46-
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+
1. Log in to the [Azure Portal](https://portal.azure.com/#home) and navigate to your Azure Open AI resource.
4749

48-
2. Once logged in, click on your profile icon in the top-right corner and select `API Keys` from the dropdown menu.
50+
2. Under Resource Management, select Keys and Endpoint to retrieve your API key and endpoint URL.
4951

50-
3. Click the `+ Create new secret key` button. You’ll be prompted to name the key (optional). Confirm to generate the key.
52+
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.
5153

52-
4. Your API key will be displayed once. Copy it and store it securely, as it won’t be shown again.
54+
4. Store these values securely, as they will be used in your application.
5355

54-
> `Security Note`: Never commit the API key to version control. Use environment variables or a secret manager for production.
56+
> `Security Note`: Never expose your API key in client-side code for production applications. Use a server-side proxy or environment variables to manage sensitive information securely.
5557
56-
## Integration Open AI with Chat UI
58+
## Integration Azure Open AI with Chat UI
5759

5860
You can add the below respective files in your application:
5961

60-
* Add your generated `API Key` at the line
62+
* Update the following configuration values with your Azure Open AI details:
6163

6264
```bash
6365

64-
const openaiApiKey = 'Place your API key here';
66+
string endpoint = "Your_Azure_OpenAI_Endpoint";
67+
string apiKey = "Your_Azure_OpenAI_API_Key";
68+
string deploymentName = "Your_Deployment_Name";
6569

6670
```
6771

@@ -74,12 +78,12 @@ const openaiApiKey = 'Place your API key here';
7478
{% endhighlight %}
7579
{% endtabs %}
7680

77-
![Open AI](../../images/openai.png)
81+
![Azure Open AI](../../images/openai.png)
7882

7983
## Run and Test
8084

8185
Run the application in the browser using the following command.
8286

8387
Build and run the app (Ctrl + F5).
8488

85-
Open `https://localhost:44321` to interact with your Open AI for dynamic response.
89+
Open `https://localhost:44321` to interact with your Azure Open AI for dynamic response.
-8.56 KB
Loading

ej2-asp-core-mvc/code-snippet/ai-assistview/ai-integrations/open-ai/openaicore.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public async Task<IActionResult> OnPostGetAIResponse([FromBody] PromptRequest re
3939
return BadRequest("Prompt cannot be empty.");
4040
}
4141

42-
string endpoint = ""; // Replace with your Azure OpenAI endpoint
43-
string apiKey = ""; // Replace with your Azure OpenAI API key
44-
string deploymentName = ""; // Replace with your Azure OpenAI deployment name (e.g., gpt-4o-mini)
42+
string endpoint = "Your_Azure_OpenAI_Endpoint"; // Replace with your Azure OpenAI endpoint
43+
string apiKey = "YOUR_AZURE_OPENAI_API_KEY"; // Replace with your Azure OpenAI API key
44+
string deploymentName = "YOUR_DEPLOYMENT_NAME"; // Replace with your Azure OpenAI deployment name (e.g., gpt-4o-mini)
4545

4646
var credential = new AzureKeyCredential(apiKey);
4747
var client = new AzureOpenAIClient(new Uri(endpoint), credential);

ej2-asp-core-mvc/code-snippet/ai-assistview/ai-integrations/open-ai/openaimvc.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ public async Task<IActionResult> GetAIResponse([FromBody] PromptRequest request)
4141
}
4242

4343
// Azure OpenAI configuration
44-
string endpoint = ""; // Replace with your Azure OpenAI endpoint
45-
string apiKey = ""; // Replace with your Azure OpenAI API key
46-
string deploymentName = ""; // Replace with your Azure OpenAI deployment name (e.g., gpt-4o-mini)
44+
string endpoint = "Your_Azure_OpenAI_Endpoint"; // Replace with your Azure OpenAI endpoint
45+
string apiKey = "YOUR_AZURE_OPENAI_API_KEY"; // Replace with your Azure OpenAI API key
46+
string deploymentName = "YOUR_DEPLOYMENT_NAME"; // Replace with your Azure OpenAI deployment name (e.g., gpt-4o-mini)
4747

4848
var credential = new AzureKeyCredential(apiKey);
4949
var client = new AzureOpenAIClient(new Uri(endpoint), credential);

ej2-asp-core-mvc/code-snippet/chat-ui/ai-integrations/Asp.net-MVC/gemini/gemini.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public async Task<IActionResult> GetAIResponse([FromBody] PromptRequest request)
3737
}
3838
string apiKey = ""; // Replace with your key
3939
var googleAI = new GoogleAI(apiKey: apiKey);
40-
var model = googleAI.GenerativeModel(model: Model.Gemini15Flash);
40+
var model = googleAI.GenerativeModel(model: Model.Gemini15Flash); // Replace Your Model Name Here
4141

4242
var responseText = await model.GenerateContent(request.Prompt);
4343
if (string.IsNullOrEmpty(responseText?.Text))

ej2-asp-core-mvc/code-snippet/chat-ui/ai-integrations/Asp.net-MVC/gemini/razor

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@using Newtonsoft.Json
33
@using Syncfusion.EJ2
44
@{
5-
ViewData["Title"] = "AI Chat with Gemini AI";
5+
ViewData["Title"] = "AI Chat with Gemini AI";
66
}
77

88
<div class="chatui-container" style="height:380px; width:450px">
@@ -30,8 +30,7 @@
3030
}
3131
}
3232

33-
function onMessageSend(args) {
34-
setTimeout(async () => {
33+
async function onMessageSend(args) {
3534
chatObj.typingUsers = [aiModel];
3635
let responseText = '';
3736
try {
@@ -58,7 +57,6 @@
5857
} finally {
5958
chatObj.typingUsers = [];
6059
}
61-
}, 500);
6260
}
6361
</script>
6462

ej2-asp-core-mvc/code-snippet/chat-ui/ai-integrations/Asp.net-MVC/openai/openai.cs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
using OpenAI.Chat;
77
using Syncfusion.EJ2.InteractiveChat;
88
using Newtonsoft.Json;
9-
9+
using Azure.AI.OpenAI;
10+
using Azure;
1011
private readonly ILogger<HomeController> _logger;
1112
public List<ToolbarItemModel> HeaderToolbar { get; set; } = new List<ToolbarItemModel>();
1213
public HomeController(ILogger<HomeController> logger)
@@ -19,7 +20,7 @@ public IActionResult Index()
1920
HeaderToolbar.Add(new ToolbarItemModel { align = "Right", iconCss = "e-icons e-refresh", tooltip = "Refresh" });
2021
ViewBag.HeaderToolbar = HeaderToolbar;
2122
var currentUser = new ChatUIUser { Id = "user1", User = "You" };
22-
var aiUser = new ChatUIUser { Id = "ai", User = "Open AI" };
23+
var aiUser = new ChatUIUser { Id = "ai", User = "Azure Open AI" };
2324
ViewBag.CurrentUser = currentUser;
2425
ViewBag.AIUser = aiUser;
2526

@@ -37,22 +38,32 @@ public async Task<IActionResult> GetAIResponse([FromBody] PromptRequest request)
3738
_logger.LogWarning("Prompt is null or empty.");
3839
return BadRequest("Prompt cannot be empty.");
3940
}
40-
string apiKey = ""; // Replace with your OpenAI API key
41-
var openAiClient = new OpenAIClient(apiKey);
42-
var chatClient = openAiClient.GetChatClient("gpt-4o-mini"); // Use your preferred model, e.g., "gpt-4o-mini" or "gpt-4o"
43-
OpenAI.Chat.ChatCompletion completion = await chatClient.CompleteChatAsync(request.Prompt);
44-
string responseText = completion.Content[0].Text;
41+
string endpoint = "Your_Azure_OpenAI_Endpoint"; // Replace with your Azure OpenAI endpoint
42+
string apiKey = "YOUR_AZURE_OPENAI_API_KEY"; // Replace with your Azure OpenAI API key
43+
string deploymentName = "YOUR_DEPLOYMENT_NAME"; // Replace with your Azure OpenAI deployment name (e.g., gpt-4o-mini)
44+
45+
var credential = new AzureKeyCredential(apiKey);
46+
var client = new AzureOpenAIClient(new Uri(endpoint), credential);
47+
var chatClient = client.GetChatClient(deploymentName);
48+
49+
var chatCompletionOptions = new ChatCompletionOptions();
50+
var completion = await chatClient.CompleteChatAsync(
51+
new[] { new UserChatMessage(request.Prompt) },
52+
chatCompletionOptions
53+
);
54+
55+
string responseText = completion.Value.Content[0].Text;
4556
if (string.IsNullOrEmpty(responseText))
4657
{
47-
_logger.LogError("OpenAI API returned no text.");
48-
return BadRequest("No response from OpenAI.");
58+
_logger.LogError("Azure OpenAI API returned no text.");
59+
return BadRequest("No response from Azure Open AI.");
4960
}
50-
_logger.LogInformation("OpenAI response received: {Response}", responseText);
61+
_logger.LogInformation("Azure OpenAI response received: {Response}", responseText);
5162
return Json(responseText);
5263
}
5364
catch (Exception ex)
5465
{
55-
_logger.LogError("Exception in OpenAI call: {Message}", ex.Message);
66+
_logger.LogError("Exception in Azure Open AI call: {Message}", ex.Message);
5667
return BadRequest($"Error generating response: {ex.Message}");
5768
}
5869
}

0 commit comments

Comments
 (0)