Skip to content

V24 2 beta update #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Nov 15, 2024
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
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @DevExpressExampleBot
46 changes: 20 additions & 26 deletions CS/console-ai-extension/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using DevExpress.AIIntegration.Extensions;
using DevExpress.AIIntegration.Localization;
using DevExpress.Data;
using Microsoft.Extensions.AI;
using System;
using System.Globalization;


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

//Enable sending large texts to Ollama
//AsyncDownloadPolicy.ConfigureHttpClient += AsyncDownloadPolicy_ConfigureHttpClient;

//Enable localization
//AIIntegrationLocalizer.Active = new CustomAILocalizer();

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

private static void AsyncDownloadPolicy_ConfigureHttpClient(object sender, AsyncDownloadPolicy.ConfigureHttpClientEventArgs e)
{
string? fullTypeName = e?.ValueType.FullName;
if (fullTypeName.Contains("Ollama"))
{
e.Client.Timeout = TimeSpan.FromMinutes(15);
}
}

public class SampleAITextModifier
{
//Modify the following lines to obtain and pass your personal Azure OpenAI credentails to the Register* method.
Expand All @@ -50,15 +40,18 @@ public class SampleAITextModifier
string DeploymentName { get { return Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENTNAME"); } }

AIExtensionsContainerDefault defaultAIContainer;

public SampleAITextModifier()
{
defaultAIContainer = new AIExtensionsContainerDefault();
//defaultAIContainer.RegisterChatClientOllamaAIService("http://localhost:11434/api/chat", "llama3.1");
defaultAIContainer.RegisterChatClientOpenAIService(
new AzureOpenAIClient(new Uri(AzureOpenAIEndpoint),
new System.ClientModel.ApiKeyCredential(AzureOpenAIKey)),
DeploymentName
);

///To register Ollama
//OllamaChatClient ollamaChatClient = new OllamaChatClient("http://localhost:11434/api/chat", "llama3.1");
//defaultAIContainer = AIExtensionsContainerConsole.CreateDefaultAIExtensionContainer(ollamaChatClient);

///To register Azure OpenAI
AzureOpenAIClient azureOpenAIClient = new AzureOpenAIClient(new Uri(AzureOpenAIEndpoint),
new System.ClientModel.ApiKeyCredential(AzureOpenAIKey));
defaultAIContainer = AIExtensionsContainerConsole.CreateDefaultAIExtensionContainer(azureOpenAIClient.AsChatClient(DeploymentName));
}

public void ChangeDefaults()
Expand All @@ -81,7 +74,7 @@ public async Task<string> GetTranslation(string textToTranslate, string language
}
return translatedText;
}
// Something unexpected happens
// When something unexpected has happened
switch (result.Status)
{
case ResponseStatus.MaxTokenLimitExceeded:
Expand All @@ -98,13 +91,14 @@ public async Task<string> GetTranslation(string textToTranslate, string language
// How to replace the default extension
public async Task<string> GetShakespeareText(string textToModify)
{
defaultAIContainer.Register<RewriteStyleRequest, WilliamShakespeareStyleExtension>();
string res = await defaultAIContainer.RewriteStyleAsync(new RewriteStyleRequest(textToModify, WritingStyle.Formal));
return res;
defaultAIContainer.Register<ChangeStyleRequest, WilliamShakespeareStyleExtension>();
string res = await defaultAIContainer.ChangeStyleAsync(new ChangeStyleRequest(textToModify, WritingStyle.Formal));
return res;
}

//How to register and call your own extension
public async Task<string> GetMarkTwainText(string textToModify) {
public async Task<string> GetMarkTwainText(string textToModify)
{
var localContainer = new AIExtensionsContainerLocal(defaultAIContainer);
localContainer.Register<AuthoredStyleRequest, AuthoredStyleExtension>();

Expand All @@ -119,10 +113,10 @@ public async Task<string> GetMarkTwainText(string textToModify) {
}
}
#region How to modify the default extension
public class WilliamShakespeareStyleExtension : RewriteStyleExtension
public class WilliamShakespeareStyleExtension : ChangeStyleExtension
{
public WilliamShakespeareStyleExtension(IServiceProvider serviceProvider) : base(serviceProvider) { }
protected override string GetSystemPrompt(RewriteStyleRequest request)
protected override string GetSystemPrompt(ChangeStyleRequest request)
{
return "Rewrite this text in the William Shakespeare style.";
}
Expand Down
8 changes: 4 additions & 4 deletions CS/console-ai-extension/Runtime-AI-Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DevExpress.AIIntegration" Version="24.2.1-alpha-24241" />
<PackageReference Include="DevExpress.AIIntegration.Azure.OpenAI" Version="24.2.1-alpha-24241" />
<PackageReference Include="DevExpress.AIIntegration.Ollama" Version="24.2.1-alpha-24241" />
<PackageReference Include="DevExpress.AIIntegration.OpenAI" Version="24.2.1-alpha-24241" />
<PackageReference Include="Azure.AI.OpenAI" Version="2.0.0" />
<PackageReference Include="DevExpress.AIIntegration" Version="24.2.*" />
<PackageReference Include="Microsoft.Extensions.AI.Ollama" Version="9.0.*" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.0.*" />
</ItemGroup>

</Project>
18 changes: 9 additions & 9 deletions CS/winforms-ai-extensions/MemoEditForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions CS/winforms-ai-extensions/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using Azure.AI.OpenAI;
using DevExpress.AIIntegration;
using Microsoft.Extensions.AI;

namespace WinForms_AI_Extensions
{
internal static class Program {
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"); } }
Expand All @@ -27,11 +29,12 @@ static void Main()

private static void RegisterDevExpressAI()
{
AIExtensionsContainerDesktop.Default.RegisterChatClientOpenAIService(
new AzureOpenAIClient(
new Uri(AzureOpenAIEndpoint),
new System.ClientModel.ApiKeyCredential(AzureOpenAIKey)),
DeploymentName);
///To register Ollama
//OllamaChatClient ollamaChatClient = new OllamaChatClient("http://localhost:11434/api/chat", "llama3.1");

AzureOpenAIClient azureOpenAIClient = new AzureOpenAIClient(new Uri(AzureOpenAIEndpoint),
new System.ClientModel.ApiKeyCredential(AzureOpenAIKey));
AIExtensionsContainerDesktop.Default.RegisterChatClient(azureOpenAIClient.AsChatClient(DeploymentName));
}
}
}
Loading