From 57870ae63bd7004365f296053c6b38a161f676a0 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Mon, 13 Nov 2023 11:19:25 -0600 Subject: [PATCH] Bump Azure.AI.OpenAI to 1.0.0-beta.9 --- Directory.Build.props | 2 +- README.md | 5 ++- docs/conf.py | 4 +- .../BotSharp.Plugin.AzureOpenAI.csproj | 4 +- .../Providers/ChatCompletionProvider.cs | 39 +++++++------------ .../Providers/TextCompletionProvider.cs | 6 +-- src/WebStarter/WebStarter.csproj | 3 +- src/WebStarter/appsettings.json | 1 + 8 files changed, 27 insertions(+), 37 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 091643ab..7862c4ae 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,7 +2,7 @@ 10.0 ..\..\..\packages - 0.18.0 + 0.19.0 true \ No newline at end of file diff --git a/README.md b/README.md index fc024a1f..7250d9e0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# The Open Source LLM Application Framework -## Connect LLMs to your existing application +# The Open Source AI Agent Application Framework +## Connect LLMs to your existing application focused on your business [![Discord](https://img.shields.io/discord/1106946823282761851?label=Discord)](https://discord.gg/qRVm82fKTS) [![QQ群聊](https://img.shields.io/static/v1?label=QQ&message=群聊&color=brightgreen)](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=sN9VVMwbWjs5L0ATpizKKxOcZdEPMrp8&authKey=RLDw41bLTrEyEgZZi%2FzT4pYk%2BwmEFgFcrhs8ZbkiVY7a4JFckzJefaYNW6Lk4yPX&noverify=0&group_code=985366726) @@ -52,6 +52,7 @@ BotSharp uses component design, the kernel is kept to a minimum, and business fu - BotSharp.Plugin.MetaAI - BotSharp.Plugin.HuggingFace - BotSharp.Plugin.LLamaSharp +- BotSharp.Plugin.SemanticKernel #### Messaging / Channel - BotSharp.OpenAPI diff --git a/docs/conf.py b/docs/conf.py index 9f82c310..5e46f107 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -64,9 +64,9 @@ author = 'Haiping Chen' # built documents. # # The short X.Y version. -version = '0.18' +version = '0.19' # The full version, including alpha/beta/rc tags. -release = '0.18.0' +release = '0.19.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/src/Plugins/BotSharp.Plugin.AzureOpenAI/BotSharp.Plugin.AzureOpenAI.csproj b/src/Plugins/BotSharp.Plugin.AzureOpenAI/BotSharp.Plugin.AzureOpenAI.csproj index ea10eaec..03f701cd 100644 --- a/src/Plugins/BotSharp.Plugin.AzureOpenAI/BotSharp.Plugin.AzureOpenAI.csproj +++ b/src/Plugins/BotSharp.Plugin.AzureOpenAI/BotSharp.Plugin.AzureOpenAI.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -10,7 +10,7 @@ - + diff --git a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs index b91d7002..bc9b9866 100644 --- a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs @@ -47,8 +47,8 @@ public class ChatCompletionProvider : IChatCompletion var client = ProviderHelper.GetClient(_model, _settings); var (prompt, chatCompletionsOptions) = PrepareOptions(agent, conversations); - - var response = client.GetChatCompletions(_model, chatCompletionsOptions); + chatCompletionsOptions.DeploymentName = _model; + var response = client.GetChatCompletions(chatCompletionsOptions); var choice = response.Value.Choices[0]; var message = choice.Message; @@ -110,7 +110,8 @@ public class ChatCompletionProvider : IChatCompletion var client = ProviderHelper.GetClient(_model, _settings); var (prompt, chatCompletionsOptions) = PrepareOptions(agent, conversations); - var response = await client.GetChatCompletionsAsync(_model, chatCompletionsOptions); + chatCompletionsOptions.DeploymentName = _model; + var response = await client.GetChatCompletionsAsync(chatCompletionsOptions); var choice = response.Value.Choices[0]; var message = choice.Message; @@ -162,39 +163,27 @@ public class ChatCompletionProvider : IChatCompletion { var client = ProviderHelper.GetClient(_model, _settings); var (prompt, chatCompletionsOptions) = PrepareOptions(agent, conversations); - - var response = await client.GetChatCompletionsStreamingAsync(_model, chatCompletionsOptions); - using StreamingChatCompletions streaming = response.Value; + chatCompletionsOptions.DeploymentName = _model; + var response = await client.GetChatCompletionsStreamingAsync(chatCompletionsOptions); string output = ""; - await foreach (var choice in streaming.GetChoicesStreaming()) + await foreach (var choice in response) { if (choice.FinishReason == CompletionsFinishReason.FunctionCall) { - var args = ""; - await foreach (var message in choice.GetMessageStreaming()) - { - if (message.FunctionCall == null || message.FunctionCall.Arguments == null) - continue; - Console.Write(message.FunctionCall.Arguments); - args += message.FunctionCall.Arguments; + Console.Write(choice.FunctionArgumentsUpdate); - } - await onMessageReceived(new RoleDialogModel(ChatRole.Assistant.ToString(), args)); + await onMessageReceived(new RoleDialogModel(ChatRole.Assistant.ToString(), choice.FunctionArgumentsUpdate)); continue; } - await foreach (var message in choice.GetMessageStreaming()) - { - if (message.Content == null) - continue; - Console.Write(message.Content); - output += message.Content; + if (choice.ContentUpdate == null) + continue; + Console.Write(choice.ContentUpdate); - _logger.LogInformation(message.Content); + _logger.LogInformation(choice.ContentUpdate); - await onMessageReceived(new RoleDialogModel(message.Role.ToString(), message.Content)); - } + await onMessageReceived(new RoleDialogModel(choice.Role.ToString(), choice.ContentUpdate)); output = ""; } diff --git a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/TextCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/TextCompletionProvider.cs index 16707bed..fc0cde2c 100644 --- a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/TextCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/TextCompletionProvider.cs @@ -77,10 +77,8 @@ public class TextCompletionProvider : ITextCompletion var samplingFactor = float.Parse(state.GetState("sampling_factor", "0.5")); completionsOptions.Temperature = temperature; completionsOptions.NucleusSamplingFactor = samplingFactor; - - var response = await client.GetCompletionsAsync( - deploymentOrModelName: _model, - completionsOptions); + completionsOptions.DeploymentName = _model; + var response = await client.GetCompletionsAsync(completionsOptions); // OpenAI var completion = ""; diff --git a/src/WebStarter/WebStarter.csproj b/src/WebStarter/WebStarter.csproj index 8c14beff..6dacdf9e 100644 --- a/src/WebStarter/WebStarter.csproj +++ b/src/WebStarter/WebStarter.csproj @@ -59,11 +59,12 @@ + + - diff --git a/src/WebStarter/appsettings.json b/src/WebStarter/appsettings.json index 157755ea..72d404d0 100644 --- a/src/WebStarter/appsettings.json +++ b/src/WebStarter/appsettings.json @@ -142,6 +142,7 @@ // "BotSharp.Plugin.Twilio", "BotSharp.Plugin.HuggingFace", "BotSharp.Plugin.LLamaSharp", + // "BotSharp.Plugin.SemanticKernel", "BotSharp.Plugin.KnowledgeBase", "BotSharp.Plugin.Qdrant", "BotSharp.Plugin.PaddleSharp",