Skip to content

Commit

Permalink
update vb
Browse files Browse the repository at this point in the history
  • Loading branch information
geumjaLee committed Nov 15, 2024
1 parent 1947237 commit c8686d7
Show file tree
Hide file tree
Showing 10 changed files with 448 additions and 420 deletions.
34 changes: 16 additions & 18 deletions VB/console-ai-extension/Program.vb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Imports DevExpress.AIIntegration
Imports DevExpress.AIIntegration.Extensions
Imports DevExpress.AIIntegration.Localization
Imports DevExpress.Data
Imports Microsoft.Extensions.AI
Imports System
Imports System.Globalization


Expand All @@ -13,9 +15,6 @@ Namespace Runtime_AI_Extensions
Shared Sub Main(ByVal args() As String)
Console.OutputEncoding = System.Text.Encoding.UTF8

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

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

Expand All @@ -32,13 +31,6 @@ Namespace Runtime_AI_Extensions
Console.ReadKey()
End Sub

Private Shared Sub AsyncDownloadPolicy_ConfigureHttpClient(ByVal sender As Object, ByVal e As AsyncDownloadPolicy.ConfigureHttpClientEventArgs)
Dim fullTypeName? As String = e?.ValueType.FullName
If fullTypeName.Contains("Ollama") Then
e.Client.Timeout = TimeSpan.FromMinutes(15)
End If
End Sub

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
Expand All @@ -58,10 +50,16 @@ Namespace Runtime_AI_Extensions
End Property

Private defaultAIContainer As AIExtensionsContainerDefault

Public Sub New()
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
Dim azureOpenAIClient As New AzureOpenAIClient(New Uri(AzureOpenAIEndpoint), New System.ClientModel.ApiKeyCredential(AzureOpenAIKey))
defaultAIContainer = AIExtensionsContainerConsole.CreateDefaultAIExtensionContainer(azureOpenAIClient.AsChatClient(DeploymentName))
End Sub

Public Sub ChangeDefaults()
Expand All @@ -81,7 +79,7 @@ Namespace Runtime_AI_Extensions
Loop
Return translatedText
End If
' Something unexpected happens
' When something unexpected has happened
Select Case result.Status
Case ResponseStatus.MaxTokenLimitExceeded, ResponseStatus.InputSizeLimitExceeded
Return "The text you're trying to send within a request is too long and exceeds the limit."
Expand All @@ -95,8 +93,8 @@ Namespace Runtime_AI_Extensions

' How to replace the default extension
Public Async Function GetShakespeareText(ByVal textToModify As String) As Task(Of String)
defaultAIContainer.Register(Of RewriteStyleRequest, WilliamShakespeareStyleExtension)()
Dim res As String = Await defaultAIContainer.RewriteStyleAsync(New RewriteStyleRequest(textToModify, WritingStyle.Formal))
defaultAIContainer.Register(Of ChangeStyleRequest, WilliamShakespeareStyleExtension)()
Dim res As String = Await defaultAIContainer.ChangeStyleAsync(New ChangeStyleRequest(textToModify, WritingStyle.Formal))
Return res
End Function

Expand All @@ -117,12 +115,12 @@ Namespace Runtime_AI_Extensions
End Class
#Region "How to modify the default extension"
Public Class WilliamShakespeareStyleExtension
Inherits RewriteStyleExtension
Inherits ChangeStyleExtension

Public Sub New(ByVal serviceProvider As IServiceProvider)
MyBase.New(serviceProvider)
End Sub
Protected Overrides Function GetSystemPrompt(ByVal request As RewriteStyleRequest) As String
Protected Overrides Function GetSystemPrompt(ByVal request As ChangeStyleRequest) As String
Return "Rewrite this text in the William Shakespeare style."
End Function
End Class
Expand Down
8 changes: 4 additions & 4 deletions VB/console-ai-extension/Runtime-AI-Extensions.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
<Import Include="System" />
</ItemGroup>
<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.1-alpha-24317" />
<PackageReference Include="Microsoft.Extensions.AI.Ollama" Version="9.0.0-preview.9.24525.1" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.0.0-preview.9.24525.1" />
</ItemGroup>

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

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

7 changes: 6 additions & 1 deletion VB/winforms-ai-extensions/Program.vb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Imports Azure.AI.OpenAI
Imports DevExpress.AIIntegration
Imports Microsoft.Extensions.AI

Namespace WinForms_AI_Extensions
Friend Module Program
Expand Down Expand Up @@ -36,7 +37,11 @@ Namespace WinForms_AI_Extensions
End Sub

Private Sub 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");

Dim azureOpenAIClient As New AzureOpenAIClient(New Uri(AzureOpenAIEndpoint), New System.ClientModel.ApiKeyCredential(AzureOpenAIKey))
AIExtensionsContainerDesktop.Default.RegisterChatClient(azureOpenAIClient.AsChatClient(DeploymentName))
End Sub
End Module
End Namespace
Loading

0 comments on commit c8686d7

Please sign in to comment.