diff --git a/CS/console-ai-extension/Program.cs b/CS/console-ai-extension/Program.cs index c1b0a39..a89cb97 100644 --- a/CS/console-ai-extension/Program.cs +++ b/CS/console-ai-extension/Program.cs @@ -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); } diff --git a/CS/winforms-ai-extensions/Program.cs b/CS/winforms-ai-extensions/Program.cs index 35e8149..141531b 100644 --- a/CS/winforms-ai-extensions/Program.cs +++ b/CS/winforms-ai-extensions/Program.cs @@ -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"); } } - /// /// The main entry point for the application. /// @@ -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); } } diff --git a/CS/wpf-ai-extensions/App.xaml.cs b/CS/wpf-ai-extensions/App.xaml.cs index 901559c..b0cb42d 100644 --- a/CS/wpf-ai-extensions/App.xaml.cs +++ b/CS/wpf-ai-extensions/App.xaml.cs @@ -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); @@ -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); } } diff --git a/README.md b/README.md index b269fb4..8004c13 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ This example registers an Azure OpenAI service and uses AI APIs within a .NET 8 >[!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. +> +> 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 @@ -40,16 +42,22 @@ Install the following NuGet packages: 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); } ``` diff --git a/VB/console-ai-extension/Program.vb b/VB/console-ai-extension/Program.vb index 40836d5..2f5906e 100644 --- a/VB/console-ai-extension/Program.vb +++ b/VB/console-ai-extension/Program.vb @@ -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 diff --git a/VB/winforms-ai-extensions/Program.vb b/VB/winforms-ai-extensions/Program.vb index 43a7a8c..1a2be18 100644 --- a/VB/winforms-ai-extensions/Program.vb +++ b/VB/winforms-ai-extensions/Program.vb @@ -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 - ''' ''' The main entry point for the application. ''' @@ -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 diff --git a/VB/wpf-ai-extensions/App.xaml.vb b/VB/wpf-ai-extensions/App.xaml.vb index 6289aa2..a460b0a 100644 --- a/VB/wpf-ai-extensions/App.xaml.vb +++ b/VB/wpf-ai-extensions/App.xaml.vb @@ -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