From d7bba4522a2fa2f954f53f142b1c8adbeba0c584 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Mon, 18 Dec 2023 14:14:14 -0600 Subject: [PATCH] Upgrade dependent libraries. --- .../BotSharp.Abstraction.csproj | 8 ++-- .../BotSharp.Plugin.AzureOpenAI.csproj | 2 +- .../Providers/ChatCompletionProvider.cs | 46 +++++++++++++------ .../BotSharp.Plugin.HuggingFace.csproj | 1 - .../BotSharp.Plugin.KnowledgeBase.csproj | 4 +- .../BotSharp.Plugin.LLamaSharp.csproj | 2 +- .../BotSharp.Plugin.Qdrant.csproj | 2 +- .../BotSharp.Plugin.SemanticKernel.csproj | 3 +- .../SemanticKernelPlugin.cs | 26 ++--------- src/WebStarter/WebStarter.csproj | 4 +- ...arp.Plugin.SemanticKernel.UnitTests.csproj | 16 +++---- tests/UnitTest/UnitTest.csproj | 8 ++-- 12 files changed, 61 insertions(+), 61 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj b/src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj index ba1ea69d..fa407847 100644 --- a/src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj +++ b/src/Infrastructure/BotSharp.Abstraction/BotSharp.Abstraction.csproj @@ -24,11 +24,11 @@ - - - + + + - + diff --git a/src/Plugins/BotSharp.Plugin.AzureOpenAI/BotSharp.Plugin.AzureOpenAI.csproj b/src/Plugins/BotSharp.Plugin.AzureOpenAI/BotSharp.Plugin.AzureOpenAI.csproj index 81205002..0781e898 100644 --- a/src/Plugins/BotSharp.Plugin.AzureOpenAI/BotSharp.Plugin.AzureOpenAI.csproj +++ b/src/Plugins/BotSharp.Plugin.AzureOpenAI/BotSharp.Plugin.AzureOpenAI.csproj @@ -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 3953756a..49185d15 100644 --- a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs @@ -201,18 +201,20 @@ public class ChatCompletionProvider : IChatCompletion if (!string.IsNullOrEmpty(agent.Instruction)) { var instruction = agentService.RenderedInstruction(agent); - chatCompletionsOptions.Messages.Add(new ChatMessage(ChatRole.System, instruction)); + chatCompletionsOptions.Messages.Add(new ChatRequestSystemMessage(instruction)); } if (!string.IsNullOrEmpty(agent.Knowledges)) { - chatCompletionsOptions.Messages.Add(new ChatMessage(ChatRole.System, agent.Knowledges)); + chatCompletionsOptions.Messages.Add(new ChatRequestSystemMessage(agent.Knowledges)); } var samples = ProviderHelper.GetChatSamples(agent.Samples); foreach (var message in samples) { - chatCompletionsOptions.Messages.Add(new ChatMessage(message.Role, message.Content)); + chatCompletionsOptions.Messages.Add(message.Role == AgentRole.User ? + new ChatRequestUserMessage(message.Content) : + new ChatRequestAssistantMessage(message.Content)); } foreach (var function in agent.Functions) @@ -229,14 +231,15 @@ public class ChatCompletionProvider : IChatCompletion { if (message.Role == ChatRole.Function) { - chatCompletionsOptions.Messages.Add(new ChatMessage(message.Role, message.Content) - { - Name = message.FunctionName - }); + chatCompletionsOptions.Messages.Add(new ChatRequestFunctionMessage(message.FunctionName, message.Content)); } - else + else if (message.Role == ChatRole.User) { - chatCompletionsOptions.Messages.Add(new ChatMessage(message.Role, message.Content)); + chatCompletionsOptions.Messages.Add(new ChatRequestUserMessage(message.Content)); + } + else if (message.Role == ChatRole.Assistant) + { + chatCompletionsOptions.Messages.Add(new ChatRequestAssistantMessage(message.Content)); } } @@ -262,7 +265,8 @@ public class ChatCompletionProvider : IChatCompletion { // System instruction var verbose = string.Join("\r\n", chatCompletionsOptions.Messages - .Where(x => x.Role == AgentRole.System).Select(x => + .Where(x => x.Role == AgentRole.System) + .Select(x => x as ChatRequestSystemMessage).Select(x => { return $"{x.Role}: {x.Content}"; })); @@ -271,9 +275,25 @@ public class ChatCompletionProvider : IChatCompletion verbose = string.Join("\r\n", chatCompletionsOptions.Messages .Where(x => x.Role != AgentRole.System).Select(x => { - return x.Role == ChatRole.Function ? - $"{x.Role}: {x.Name} => {x.Content}" : - $"{x.Role}: {x.Content}"; + if (x.Role == ChatRole.Function) + { + var m = x as ChatRequestFunctionMessage; + return $"{m.Role}: {m.Name} => {m.Content}"; + } + else if (x.Role == ChatRole.User) + { + var m = x as ChatRequestUserMessage; + return $"{m.Role}: {m.Content}"; + } + else if (x.Role == ChatRole.Assistant) + { + var m = x as ChatRequestAssistantMessage; + return $"{m.Role}: {m.Content}"; + } + else + { + throw new NotImplementedException("Not found role"); + } })); prompt += $"\r\n{verbose}\r\n"; } diff --git a/src/Plugins/BotSharp.Plugin.HuggingFace/BotSharp.Plugin.HuggingFace.csproj b/src/Plugins/BotSharp.Plugin.HuggingFace/BotSharp.Plugin.HuggingFace.csproj index 640b18fe..f8514ef1 100644 --- a/src/Plugins/BotSharp.Plugin.HuggingFace/BotSharp.Plugin.HuggingFace.csproj +++ b/src/Plugins/BotSharp.Plugin.HuggingFace/BotSharp.Plugin.HuggingFace.csproj @@ -12,7 +12,6 @@ - diff --git a/src/Plugins/BotSharp.Plugin.KnowledgeBase/BotSharp.Plugin.KnowledgeBase.csproj b/src/Plugins/BotSharp.Plugin.KnowledgeBase/BotSharp.Plugin.KnowledgeBase.csproj index 28609e58..2931236f 100644 --- a/src/Plugins/BotSharp.Plugin.KnowledgeBase/BotSharp.Plugin.KnowledgeBase.csproj +++ b/src/Plugins/BotSharp.Plugin.KnowledgeBase/BotSharp.Plugin.KnowledgeBase.csproj @@ -10,8 +10,8 @@ - - + + diff --git a/src/Plugins/BotSharp.Plugin.LLamaSharp/BotSharp.Plugin.LLamaSharp.csproj b/src/Plugins/BotSharp.Plugin.LLamaSharp/BotSharp.Plugin.LLamaSharp.csproj index 9e4874cc..8dcb7b38 100644 --- a/src/Plugins/BotSharp.Plugin.LLamaSharp/BotSharp.Plugin.LLamaSharp.csproj +++ b/src/Plugins/BotSharp.Plugin.LLamaSharp/BotSharp.Plugin.LLamaSharp.csproj @@ -10,7 +10,7 @@ - + diff --git a/src/Plugins/BotSharp.Plugin.Qdrant/BotSharp.Plugin.Qdrant.csproj b/src/Plugins/BotSharp.Plugin.Qdrant/BotSharp.Plugin.Qdrant.csproj index e8f32d39..e24b8da2 100644 --- a/src/Plugins/BotSharp.Plugin.Qdrant/BotSharp.Plugin.Qdrant.csproj +++ b/src/Plugins/BotSharp.Plugin.Qdrant/BotSharp.Plugin.Qdrant.csproj @@ -10,7 +10,7 @@ - + diff --git a/src/Plugins/BotSharp.Plugin.SemanticKernel/BotSharp.Plugin.SemanticKernel.csproj b/src/Plugins/BotSharp.Plugin.SemanticKernel/BotSharp.Plugin.SemanticKernel.csproj index 2dd2e3b3..21d06a51 100644 --- a/src/Plugins/BotSharp.Plugin.SemanticKernel/BotSharp.Plugin.SemanticKernel.csproj +++ b/src/Plugins/BotSharp.Plugin.SemanticKernel/BotSharp.Plugin.SemanticKernel.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 @@ -10,7 +10,6 @@ - diff --git a/src/Plugins/BotSharp.Plugin.SemanticKernel/SemanticKernelPlugin.cs b/src/Plugins/BotSharp.Plugin.SemanticKernel/SemanticKernelPlugin.cs index 45afa52f..c35bf0a1 100644 --- a/src/Plugins/BotSharp.Plugin.SemanticKernel/SemanticKernelPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.SemanticKernel/SemanticKernelPlugin.cs @@ -20,28 +20,10 @@ namespace BotSharp.Plugin.SemanticKernel /// public void RegisterDI(IServiceCollection services, IConfiguration config) { - - var provider = services.BuildServiceProvider().CreateScope().ServiceProvider; - - if (provider.GetService() != null) - { - services.AddScoped(); - } - - if (provider.GetService() != null) - { - services.AddScoped(); - } - - if (provider.GetService() != null) - { - services.AddScoped(); - } - - if (provider.GetService() != null) - { - services.AddScoped(); - } + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); } } } \ No newline at end of file diff --git a/src/WebStarter/WebStarter.csproj b/src/WebStarter/WebStarter.csproj index 26af9b65..767af598 100644 --- a/src/WebStarter/WebStarter.csproj +++ b/src/WebStarter/WebStarter.csproj @@ -1,7 +1,7 @@ - + - net6.0 + net8.0 enable enable InProcess diff --git a/tests/BotSharp.Plugin.SemanticKernel.UnitTests/BotSharp.Plugin.SemanticKernel.UnitTests.csproj b/tests/BotSharp.Plugin.SemanticKernel.UnitTests/BotSharp.Plugin.SemanticKernel.UnitTests.csproj index 057c117c..a9d98db9 100644 --- a/tests/BotSharp.Plugin.SemanticKernel.UnitTests/BotSharp.Plugin.SemanticKernel.UnitTests.csproj +++ b/tests/BotSharp.Plugin.SemanticKernel.UnitTests/BotSharp.Plugin.SemanticKernel.UnitTests.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 enable enable @@ -9,17 +9,17 @@ - - - + + + - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/tests/UnitTest/UnitTest.csproj b/tests/UnitTest/UnitTest.csproj index c3ac4f4e..60f21cc4 100644 --- a/tests/UnitTest/UnitTest.csproj +++ b/tests/UnitTest/UnitTest.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 enable enable @@ -10,9 +10,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive