Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions CS/console-ai-extension/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,23 @@ static void Main(string[] args)

public class SampleAITextModifier
{
//Modify the following lines to obtain and pass your personal Azure OpenAI credentails to the Register* method.
string AzureOpenAIEndpoint { get { return Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT"); } }
string AzureOpenAIKey { get { return Environment.GetEnvironmentVariable("AZURE_OPENAI_APIKEY"); } }
string DeploymentName { get { return Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENTNAME"); } }

AIExtensionsContainerDefault defaultAIContainer;

public SampleAITextModifier()
{
IChatClient client = new AzureOpenAIClient(new Uri(AzureOpenAIEndpoint),
new System.ClientModel.ApiKeyCredential(AzureOpenAIKey)).GetChatClient(DeploymentName).AsIChatClient();
//Modify the following lines to obtain and pass your personal Azure OpenAI credentails to the Register* method.
string azureOpenAIEndpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
if (string.IsNullOrEmpty(azureOpenAIEndpoint))
azureOpenAIEndpoint = "https://api.devexpress.com/demo-openai";//DevExpress demo proxy-server
string azureOpenAIKey = Environment.GetEnvironmentVariable("AZURE_OPENAI_APIKEY");
if (string.IsNullOrEmpty(azureOpenAIKey))
azureOpenAIKey = "DEMO";//Demo key
string deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENTNAME");
if (string.IsNullOrEmpty(deploymentName))
deploymentName = "demo";//DevExpress demo deployment

IChatClient client = new AzureOpenAIClient(new Uri(azureOpenAIEndpoint),
new System.ClientModel.ApiKeyCredential(azureOpenAIKey)).GetChatClient(deploymentName).AsIChatClient();
defaultAIContainer = AIExtensionsContainerConsole.CreateDefaultAIExtensionContainer(client);
}

Expand Down
20 changes: 13 additions & 7 deletions CS/winforms-ai-extensions/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ namespace WinForms_AI_Extensions
{
internal static class Program
{
//Modify the following lines to obtain and pass your personal Azure OpenAI credentails to the Register* method.
static string AzureOpenAIEndpoint { get { return Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT"); } }
static string AzureOpenAIKey { get { return Environment.GetEnvironmentVariable("AZURE_OPENAI_APIKEY"); } }
static string DeploymentName { get { return Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENTNAME"); } }

/// <summary>
/// The main entry point for the application.
/// </summary>
Expand All @@ -32,8 +27,19 @@ private static void RegisterDevExpressAI()
///To register Ollama
//OllamaChatClient ollamaChatClient = new OllamaChatClient("http://localhost:11434/", "llama3.1");

IChatClient azureOpenAIClient = new AzureOpenAIClient(new Uri(AzureOpenAIEndpoint),
new System.ClientModel.ApiKeyCredential(AzureOpenAIKey)).GetChatClient(DeploymentName).AsIChatClient(); ;
//Modify the following lines to obtain and pass your personal Azure OpenAI credentails to the Register* method.
string azureOpenAIEndpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
if (string.IsNullOrEmpty(azureOpenAIEndpoint))
azureOpenAIEndpoint = "https://api.devexpress.com/demo-openai";//DevExpress demo proxy-server
string azureOpenAIKey = Environment.GetEnvironmentVariable("AZURE_OPENAI_APIKEY");
if (string.IsNullOrEmpty(azureOpenAIKey))
azureOpenAIKey = "DEMO";//Demo key
string deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENTNAME");
if (string.IsNullOrEmpty(deploymentName))
deploymentName = "demo";//DevExpress demo deployment

IChatClient azureOpenAIClient = new AzureOpenAIClient(new Uri(azureOpenAIEndpoint),
new System.ClientModel.ApiKeyCredential(azureOpenAIKey)).GetChatClient(deploymentName).AsIChatClient();
AIExtensionsContainerDesktop.Default.RegisterChatClient(azureOpenAIClient);
}
}
Expand Down
20 changes: 13 additions & 7 deletions CS/wpf-ai-extensions/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ namespace WPF_AI_Extensions

public partial class App : System.Windows.Application
{
//Modify the following lines to obtain and pass your personal Azure OpenAI credentails to the Register* method.
string AzureOpenAIEndpoint { get { return Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT"); } }
string AzureOpenAIKey { get { return Environment.GetEnvironmentVariable("AZURE_OPENAI_APIKEY"); } }
string DeploymentName { get { return Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENTNAME"); } }

protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
Expand All @@ -31,8 +26,19 @@ protected override void OnStartup(StartupEventArgs e)
///To register Ollama
//OllamaChatClient ollamaChatClient = new OllamaChatClient("http://localhost:11434/", "llama3.1");

IChatClient azureOpenAIClient = new AzureOpenAIClient(new Uri(AzureOpenAIEndpoint),
new System.ClientModel.ApiKeyCredential(AzureOpenAIKey)).GetChatClient(DeploymentName).AsIChatClient();
//Modify the following lines to obtain and pass your personal Azure OpenAI credentails to the Register* method.
string azureOpenAIEndpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
if (string.IsNullOrEmpty(azureOpenAIEndpoint))
azureOpenAIEndpoint = "https://api.devexpress.com/demo-openai";//DevExpress demo proxy-server
string azureOpenAIKey = Environment.GetEnvironmentVariable("AZURE_OPENAI_APIKEY");
if (string.IsNullOrEmpty(azureOpenAIKey))
azureOpenAIKey = "DEMO";//Demo key
string deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENTNAME");
if (string.IsNullOrEmpty(deploymentName))
deploymentName = "demo";//DevExpress demo deployment

IChatClient azureOpenAIClient = new AzureOpenAIClient(new Uri(azureOpenAIEndpoint),
new System.ClientModel.ApiKeyCredential(azureOpenAIKey)).GetChatClient(deploymentName).AsIChatClient();
AIExtensionsContainerDesktop.Default.RegisterChatClient(azureOpenAIClient);
}
}
Expand Down
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![](https://img.shields.io/badge/💬_Leave_Feedback-feecdd?style=flat-square)](#does-this-example-address-your-development-requirementsobjectives)
<!-- default badges end -->

# Integrate DevExpress AI-Powered Text Extensions into Console, WinForms, and WPF Apps

Check failure on line 8 in README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] README.md#L8

[DX.ProperNoun] Capitalize a proper noun or conform term capitalization to our guidelines - "AI-powered".
Raw output
{"message": "[DX.ProperNoun] Capitalize a proper noun or conform term capitalization to our guidelines - \"AI-powered\".", "location": {"path": "README.md", "range": {"start": {"line": 8, "column": 24}}}, "severity": "ERROR"}

This example registers an Azure OpenAI service and uses AI APIs within a .NET 8 console application and adds AI-powered text processing features to the following DevExpress UI components:

Expand All @@ -15,7 +15,9 @@
* [WPF RichEditControl](https://www.devexpress.com/products/net/controls/wpf/rich_editor/)

>[!Note]
> DevExpress does not provide a REST API or include built-in LLMs/SLMs. To use AI services, you need an active Azure/OpenAI subscription to obtain the necessary REST API endpoint, key, and model deployment name. This information must be added at application startup to register AI clients and enable DevExpress AI-powered features in your application.

Check warning on line 18 in README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] README.md#L18

[DX.RayRules-Alternatives] Use a more specific synonym, such as 'include(s)' or 'store(s)'
Raw output
{"message": "[DX.RayRules-Alternatives] Use a more specific synonym, such as 'include(s)' or 'store(s)'", "location": {"path": "README.md", "range": {"start": {"line": 18, "column": 23}}}, "severity": "WARNING"}
>
> If these environment variables are not set, the sample falls back to the DevExpress demo proxy (`https://api.devexpress.com/demo-openai`) so you can try it out of the box. The demo proxy is rate-limited and intended for evaluation only — use your own Azure/OpenAI credentials for development.

## Implementation Details

Expand All @@ -28,7 +30,7 @@
3. Microsoft.Extensions.AI.OpenAI

> [!Note]
> We use the following versions of the `Microsoft.Extensions.AI.*` libraries in our `v25.2.2+` source code:

Check warning on line 33 in README.md

View workflow job for this annotation

GitHub Actions / vale

[vale] README.md#L33

[Microsoft.We] Only use we/us when you refer to our organization.
Raw output
{"message": "[Microsoft.We] Only use we/us when you refer to our organization.", "location": {"path": "README.md", "range": {"start": {"line": 33, "column": 81}}}, "severity": "WARNING"}
>
> * `Microsoft.Extensions.AI` | **9.7.1**
> * `Microsoft.Extensions.AI.OpenAI` | **9.7.1-preview.1.25365.4**
Expand All @@ -40,16 +42,22 @@
The following code in the `Program.cs` file registers an Azure AI service in the application:

```cs
// Modify the following lines to obtain and pass your personal Azure OpenAI credentials to the `Register~` method.
static string AzureOpenAIEndpoint { get { return Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT"); } }
static string AzureOpenAIKey { get { return Environment.GetEnvironmentVariable("AZURE_OPENAI_APIKEY"); } }
static string DeploymentName { get { return Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENTNAME"); } }

AIExtensionsContainerDefault defaultAIContainer;
public SampleAITextModifier()
{
IChatClient azureOpenAIClient = new AzureOpenAIClient(new Uri(AzureOpenAIEndpoint),
new System.ClientModel.ApiKeyCredential(AzureOpenAIKey)).GetChatClient(DeploymentName).AsIChatClient();
// Modify the following lines to obtain and pass your personal Azure OpenAI credentials to the `Register~` method.
string azureOpenAIEndpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
if (string.IsNullOrEmpty(azureOpenAIEndpoint))
azureOpenAIEndpoint = "https://api.devexpress.com/demo-openai";//DevExpress demo proxy-server
string azureOpenAIKey = Environment.GetEnvironmentVariable("AZURE_OPENAI_APIKEY");
if (string.IsNullOrEmpty(azureOpenAIKey))
azureOpenAIKey = "DEMO";//Demo key
string deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENTNAME");
if (string.IsNullOrEmpty(deploymentName))
deploymentName = "demo";//DevExpress demo deployment

IChatClient azureOpenAIClient = new AzureOpenAIClient(new Uri(azureOpenAIEndpoint),
new System.ClientModel.ApiKeyCredential(azureOpenAIKey)).GetChatClient(deploymentName).AsIChatClient();
AIExtensionsContainerDesktop.Default.RegisterChatClient(azureOpenAIClient);
}
```
Expand Down
29 changes: 9 additions & 20 deletions VB/console-ai-extension/Program.vb
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,18 @@ Namespace Runtime_AI_Extensions

Public Class SampleAITextModifier

'Modify the following lines to obtain and pass your personal Azure OpenAI credentails to the Register* method.
Private ReadOnly Property AzureOpenAIEndpoint As String
Get
Return Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")
End Get
End Property

Private ReadOnly Property AzureOpenAIKey As String
Get
Return Environment.GetEnvironmentVariable("AZURE_OPENAI_APIKEY")
End Get
End Property

Private ReadOnly Property DeploymentName As String
Get
Return Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENTNAME")
End Get
End Property

Private defaultAIContainer As AIExtensionsContainerDefault

Public Sub New()
Dim client As IChatClient = New AzureOpenAIClient(New Uri(AzureOpenAIEndpoint), New ClientModel.ApiKeyCredential(AzureOpenAIKey)).GetChatClient(DeploymentName).AsIChatClient()
'Modify the following lines to obtain and pass your personal Azure OpenAI credentails to the Register* method.
Dim azureOpenAIEndpoint As String = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")
If String.IsNullOrEmpty(azureOpenAIEndpoint) Then azureOpenAIEndpoint = "https://api.devexpress.com/demo-openai" 'DevExpress demo proxy-server
Dim azureOpenAIKey As String = Environment.GetEnvironmentVariable("AZURE_OPENAI_APIKEY")
If String.IsNullOrEmpty(azureOpenAIKey) Then azureOpenAIKey = "DEMO" 'Demo key
Dim deploymentName As String = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENTNAME")
If String.IsNullOrEmpty(deploymentName) Then deploymentName = "demo" 'DevExpress demo deployment

Dim client As IChatClient = New AzureOpenAIClient(New Uri(azureOpenAIEndpoint), New ClientModel.ApiKeyCredential(azureOpenAIKey)).GetChatClient(deploymentName).AsIChatClient()
defaultAIContainer = AIExtensionsContainerConsole.CreateDefaultAIExtensionContainer(client)
End Sub

Expand Down
30 changes: 10 additions & 20 deletions VB/winforms-ai-extensions/Program.vb
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,6 @@ Namespace WinForms_AI_Extensions

Friend Module Program

'Modify the following lines to obtain and pass your personal Azure OpenAI credentails to the Register* method.
Private ReadOnly Property AzureOpenAIEndpoint As String
Get
Return Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")
End Get
End Property

Private ReadOnly Property AzureOpenAIKey As String
Get
Return Environment.GetEnvironmentVariable("AZURE_OPENAI_APIKEY")
End Get
End Property

Private ReadOnly Property DeploymentName As String
Get
Return Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENTNAME")
End Get
End Property

''' <summary>
''' The main entry point for the application.
''' </summary>
Expand All @@ -41,7 +22,16 @@ Namespace WinForms_AI_Extensions
Private Sub RegisterDevExpressAI()
''' To register Ollama
'OllamaChatClient ollamaChatClient = new OllamaChatClient("http://localhost:11434/", "llama3.1");
Dim azureOpenAIClient As IChatClient = New AzureOpenAIClient(New Uri(AzureOpenAIEndpoint), New System.ClientModel.ApiKeyCredential(AzureOpenAIKey)).GetChatClient(DeploymentName).AsIChatClient()

'Modify the following lines to obtain and pass your personal Azure OpenAI credentails to the Register* method.
Dim azureOpenAIEndpoint As String = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")
If String.IsNullOrEmpty(azureOpenAIEndpoint) Then azureOpenAIEndpoint = "https://api.devexpress.com/demo-openai" 'DevExpress demo proxy-server
Dim azureOpenAIKey As String = Environment.GetEnvironmentVariable("AZURE_OPENAI_APIKEY")
If String.IsNullOrEmpty(azureOpenAIKey) Then azureOpenAIKey = "DEMO" 'Demo key
Dim deploymentName As String = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENTNAME")
If String.IsNullOrEmpty(deploymentName) Then deploymentName = "demo" 'DevExpress demo deployment

Dim azureOpenAIClient As IChatClient = New AzureOpenAIClient(New Uri(azureOpenAIEndpoint), New System.ClientModel.ApiKeyCredential(azureOpenAIKey)).GetChatClient(deploymentName).AsIChatClient()
AIExtensionsContainerDesktop.Default.RegisterChatClient(azureOpenAIClient)
End Sub
End Module
Expand Down
30 changes: 10 additions & 20 deletions VB/wpf-ai-extensions/App.xaml.vb
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,21 @@ Namespace WPF_AI_Extensions
Public Partial Class App
Inherits System.Windows.Application

'Modify the following lines to obtain and pass your personal Azure OpenAI credentails to the Register* method.
Private ReadOnly Property AzureOpenAIEndpoint As String
Get
Return Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")
End Get
End Property

Private ReadOnly Property AzureOpenAIKey As String
Get
Return Environment.GetEnvironmentVariable("AZURE_OPENAI_APIKEY")
End Get
End Property

Private ReadOnly Property DeploymentName As String
Get
Return Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENTNAME")
End Get
End Property

Protected Overrides Sub OnStartup(ByVal e As StartupEventArgs)
MyBase.OnStartup(e)
ApplicationThemeHelper.ApplicationThemeName = "Office2019Colorful"
''' To register Ollama
'OllamaChatClient ollamaChatClient = new OllamaChatClient("http://localhost:11434/", "llama3.1");
Dim azureOpenAIClient As IChatClient = New AzureOpenAIClient(New Uri(AzureOpenAIEndpoint), New System.ClientModel.ApiKeyCredential(AzureOpenAIKey)).GetChatClient(DeploymentName).AsIChatClient()

'Modify the following lines to obtain and pass your personal Azure OpenAI credentails to the Register* method.
Dim azureOpenAIEndpoint As String = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")
If String.IsNullOrEmpty(azureOpenAIEndpoint) Then azureOpenAIEndpoint = "https://api.devexpress.com/demo-openai" 'DevExpress demo proxy-server
Dim azureOpenAIKey As String = Environment.GetEnvironmentVariable("AZURE_OPENAI_APIKEY")
If String.IsNullOrEmpty(azureOpenAIKey) Then azureOpenAIKey = "DEMO" 'Demo key
Dim deploymentName As String = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENTNAME")
If String.IsNullOrEmpty(deploymentName) Then deploymentName = "demo" 'DevExpress demo deployment

Dim azureOpenAIClient As IChatClient = New AzureOpenAIClient(New Uri(azureOpenAIEndpoint), New System.ClientModel.ApiKeyCredential(azureOpenAIKey)).GetChatClient(deploymentName).AsIChatClient()
AIExtensionsContainerDesktop.Default.RegisterChatClient(azureOpenAIClient)
End Sub
End Class
Expand Down
Loading