Skip to content

Commit 623c0fc

Browse files
committed
references and API usage updated for v24.2
1 parent 5924666 commit 623c0fc

File tree

11 files changed

+450
-421
lines changed

11 files changed

+450
-421
lines changed

CS/console-ai-extension/Program.cs

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using DevExpress.AIIntegration.Extensions;
44
using DevExpress.AIIntegration.Localization;
55
using DevExpress.Data;
6+
using Microsoft.Extensions.AI;
7+
using System;
68
using System.Globalization;
79

810

@@ -14,9 +16,6 @@ static void Main(string[] args)
1416
{
1517
Console.OutputEncoding = System.Text.Encoding.UTF8;
1618

17-
//Enable sending large texts to Ollama
18-
//AsyncDownloadPolicy.ConfigureHttpClient += AsyncDownloadPolicy_ConfigureHttpClient;
19-
2019
//Enable localization
2120
//AIIntegrationLocalizer.Active = new CustomAILocalizer();
2221

@@ -33,15 +32,6 @@ static void Main(string[] args)
3332
Console.ReadKey();
3433
}
3534

36-
private static void AsyncDownloadPolicy_ConfigureHttpClient(object sender, AsyncDownloadPolicy.ConfigureHttpClientEventArgs e)
37-
{
38-
string? fullTypeName = e?.ValueType.FullName;
39-
if (fullTypeName.Contains("Ollama"))
40-
{
41-
e.Client.Timeout = TimeSpan.FromMinutes(15);
42-
}
43-
}
44-
4535
public class SampleAITextModifier
4636
{
4737
//Modify the following lines to obtain and pass your personal Azure OpenAI credentails to the Register* method.
@@ -50,15 +40,18 @@ public class SampleAITextModifier
5040
string DeploymentName { get { return Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENTNAME"); } }
5141

5242
AIExtensionsContainerDefault defaultAIContainer;
43+
5344
public SampleAITextModifier()
5445
{
55-
defaultAIContainer = new AIExtensionsContainerDefault();
56-
//defaultAIContainer.RegisterChatClientOllamaAIService("http://localhost:11434/api/chat", "llama3.1");
57-
defaultAIContainer.RegisterChatClientOpenAIService(
58-
new AzureOpenAIClient(new Uri(AzureOpenAIEndpoint),
59-
new System.ClientModel.ApiKeyCredential(AzureOpenAIKey)),
60-
DeploymentName
61-
);
46+
47+
///To register Ollama
48+
//OllamaChatClient ollamaChatClient = new OllamaChatClient("http://localhost:11434/api/chat", "llama3.1");
49+
//defaultAIContainer = AIExtensionsContainerConsole.CreateDefaultAIExtensionContainer(ollamaChatClient);
50+
51+
///To register Azure OpenAI
52+
AzureOpenAIClient azureOpenAIClient = new AzureOpenAIClient(new Uri(AzureOpenAIEndpoint),
53+
new System.ClientModel.ApiKeyCredential(AzureOpenAIKey));
54+
defaultAIContainer = AIExtensionsContainerConsole.CreateDefaultAIExtensionContainer(azureOpenAIClient.AsChatClient(DeploymentName));
6255
}
6356

6457
public void ChangeDefaults()
@@ -81,7 +74,7 @@ public async Task<string> GetTranslation(string textToTranslate, string language
8174
}
8275
return translatedText;
8376
}
84-
// Something unexpected happens
77+
// When something unexpected has happened
8578
switch (result.Status)
8679
{
8780
case ResponseStatus.MaxTokenLimitExceeded:
@@ -98,13 +91,14 @@ public async Task<string> GetTranslation(string textToTranslate, string language
9891
// How to replace the default extension
9992
public async Task<string> GetShakespeareText(string textToModify)
10093
{
101-
defaultAIContainer.Register<RewriteStyleRequest, WilliamShakespeareStyleExtension>();
102-
string res = await defaultAIContainer.RewriteStyleAsync(new RewriteStyleRequest(textToModify, WritingStyle.Formal));
103-
return res;
94+
defaultAIContainer.Register<ChangeStyleRequest, WilliamShakespeareStyleExtension>();
95+
string res = await defaultAIContainer.ChangeStyleAsync(new ChangeStyleRequest(textToModify, WritingStyle.Formal));
96+
return res;
10497
}
10598

10699
//How to register and call your own extension
107-
public async Task<string> GetMarkTwainText(string textToModify) {
100+
public async Task<string> GetMarkTwainText(string textToModify)
101+
{
108102
var localContainer = new AIExtensionsContainerLocal(defaultAIContainer);
109103
localContainer.Register<AuthoredStyleRequest, AuthoredStyleExtension>();
110104

@@ -119,10 +113,10 @@ public async Task<string> GetMarkTwainText(string textToModify) {
119113
}
120114
}
121115
#region How to modify the default extension
122-
public class WilliamShakespeareStyleExtension : RewriteStyleExtension
116+
public class WilliamShakespeareStyleExtension : ChangeStyleExtension
123117
{
124118
public WilliamShakespeareStyleExtension(IServiceProvider serviceProvider) : base(serviceProvider) { }
125-
protected override string GetSystemPrompt(RewriteStyleRequest request)
119+
protected override string GetSystemPrompt(ChangeStyleRequest request)
126120
{
127121
return "Rewrite this text in the William Shakespeare style.";
128122
}

CS/console-ai-extension/Runtime-AI-Extensions.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="DevExpress.AIIntegration" Version="24.2.1-alpha-24241" />
13-
<PackageReference Include="DevExpress.AIIntegration.Azure.OpenAI" Version="24.2.1-alpha-24241" />
14-
<PackageReference Include="DevExpress.AIIntegration.Ollama" Version="24.2.1-alpha-24241" />
15-
<PackageReference Include="DevExpress.AIIntegration.OpenAI" Version="24.2.1-alpha-24241" />
12+
<PackageReference Include="Azure.AI.OpenAI" Version="2.0.0" />
13+
<PackageReference Include="DevExpress.AIIntegration" Version="24.2.1-alpha-24317" />
14+
<PackageReference Include="Microsoft.Extensions.AI.Ollama" Version="9.0.0-preview.9.24525.1" />
15+
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.0.0-preview.9.24525.1" />
1616
</ItemGroup>
1717

1818
</Project>

CS/winforms-ai-extensions/MemoEditForm.Designer.cs

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CS/winforms-ai-extensions/Program.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using Azure.AI.OpenAI;
22
using DevExpress.AIIntegration;
3+
using Microsoft.Extensions.AI;
34

45
namespace WinForms_AI_Extensions
56
{
6-
internal static class Program {
7+
internal static class Program
8+
{
79
//Modify the following lines to obtain and pass your personal Azure OpenAI credentails to the Register* method.
810
static string AzureOpenAIEndpoint { get { return Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT"); } }
911
static string AzureOpenAIKey { get { return Environment.GetEnvironmentVariable("AZURE_OPENAI_APIKEY"); } }
@@ -27,11 +29,12 @@ static void Main()
2729

2830
private static void RegisterDevExpressAI()
2931
{
30-
AIExtensionsContainerDesktop.Default.RegisterChatClientOpenAIService(
31-
new AzureOpenAIClient(
32-
new Uri(AzureOpenAIEndpoint),
33-
new System.ClientModel.ApiKeyCredential(AzureOpenAIKey)),
34-
DeploymentName);
32+
///To register Ollama
33+
//OllamaChatClient ollamaChatClient = new OllamaChatClient("http://localhost:11434/api/chat", "llama3.1");
34+
35+
AzureOpenAIClient azureOpenAIClient = new AzureOpenAIClient(new Uri(AzureOpenAIEndpoint),
36+
new System.ClientModel.ApiKeyCredential(AzureOpenAIKey));
37+
AIExtensionsContainerDesktop.Default.RegisterChatClient(azureOpenAIClient.AsChatClient(DeploymentName));
3538
}
3639
}
3740
}

0 commit comments

Comments
 (0)