From 229fcfe6ea14a50f25db7818ee31e4629eb334ec Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Tue, 6 Jun 2023 19:59:32 -0500 Subject: [PATCH] Refactor plugins mechanism. --- BotSharp.sln | 115 ++++++++---------- README.md | 2 +- .../ApiAdapters/IApiAdapter.cs | 5 + .../Conversations/ISessionService.cs | 2 +- .../Conversations/Models/MessageModel.cs | 7 ++ .../BotSharp.Abstraction/IBotUiAdapter.cs | 9 -- .../Plugins/IBotSharpPlugin.cs | 5 + .../ITextCompletionProvider.cs} | 6 +- .../BotSharp.Core/BotSharp.Core.csproj | 4 +- .../BotSharpServiceCollectionExtensions.cs | 10 ++ .../Conversations/SessionService.cs | 18 ++- .../{Services => Plugins}/PlatformMidware.cs | 3 +- .../LlamaSharpCompletionProvider.cs} | 24 ++-- .../LLamaSharp}/LlamaSharpSettings.cs | 2 +- .../Repository/Collections/Conversation.cs | 22 ++++ .../Repository/DataContextHelper.cs | 8 +- .../Repository/IMongoDbCollection.cs | 3 + .../Repository/MongoDbContext.cs | 4 + .../BotSharp.Channel.FacebookMessenger.csproj | 7 -- .../BotSharp.Plugin.FacebookMessenger.csproj} | 9 +- .../BotSharp.Plugin.Weixin.csproj} | 4 + .../BotSharp.Channel.Weixin/README.md | 0 .../BotSharplServiceCollectionExtensions.cs | 22 ---- .../BotSharp.Platform.OpenAi.csproj | 9 -- .../AzureAiServiceCollectionExtensions.cs | 4 +- .../AzureAiSettings.cs | 0 .../BotSharp.Plugin.AzureOpenAI.csproj} | 0 .../Providers}/ChatCompletionHandler.cs | 4 +- .../BotSharp.Plugin.ChatbotUI.csproj} | 0 .../BotSharp.Plugin.ChatbotUI}/Chatbot-UI.md | 0 .../ChatbotUiController.cs | 7 +- .../ViewModels/OpenAiChatOutput.cs | 2 +- .../ViewModels/OpenAiChoice.cs | 2 +- .../ViewModels/OpenAiMessageBody.cs | 2 +- .../ViewModels/OpenAiMessageInput.cs | 2 +- .../ViewModels/OpenAiModels.cs | 2 +- .../BotSharp.Plugin.HuggingChatUI.csproj} | 0 .../HuggingChat-UI.md | 2 +- .../HuggingChatUiController.cs | 14 ++- .../ViewModels/ConversationCreationModel.cs | 2 +- .../ViewModels/ConversationViewModel.cs | 2 +- src/WebStarter/Program.cs | 1 - src/WebStarter/Prompts/chat-samples.txt | 2 + src/WebStarter/WebStarter.csproj | 9 +- src/WebStarter/appsettings.json | 5 +- 45 files changed, 187 insertions(+), 175 deletions(-) create mode 100644 src/Infrastructure/BotSharp.Abstraction/ApiAdapters/IApiAdapter.cs create mode 100644 src/Infrastructure/BotSharp.Abstraction/Conversations/Models/MessageModel.cs delete mode 100644 src/Infrastructure/BotSharp.Abstraction/IBotUiAdapter.cs create mode 100644 src/Infrastructure/BotSharp.Abstraction/Plugins/IBotSharpPlugin.cs rename src/Infrastructure/BotSharp.Abstraction/{IChatCompletionHandler.cs => TextCompletions/ITextCompletionProvider.cs} (70%) rename src/Infrastructure/BotSharp.Core/{Services => Plugins}/PlatformMidware.cs (87%) rename src/{Plugins/Platforms/BotSharp.Platform.Native/Handlers/ChatCompletionHandler.cs => Infrastructure/BotSharp.Core/Plugins/TextCompletions/LLamaSharp/LlamaSharpCompletionProvider.cs} (80%) rename src/{Plugins/Platforms/BotSharp.Platform.Native/Settings => Infrastructure/BotSharp.Core/Plugins/TextCompletions/LLamaSharp}/LlamaSharpSettings.cs (88%) create mode 100644 src/Infrastructure/BotSharp.Core/Repository/Collections/Conversation.cs delete mode 100644 src/Plugins/Channels/BotSharp.Channel.FacebookMessenger/BotSharp.Channel.FacebookMessenger.csproj rename src/Plugins/{Platforms/BotSharp.Platform.Native/BotSharp.Platform.Native.csproj => Messages/BotSharp.Channel.FacebookMessenger/BotSharp.Plugin.FacebookMessenger.csproj} (52%) rename src/Plugins/{Channels/BotSharp.Channel.Weixin/BotSharp.Channel.Weixin.csproj => Messages/BotSharp.Channel.Weixin/BotSharp.Plugin.Weixin.csproj} (86%) rename src/Plugins/{Channels => Messages}/BotSharp.Channel.Weixin/README.md (100%) delete mode 100644 src/Plugins/Platforms/BotSharp.Platform.Native/BotSharplServiceCollectionExtensions.cs delete mode 100644 src/Plugins/Platforms/BotSharp.Platform.OpenAi/BotSharp.Platform.OpenAi.csproj rename src/Plugins/Platforms/{BotSharp.Platform.AureAi => BotSharp.Plugin.AureOpenAI}/AzureAiServiceCollectionExtensions.cs (81%) rename src/Plugins/Platforms/{BotSharp.Platform.AureAi => BotSharp.Plugin.AureOpenAI}/AzureAiSettings.cs (100%) rename src/Plugins/Platforms/{BotSharp.Platform.AureAi/BotSharp.Platform.AzureAi.csproj => BotSharp.Plugin.AureOpenAI/BotSharp.Plugin.AzureOpenAI.csproj} (100%) rename src/Plugins/Platforms/{BotSharp.Platform.AureAi/Handlers => BotSharp.Plugin.AureOpenAI/Providers}/ChatCompletionHandler.cs (96%) rename src/Plugins/{UiAdapters/BotSharp.UiAdapter.ChatbotUI/BotSharp.UIAdapter.ChatbotUI.csproj => UIs/BotSharp.Plugin.ChatbotUI/BotSharp.Plugin.ChatbotUI.csproj} (100%) rename src/Plugins/{UiAdapters/BotSharp.UiAdapter.ChatbotUI => UIs/BotSharp.Plugin.ChatbotUI}/Chatbot-UI.md (100%) rename src/Plugins/{UiAdapters/BotSharp.UiAdapter.ChatbotUI => UIs/BotSharp.Plugin.ChatbotUI}/ChatbotUiController.cs (94%) rename src/Plugins/{UiAdapters/BotSharp.UiAdapter.ChatbotUI => UIs/BotSharp.Plugin.ChatbotUI}/ViewModels/OpenAiChatOutput.cs (71%) rename src/Plugins/{UiAdapters/BotSharp.UiAdapter.ChatbotUI => UIs/BotSharp.Plugin.ChatbotUI}/ViewModels/OpenAiChoice.cs (82%) rename src/Plugins/{UiAdapters/BotSharp.UiAdapter.ChatbotUI => UIs/BotSharp.Plugin.ChatbotUI}/ViewModels/OpenAiMessageBody.cs (70%) rename src/Plugins/{UiAdapters/BotSharp.UiAdapter.ChatbotUI => UIs/BotSharp.Plugin.ChatbotUI}/ViewModels/OpenAiMessageInput.cs (92%) rename src/Plugins/{UiAdapters/BotSharp.UiAdapter.ChatbotUI => UIs/BotSharp.Plugin.ChatbotUI}/ViewModels/OpenAiModels.cs (77%) rename src/Plugins/{UiAdapters/BotSharp.UiAdapter.HuggingChatUI/BotSharp.UIAdapter.HuggingChatUI.csproj => UIs/BotSharp.Plugin.HuggingChatUI/BotSharp.Plugin.HuggingChatUI.csproj} (100%) rename src/Plugins/{UiAdapters/BotSharp.UiAdapter.HuggingChatUI => UIs/BotSharp.Plugin.HuggingChatUI}/HuggingChat-UI.md (91%) rename src/Plugins/{UiAdapters/BotSharp.UiAdapter.HuggingChatUI => UIs/BotSharp.Plugin.HuggingChatUI}/HuggingChatUiController.cs (50%) rename src/Plugins/{UiAdapters/BotSharp.UiAdapter.HuggingChatUI => UIs/BotSharp.Plugin.HuggingChatUI}/ViewModels/ConversationCreationModel.cs (61%) rename src/Plugins/{UiAdapters/BotSharp.UiAdapter.HuggingChatUI => UIs/BotSharp.Plugin.HuggingChatUI}/ViewModels/ConversationViewModel.cs (62%) create mode 100644 src/WebStarter/Prompts/chat-samples.txt diff --git a/BotSharp.sln b/BotSharp.sln index e1b8f1fa..40548e48 100644 --- a/BotSharp.sln +++ b/BotSharp.sln @@ -11,25 +11,23 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Core", "src\Infras EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebStarter", "src\WebStarter\WebStarter.csproj", "{07AD18C5-CE7B-495A-815F-170E93CCC42A}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "UiAdapters", "UiAdapters", "{42226933-0A0D-48E8-85EC-AFE773A1F841}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "UIs", "UIs", "{42226933-0A0D-48E8-85EC-AFE773A1F841}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugins", "Plugins", "{2635EC9B-2E5F-4313-AC21-0B847F31F36C}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Channels", "Channels", "{64264688-0F5C-4AB0-8F2B-B59B717CCE00}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Messages", "Messages", "{64264688-0F5C-4AB0-8F2B-B59B717CCE00}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Platforms", "Platforms", "{D5293208-2BEF-42FC-A64C-5954F61720BA}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Channel.Weixin", "src\Plugins\Channels\BotSharp.Channel.Weixin\BotSharp.Channel.Weixin.csproj", "{B99E1F96-5989-41FF-A4FB-90EFD5C3099F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.AzureOpenAI", "src\Plugins\Platforms\BotSharp.Plugin.AureOpenAI\BotSharp.Plugin.AzureOpenAI.csproj", "{A8DF9393-9D67-460C-86F3-1D3C65A80D0A}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Channel.FacebookMessenger", "src\Plugins\Channels\BotSharp.Channel.FacebookMessenger\BotSharp.Channel.FacebookMessenger.csproj", "{1D651A53-6755-465B-93FC-FA537A5A614E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.FacebookMessenger", "src\Plugins\Messages\BotSharp.Channel.FacebookMessenger\BotSharp.Plugin.FacebookMessenger.csproj", "{ACAB7D42-CCB3-4559-9DB7-B969C52A833D}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.AzureAi", "src\Plugins\Platforms\BotSharp.Platform.AureAi\BotSharp.Platform.AzureAi.csproj", "{DB98D551-C74A-426E-AF15-D1D49610E00E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.Weixin", "src\Plugins\Messages\BotSharp.Channel.Weixin\BotSharp.Plugin.Weixin.csproj", "{4DA3E063-9F5A-4361-8EFE-8727409B238D}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.UIAdapter.ChatbotUI", "src\Plugins\UiAdapters\BotSharp.UiAdapter.ChatbotUI\BotSharp.UIAdapter.ChatbotUI.csproj", "{B49EFCCA-3E5D-4E26-8E83-4070C6FE34C8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.ChatbotUI", "src\Plugins\UIs\BotSharp.Plugin.ChatbotUI\BotSharp.Plugin.ChatbotUI.csproj", "{BDCE7250-A5B0-4AA6-BEB6-B799C12990EF}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.UIAdapter.HuggingChatUI", "src\Plugins\UiAdapters\BotSharp.UiAdapter.HuggingChatUI\BotSharp.UIAdapter.HuggingChatUI.csproj", "{CAEA84EF-B121-48AE-AE0F-AFB514A3FAFF}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.Native", "src\Plugins\Platforms\BotSharp.Platform.Native\BotSharp.Platform.Native.csproj", "{6498D3E6-6C87-4955-8686-38817EEDC23E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.HuggingChatUI", "src\Plugins\UIs\BotSharp.Plugin.HuggingChatUI\BotSharp.Plugin.HuggingChatUI.csproj", "{17640C6E-2797-4D51-AF97-F2D1B5C47623}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -63,54 +61,46 @@ Global {07AD18C5-CE7B-495A-815F-170E93CCC42A}.Release|Any CPU.Build.0 = Release|Any CPU {07AD18C5-CE7B-495A-815F-170E93CCC42A}.Release|x64.ActiveCfg = Release|Any CPU {07AD18C5-CE7B-495A-815F-170E93CCC42A}.Release|x64.Build.0 = Release|Any CPU - {B99E1F96-5989-41FF-A4FB-90EFD5C3099F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B99E1F96-5989-41FF-A4FB-90EFD5C3099F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B99E1F96-5989-41FF-A4FB-90EFD5C3099F}.Debug|x64.ActiveCfg = Debug|Any CPU - {B99E1F96-5989-41FF-A4FB-90EFD5C3099F}.Debug|x64.Build.0 = Debug|Any CPU - {B99E1F96-5989-41FF-A4FB-90EFD5C3099F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B99E1F96-5989-41FF-A4FB-90EFD5C3099F}.Release|Any CPU.Build.0 = Release|Any CPU - {B99E1F96-5989-41FF-A4FB-90EFD5C3099F}.Release|x64.ActiveCfg = Release|Any CPU - {B99E1F96-5989-41FF-A4FB-90EFD5C3099F}.Release|x64.Build.0 = Release|Any CPU - {1D651A53-6755-465B-93FC-FA537A5A614E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1D651A53-6755-465B-93FC-FA537A5A614E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1D651A53-6755-465B-93FC-FA537A5A614E}.Debug|x64.ActiveCfg = Debug|Any CPU - {1D651A53-6755-465B-93FC-FA537A5A614E}.Debug|x64.Build.0 = Debug|Any CPU - {1D651A53-6755-465B-93FC-FA537A5A614E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1D651A53-6755-465B-93FC-FA537A5A614E}.Release|Any CPU.Build.0 = Release|Any CPU - {1D651A53-6755-465B-93FC-FA537A5A614E}.Release|x64.ActiveCfg = Release|Any CPU - {1D651A53-6755-465B-93FC-FA537A5A614E}.Release|x64.Build.0 = Release|Any CPU - {DB98D551-C74A-426E-AF15-D1D49610E00E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DB98D551-C74A-426E-AF15-D1D49610E00E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DB98D551-C74A-426E-AF15-D1D49610E00E}.Debug|x64.ActiveCfg = Debug|Any CPU - {DB98D551-C74A-426E-AF15-D1D49610E00E}.Debug|x64.Build.0 = Debug|Any CPU - {DB98D551-C74A-426E-AF15-D1D49610E00E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DB98D551-C74A-426E-AF15-D1D49610E00E}.Release|Any CPU.Build.0 = Release|Any CPU - {DB98D551-C74A-426E-AF15-D1D49610E00E}.Release|x64.ActiveCfg = Release|Any CPU - {DB98D551-C74A-426E-AF15-D1D49610E00E}.Release|x64.Build.0 = Release|Any CPU - {B49EFCCA-3E5D-4E26-8E83-4070C6FE34C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B49EFCCA-3E5D-4E26-8E83-4070C6FE34C8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B49EFCCA-3E5D-4E26-8E83-4070C6FE34C8}.Debug|x64.ActiveCfg = Debug|Any CPU - {B49EFCCA-3E5D-4E26-8E83-4070C6FE34C8}.Debug|x64.Build.0 = Debug|Any CPU - {B49EFCCA-3E5D-4E26-8E83-4070C6FE34C8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B49EFCCA-3E5D-4E26-8E83-4070C6FE34C8}.Release|Any CPU.Build.0 = Release|Any CPU - {B49EFCCA-3E5D-4E26-8E83-4070C6FE34C8}.Release|x64.ActiveCfg = Release|Any CPU - {B49EFCCA-3E5D-4E26-8E83-4070C6FE34C8}.Release|x64.Build.0 = Release|Any CPU - {CAEA84EF-B121-48AE-AE0F-AFB514A3FAFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CAEA84EF-B121-48AE-AE0F-AFB514A3FAFF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CAEA84EF-B121-48AE-AE0F-AFB514A3FAFF}.Debug|x64.ActiveCfg = Debug|Any CPU - {CAEA84EF-B121-48AE-AE0F-AFB514A3FAFF}.Debug|x64.Build.0 = Debug|Any CPU - {CAEA84EF-B121-48AE-AE0F-AFB514A3FAFF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CAEA84EF-B121-48AE-AE0F-AFB514A3FAFF}.Release|Any CPU.Build.0 = Release|Any CPU - {CAEA84EF-B121-48AE-AE0F-AFB514A3FAFF}.Release|x64.ActiveCfg = Release|Any CPU - {CAEA84EF-B121-48AE-AE0F-AFB514A3FAFF}.Release|x64.Build.0 = Release|Any CPU - {6498D3E6-6C87-4955-8686-38817EEDC23E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6498D3E6-6C87-4955-8686-38817EEDC23E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6498D3E6-6C87-4955-8686-38817EEDC23E}.Debug|x64.ActiveCfg = Debug|Any CPU - {6498D3E6-6C87-4955-8686-38817EEDC23E}.Debug|x64.Build.0 = Debug|Any CPU - {6498D3E6-6C87-4955-8686-38817EEDC23E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6498D3E6-6C87-4955-8686-38817EEDC23E}.Release|Any CPU.Build.0 = Release|Any CPU - {6498D3E6-6C87-4955-8686-38817EEDC23E}.Release|x64.ActiveCfg = Release|Any CPU - {6498D3E6-6C87-4955-8686-38817EEDC23E}.Release|x64.Build.0 = Release|Any CPU + {A8DF9393-9D67-460C-86F3-1D3C65A80D0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A8DF9393-9D67-460C-86F3-1D3C65A80D0A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A8DF9393-9D67-460C-86F3-1D3C65A80D0A}.Debug|x64.ActiveCfg = Debug|Any CPU + {A8DF9393-9D67-460C-86F3-1D3C65A80D0A}.Debug|x64.Build.0 = Debug|Any CPU + {A8DF9393-9D67-460C-86F3-1D3C65A80D0A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A8DF9393-9D67-460C-86F3-1D3C65A80D0A}.Release|Any CPU.Build.0 = Release|Any CPU + {A8DF9393-9D67-460C-86F3-1D3C65A80D0A}.Release|x64.ActiveCfg = Release|Any CPU + {A8DF9393-9D67-460C-86F3-1D3C65A80D0A}.Release|x64.Build.0 = Release|Any CPU + {ACAB7D42-CCB3-4559-9DB7-B969C52A833D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ACAB7D42-CCB3-4559-9DB7-B969C52A833D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ACAB7D42-CCB3-4559-9DB7-B969C52A833D}.Debug|x64.ActiveCfg = Debug|Any CPU + {ACAB7D42-CCB3-4559-9DB7-B969C52A833D}.Debug|x64.Build.0 = Debug|Any CPU + {ACAB7D42-CCB3-4559-9DB7-B969C52A833D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ACAB7D42-CCB3-4559-9DB7-B969C52A833D}.Release|Any CPU.Build.0 = Release|Any CPU + {ACAB7D42-CCB3-4559-9DB7-B969C52A833D}.Release|x64.ActiveCfg = Release|Any CPU + {ACAB7D42-CCB3-4559-9DB7-B969C52A833D}.Release|x64.Build.0 = Release|Any CPU + {4DA3E063-9F5A-4361-8EFE-8727409B238D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4DA3E063-9F5A-4361-8EFE-8727409B238D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4DA3E063-9F5A-4361-8EFE-8727409B238D}.Debug|x64.ActiveCfg = Debug|Any CPU + {4DA3E063-9F5A-4361-8EFE-8727409B238D}.Debug|x64.Build.0 = Debug|Any CPU + {4DA3E063-9F5A-4361-8EFE-8727409B238D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4DA3E063-9F5A-4361-8EFE-8727409B238D}.Release|Any CPU.Build.0 = Release|Any CPU + {4DA3E063-9F5A-4361-8EFE-8727409B238D}.Release|x64.ActiveCfg = Release|Any CPU + {4DA3E063-9F5A-4361-8EFE-8727409B238D}.Release|x64.Build.0 = Release|Any CPU + {BDCE7250-A5B0-4AA6-BEB6-B799C12990EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BDCE7250-A5B0-4AA6-BEB6-B799C12990EF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BDCE7250-A5B0-4AA6-BEB6-B799C12990EF}.Debug|x64.ActiveCfg = Debug|Any CPU + {BDCE7250-A5B0-4AA6-BEB6-B799C12990EF}.Debug|x64.Build.0 = Debug|Any CPU + {BDCE7250-A5B0-4AA6-BEB6-B799C12990EF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BDCE7250-A5B0-4AA6-BEB6-B799C12990EF}.Release|Any CPU.Build.0 = Release|Any CPU + {BDCE7250-A5B0-4AA6-BEB6-B799C12990EF}.Release|x64.ActiveCfg = Release|Any CPU + {BDCE7250-A5B0-4AA6-BEB6-B799C12990EF}.Release|x64.Build.0 = Release|Any CPU + {17640C6E-2797-4D51-AF97-F2D1B5C47623}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {17640C6E-2797-4D51-AF97-F2D1B5C47623}.Debug|Any CPU.Build.0 = Debug|Any CPU + {17640C6E-2797-4D51-AF97-F2D1B5C47623}.Debug|x64.ActiveCfg = Debug|Any CPU + {17640C6E-2797-4D51-AF97-F2D1B5C47623}.Debug|x64.Build.0 = Debug|Any CPU + {17640C6E-2797-4D51-AF97-F2D1B5C47623}.Release|Any CPU.ActiveCfg = Release|Any CPU + {17640C6E-2797-4D51-AF97-F2D1B5C47623}.Release|Any CPU.Build.0 = Release|Any CPU + {17640C6E-2797-4D51-AF97-F2D1B5C47623}.Release|x64.ActiveCfg = Release|Any CPU + {17640C6E-2797-4D51-AF97-F2D1B5C47623}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -121,12 +111,11 @@ Global {42226933-0A0D-48E8-85EC-AFE773A1F841} = {2635EC9B-2E5F-4313-AC21-0B847F31F36C} {64264688-0F5C-4AB0-8F2B-B59B717CCE00} = {2635EC9B-2E5F-4313-AC21-0B847F31F36C} {D5293208-2BEF-42FC-A64C-5954F61720BA} = {2635EC9B-2E5F-4313-AC21-0B847F31F36C} - {B99E1F96-5989-41FF-A4FB-90EFD5C3099F} = {64264688-0F5C-4AB0-8F2B-B59B717CCE00} - {1D651A53-6755-465B-93FC-FA537A5A614E} = {64264688-0F5C-4AB0-8F2B-B59B717CCE00} - {DB98D551-C74A-426E-AF15-D1D49610E00E} = {D5293208-2BEF-42FC-A64C-5954F61720BA} - {B49EFCCA-3E5D-4E26-8E83-4070C6FE34C8} = {42226933-0A0D-48E8-85EC-AFE773A1F841} - {CAEA84EF-B121-48AE-AE0F-AFB514A3FAFF} = {42226933-0A0D-48E8-85EC-AFE773A1F841} - {6498D3E6-6C87-4955-8686-38817EEDC23E} = {D5293208-2BEF-42FC-A64C-5954F61720BA} + {A8DF9393-9D67-460C-86F3-1D3C65A80D0A} = {D5293208-2BEF-42FC-A64C-5954F61720BA} + {ACAB7D42-CCB3-4559-9DB7-B969C52A833D} = {64264688-0F5C-4AB0-8F2B-B59B717CCE00} + {4DA3E063-9F5A-4361-8EFE-8727409B238D} = {64264688-0F5C-4AB0-8F2B-B59B717CCE00} + {BDCE7250-A5B0-4AA6-BEB6-B799C12990EF} = {42226933-0A0D-48E8-85EC-AFE773A1F841} + {17640C6E-2797-4D51-AF97-F2D1B5C47623} = {42226933-0A0D-48E8-85EC-AFE773A1F841} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19} diff --git a/README.md b/README.md index 482018e0..eb5e1a8a 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ **BotSharp** is an open source machine learning framework for AI Bot platform builder. This project involves natural language understanding, computer vision and audio processing technologies, and aims to promote the development and application of intelligent robot assistants in information systems. Out-of-the-box machine learning algorithms allow ordinary programmers to develop artificial intelligence applications faster and easier. -It's written in C# running on .Net Core that is full cross-platform framework. C# is a enterprise grade programming language which is widely used to code business logic in information management related system. More friendly to corporate developers. BotSharp adopts machine learning algrithm in C# directly. That will facilitate the feature of the typed language C#, and be more easier when refactoring code in system scope. +It's written in C# running on .Net Core that is full cross-platform framework, the plug-in and pipeline flow execution design is adopted to completely decouple the plug-ins. C# is a enterprise grade programming language which is widely used to code business logic in information management related system. More friendly to corporate developers. BotSharp adopts machine learning algrithm in C# directly. That will facilitate the feature of the typed language C#, and be more easier when refactoring code in system scope. Why we do this? Because we all know Python is not friendly programming language for enterprise developers, it's not only because it's low performance but also it's a type weak language, it will be a disaster if you use Python to build your bussiness system. diff --git a/src/Infrastructure/BotSharp.Abstraction/ApiAdapters/IApiAdapter.cs b/src/Infrastructure/BotSharp.Abstraction/ApiAdapters/IApiAdapter.cs new file mode 100644 index 00000000..1087312b --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/ApiAdapters/IApiAdapter.cs @@ -0,0 +1,5 @@ +namespace BotSharp.Abstraction.ApiAdapters; + +public interface IApiAdapter +{ +} diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/ISessionService.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/ISessionService.cs index fa59ae28..99e61e6d 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Conversations/ISessionService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/ISessionService.cs @@ -4,7 +4,7 @@ namespace BotSharp.Abstraction.Conversations; public interface ISessionService { - SessionModel NewSession(string userId); + Task NewSession(string userId); List GetAllSessions(string userId); void DeleteSession(string sessionId); } diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/MessageModel.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/MessageModel.cs new file mode 100644 index 00000000..0a625d68 --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/Models/MessageModel.cs @@ -0,0 +1,7 @@ +namespace BotSharp.Abstraction.Conversations.Models; + +public class MessageModel +{ + public string From { get; set; } + public string Content { get; set; } +} diff --git a/src/Infrastructure/BotSharp.Abstraction/IBotUiAdapter.cs b/src/Infrastructure/BotSharp.Abstraction/IBotUiAdapter.cs deleted file mode 100644 index 5d4bfc40..00000000 --- a/src/Infrastructure/BotSharp.Abstraction/IBotUiAdapter.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BotSharp.Abstraction; - -public interface IBotUiAdapter -{ -} diff --git a/src/Infrastructure/BotSharp.Abstraction/Plugins/IBotSharpPlugin.cs b/src/Infrastructure/BotSharp.Abstraction/Plugins/IBotSharpPlugin.cs new file mode 100644 index 00000000..b300c140 --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Plugins/IBotSharpPlugin.cs @@ -0,0 +1,5 @@ +namespace BotSharp.Abstraction.Plugins; + +public interface IBotSharpPlugin +{ +} diff --git a/src/Infrastructure/BotSharp.Abstraction/IChatCompletionHandler.cs b/src/Infrastructure/BotSharp.Abstraction/TextCompletions/ITextCompletionProvider.cs similarity index 70% rename from src/Infrastructure/BotSharp.Abstraction/IChatCompletionHandler.cs rename to src/Infrastructure/BotSharp.Abstraction/TextCompletions/ITextCompletionProvider.cs index bed4600e..a5e03bb0 100644 --- a/src/Infrastructure/BotSharp.Abstraction/IChatCompletionHandler.cs +++ b/src/Infrastructure/BotSharp.Abstraction/TextCompletions/ITextCompletionProvider.cs @@ -1,12 +1,12 @@ using BotSharp.Abstraction.Models; -namespace BotSharp.Abstraction; +namespace BotSharp.Abstraction.TextCompletions; -public interface IChatCompletionHandler +public interface ITextCompletionProvider { string GetInstruction(); List GetChatSamples(); - Task GetChatCompletionsAsync(List conversations, + Task GetChatCompletionsAsync(List conversations, Func onChunkReceived); } diff --git a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj index ff8a1825..dd07f938 100644 --- a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj +++ b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj @@ -56,7 +56,9 @@ - + + + diff --git a/src/Infrastructure/BotSharp.Core/BotSharpServiceCollectionExtensions.cs b/src/Infrastructure/BotSharp.Core/BotSharpServiceCollectionExtensions.cs index f8b495ce..fd0b89d4 100644 --- a/src/Infrastructure/BotSharp.Core/BotSharpServiceCollectionExtensions.cs +++ b/src/Infrastructure/BotSharp.Core/BotSharpServiceCollectionExtensions.cs @@ -1,5 +1,7 @@ using BotSharp.Abstraction.Conversations; +using BotSharp.Abstraction.TextCompletions; using BotSharp.Core.Conversations; +using BotSharp.Core.Plugins.TextCompletions.LLamaSharp; using BotSharp.Core.Repository; using BotSharp.Core.Services; using EntityFrameworkCore.BootKit; @@ -55,5 +57,13 @@ public static class BotSharpServiceCollectionExtensions { return DataContextHelper.GetDbContext(myDatabaseSettings, x); }); + + services.AddSingleton(x => + { + var settings = new LlamaSharpSettings(); + config.Bind("LlamaSharp", settings); + return settings; + }); + services.AddSingleton(); } } diff --git a/src/Infrastructure/BotSharp.Core/Conversations/SessionService.cs b/src/Infrastructure/BotSharp.Core/Conversations/SessionService.cs index 1964814d..7278f7ea 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/SessionService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/SessionService.cs @@ -1,7 +1,11 @@ using BotSharp.Abstraction.Conversations; using BotSharp.Abstraction.Conversations.Models; using BotSharp.Core.Repository; +using BotSharp.Core.Repository.Collections; +using EntityFrameworkCore.BootKit; using Microsoft.Extensions.DependencyInjection; +using MongoDB.Bson; +using MongoDB.Driver; namespace BotSharp.Core.Conversations; @@ -24,13 +28,23 @@ public class SessionService : ISessionService throw new NotImplementedException(); } - public SessionModel NewSession(string userId) + public async Task NewSession(string userId) { var mongo = _services.CreateScope().ServiceProvider.GetRequiredService(); + var record = new Conversation + { + CreatedAt = DateTime.UtcNow, + Messages = new List(), + UserId = "anonymous", + Model = "OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5" + }; + await mongo.Conversations.InsertOneAsync(record); + return new SessionModel { - SessionId = Guid.NewGuid().ToString() + SessionId = record.Id.ToString(), + UserId = record.UserId }; } } diff --git a/src/Infrastructure/BotSharp.Core/Services/PlatformMidware.cs b/src/Infrastructure/BotSharp.Core/Plugins/PlatformMidware.cs similarity index 87% rename from src/Infrastructure/BotSharp.Core/Services/PlatformMidware.cs rename to src/Infrastructure/BotSharp.Core/Plugins/PlatformMidware.cs index 211995e3..3ed40ee4 100644 --- a/src/Infrastructure/BotSharp.Core/Services/PlatformMidware.cs +++ b/src/Infrastructure/BotSharp.Core/Plugins/PlatformMidware.cs @@ -1,5 +1,6 @@ using BotSharp.Abstraction.Conversations; using BotSharp.Abstraction.Models; +using BotSharp.Abstraction.TextCompletions; using Microsoft.Extensions.DependencyInjection; namespace BotSharp.Core.Services; @@ -20,7 +21,7 @@ public class PlatformMidware : IPlatformMidware public async Task GetChatCompletionsAsync(List conversations, Func onChunkReceived) { - var handlers = _services.GetServices().ToList(); + var handlers = _services.GetServices().ToList(); for (int i = 0; i < handlers.Count(); i++) { var handler = handlers[i]; diff --git a/src/Plugins/Platforms/BotSharp.Platform.Native/Handlers/ChatCompletionHandler.cs b/src/Infrastructure/BotSharp.Core/Plugins/TextCompletions/LLamaSharp/LlamaSharpCompletionProvider.cs similarity index 80% rename from src/Plugins/Platforms/BotSharp.Platform.Native/Handlers/ChatCompletionHandler.cs rename to src/Infrastructure/BotSharp.Core/Plugins/TextCompletions/LLamaSharp/LlamaSharpCompletionProvider.cs index 1abce353..581c1c79 100644 --- a/src/Plugins/Platforms/BotSharp.Platform.Native/Handlers/ChatCompletionHandler.cs +++ b/src/Infrastructure/BotSharp.Core/Plugins/TextCompletions/LLamaSharp/LlamaSharpCompletionProvider.cs @@ -1,29 +1,23 @@ -using BotSharp.Abstraction; using BotSharp.Abstraction.Models; -using BotSharp.Platform.Native.Settings; +using BotSharp.Abstraction.Plugins; +using BotSharp.Abstraction.TextCompletions; using LLama; -using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Runtime; -using System.Text; -using System.Threading.Tasks; -namespace BotSharp.Platform.Native.Handlers; +namespace BotSharp.Core.Plugins.TextCompletions.LLamaSharp; -public class ChatCompletionHandler : IChatCompletionHandler +public class LlamaSharpCompletionProvider : ITextCompletionProvider, IBotSharpPlugin { private readonly IChatModel _model; private readonly LlamaSharpSettings _settings; - public ChatCompletionHandler(LlamaSharpSettings settings) + public LlamaSharpCompletionProvider(LlamaSharpSettings settings) { _settings = settings; - _model = new LLamaModel(new LLamaParams(model: _settings.ModelPath, - n_ctx: _settings.MaxContextLength, - interactive: _settings.Interactive, - repeat_penalty: _settings.RepeatPenalty, + _model = new LLamaModel(new LLamaParams(model: _settings.ModelPath, + n_ctx: _settings.MaxContextLength, + interactive: _settings.Interactive, + repeat_penalty: _settings.RepeatPenalty, verbose_prompt: _settings.VerbosePrompt, n_gpu_layers: _settings.NumberOfGpuLayer)); diff --git a/src/Plugins/Platforms/BotSharp.Platform.Native/Settings/LlamaSharpSettings.cs b/src/Infrastructure/BotSharp.Core/Plugins/TextCompletions/LLamaSharp/LlamaSharpSettings.cs similarity index 88% rename from src/Plugins/Platforms/BotSharp.Platform.Native/Settings/LlamaSharpSettings.cs rename to src/Infrastructure/BotSharp.Core/Plugins/TextCompletions/LLamaSharp/LlamaSharpSettings.cs index 7246b40d..a69f446e 100644 --- a/src/Plugins/Platforms/BotSharp.Platform.Native/Settings/LlamaSharpSettings.cs +++ b/src/Infrastructure/BotSharp.Core/Plugins/TextCompletions/LLamaSharp/LlamaSharpSettings.cs @@ -1,4 +1,4 @@ -namespace BotSharp.Platform.Native.Settings; +namespace BotSharp.Core.Plugins.TextCompletions.LLamaSharp; public class LlamaSharpSettings { diff --git a/src/Infrastructure/BotSharp.Core/Repository/Collections/Conversation.cs b/src/Infrastructure/BotSharp.Core/Repository/Collections/Conversation.cs new file mode 100644 index 00000000..e61f5813 --- /dev/null +++ b/src/Infrastructure/BotSharp.Core/Repository/Collections/Conversation.cs @@ -0,0 +1,22 @@ +using BotSharp.Abstraction.Conversations.Models; +using MongoDB.Bson; +using MongoDB.Bson.Serialization.Attributes; +using MongoDB.Bson.Serialization.IdGenerators; + +namespace BotSharp.Core.Repository.Collections; + +public class Conversation : IMongoDbCollection +{ + [BsonId(IdGenerator = typeof(ObjectIdGenerator))] + public ObjectId Id { get; set; } + + public string SessionId { get; set; } + public string UserId { get; set; } + public string Model { get; set; } + + public string Title { get; set; } + public List Messages { get; set; } + + public DateTime CreatedAt { get; set; } + public DateTime UpdatedAt { get; set; } +} diff --git a/src/Infrastructure/BotSharp.Core/Repository/DataContextHelper.cs b/src/Infrastructure/BotSharp.Core/Repository/DataContextHelper.cs index 139a2199..3110218f 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/DataContextHelper.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/DataContextHelper.cs @@ -1,5 +1,5 @@ using EntityFrameworkCore.BootKit; -using Microsoft.Data.SqlClient; +using System.Data.Common; namespace BotSharp.Core.Repository; @@ -14,13 +14,13 @@ public static class DataContextHelper AppDomain.CurrentDomain.SetData("Assemblies", settings.Assemblies); var dc = new T(); - if (typeof(T) == typeof(DbContext4MongoDb)) + if (typeof(T) == typeof(MongoDbContext)) { dc.BindDbContext(new DatabaseBind { ServiceProvider = serviceProvider, - MasterConnection = new MongoDbConnection("mongodb://user:password@localhost:27017"), - CreateDbIfNotExist = true + MasterConnection = new MongoDbConnection(settings.MongoDb.Master), + IsRelational = false }); } return dc; diff --git a/src/Infrastructure/BotSharp.Core/Repository/IMongoDbCollection.cs b/src/Infrastructure/BotSharp.Core/Repository/IMongoDbCollection.cs index a3bebd79..b91b1a4e 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/IMongoDbCollection.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/IMongoDbCollection.cs @@ -1,5 +1,8 @@ +using MongoDB.Bson; + namespace BotSharp.Core.Repository; public interface IMongoDbCollection { + ObjectId Id { get; set; } } diff --git a/src/Infrastructure/BotSharp.Core/Repository/MongoDbContext.cs b/src/Infrastructure/BotSharp.Core/Repository/MongoDbContext.cs index c2279b08..389bb2eb 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/MongoDbContext.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/MongoDbContext.cs @@ -1,7 +1,11 @@ +using BotSharp.Core.Repository.Collections; using EntityFrameworkCore.BootKit; +using MongoDB.Driver; namespace BotSharp.Core.Repository; public class MongoDbContext : Database { + public IMongoCollection Conversations + => Collection("conversations"); } diff --git a/src/Plugins/Channels/BotSharp.Channel.FacebookMessenger/BotSharp.Channel.FacebookMessenger.csproj b/src/Plugins/Channels/BotSharp.Channel.FacebookMessenger/BotSharp.Channel.FacebookMessenger.csproj deleted file mode 100644 index d4c395e8..00000000 --- a/src/Plugins/Channels/BotSharp.Channel.FacebookMessenger/BotSharp.Channel.FacebookMessenger.csproj +++ /dev/null @@ -1,7 +0,0 @@ - - - - netstandard2.1 - - - diff --git a/src/Plugins/Platforms/BotSharp.Platform.Native/BotSharp.Platform.Native.csproj b/src/Plugins/Messages/BotSharp.Channel.FacebookMessenger/BotSharp.Plugin.FacebookMessenger.csproj similarity index 52% rename from src/Plugins/Platforms/BotSharp.Platform.Native/BotSharp.Platform.Native.csproj rename to src/Plugins/Messages/BotSharp.Channel.FacebookMessenger/BotSharp.Plugin.FacebookMessenger.csproj index 38285e33..3590be46 100644 --- a/src/Plugins/Platforms/BotSharp.Platform.Native/BotSharp.Platform.Native.csproj +++ b/src/Plugins/Messages/BotSharp.Channel.FacebookMessenger/BotSharp.Plugin.FacebookMessenger.csproj @@ -2,17 +2,10 @@ netstandard2.1 - enable - 10 - - - - - - \ No newline at end of file + diff --git a/src/Plugins/Channels/BotSharp.Channel.Weixin/BotSharp.Channel.Weixin.csproj b/src/Plugins/Messages/BotSharp.Channel.Weixin/BotSharp.Plugin.Weixin.csproj similarity index 86% rename from src/Plugins/Channels/BotSharp.Channel.Weixin/BotSharp.Channel.Weixin.csproj rename to src/Plugins/Messages/BotSharp.Channel.Weixin/BotSharp.Plugin.Weixin.csproj index d1ee4dc0..dfc83769 100644 --- a/src/Plugins/Channels/BotSharp.Channel.Weixin/BotSharp.Channel.Weixin.csproj +++ b/src/Plugins/Messages/BotSharp.Channel.Weixin/BotSharp.Plugin.Weixin.csproj @@ -23,4 +23,8 @@ + + + + diff --git a/src/Plugins/Channels/BotSharp.Channel.Weixin/README.md b/src/Plugins/Messages/BotSharp.Channel.Weixin/README.md similarity index 100% rename from src/Plugins/Channels/BotSharp.Channel.Weixin/README.md rename to src/Plugins/Messages/BotSharp.Channel.Weixin/README.md diff --git a/src/Plugins/Platforms/BotSharp.Platform.Native/BotSharplServiceCollectionExtensions.cs b/src/Plugins/Platforms/BotSharp.Platform.Native/BotSharplServiceCollectionExtensions.cs deleted file mode 100644 index 6571e409..00000000 --- a/src/Plugins/Platforms/BotSharp.Platform.Native/BotSharplServiceCollectionExtensions.cs +++ /dev/null @@ -1,22 +0,0 @@ -using BotSharp.Abstraction; -using BotSharp.Platform.Native.Handlers; -using BotSharp.Platform.Native.Settings; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; - -namespace BotSharp.Core; - -public static class BotSharplServiceCollectionExtensions -{ - public static IServiceCollection AddBotSharpPlatform(this IServiceCollection services, IConfiguration config) - { - services.AddSingleton(x => - { - var settings = new LlamaSharpSettings(); - config.Bind("LlamaSharp", settings); - return settings; - }); - services.AddSingleton(); - return services; - } -} \ No newline at end of file diff --git a/src/Plugins/Platforms/BotSharp.Platform.OpenAi/BotSharp.Platform.OpenAi.csproj b/src/Plugins/Platforms/BotSharp.Platform.OpenAi/BotSharp.Platform.OpenAi.csproj deleted file mode 100644 index 736b7ffd..00000000 --- a/src/Plugins/Platforms/BotSharp.Platform.OpenAi/BotSharp.Platform.OpenAi.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - netstandard2.1 - enable - 10 - - - diff --git a/src/Plugins/Platforms/BotSharp.Platform.AureAi/AzureAiServiceCollectionExtensions.cs b/src/Plugins/Platforms/BotSharp.Plugin.AureOpenAI/AzureAiServiceCollectionExtensions.cs similarity index 81% rename from src/Plugins/Platforms/BotSharp.Platform.AureAi/AzureAiServiceCollectionExtensions.cs rename to src/Plugins/Platforms/BotSharp.Plugin.AureOpenAI/AzureAiServiceCollectionExtensions.cs index 5d97f1de..822fa2bc 100644 --- a/src/Plugins/Platforms/BotSharp.Platform.AureAi/AzureAiServiceCollectionExtensions.cs +++ b/src/Plugins/Platforms/BotSharp.Plugin.AureOpenAI/AzureAiServiceCollectionExtensions.cs @@ -1,4 +1,4 @@ -using BotSharp.Abstraction; +using BotSharp.Abstraction.TextCompletions; using BotSharp.Platform.AzureAi; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -15,7 +15,7 @@ public static class AzureAiServiceCollectionExtensions config.Bind("AzureAi", settings); return settings; }); - services.AddScoped(); + services.AddScoped(); return services; } } \ No newline at end of file diff --git a/src/Plugins/Platforms/BotSharp.Platform.AureAi/AzureAiSettings.cs b/src/Plugins/Platforms/BotSharp.Plugin.AureOpenAI/AzureAiSettings.cs similarity index 100% rename from src/Plugins/Platforms/BotSharp.Platform.AureAi/AzureAiSettings.cs rename to src/Plugins/Platforms/BotSharp.Plugin.AureOpenAI/AzureAiSettings.cs diff --git a/src/Plugins/Platforms/BotSharp.Platform.AureAi/BotSharp.Platform.AzureAi.csproj b/src/Plugins/Platforms/BotSharp.Plugin.AureOpenAI/BotSharp.Plugin.AzureOpenAI.csproj similarity index 100% rename from src/Plugins/Platforms/BotSharp.Platform.AureAi/BotSharp.Platform.AzureAi.csproj rename to src/Plugins/Platforms/BotSharp.Plugin.AureOpenAI/BotSharp.Plugin.AzureOpenAI.csproj diff --git a/src/Plugins/Platforms/BotSharp.Platform.AureAi/Handlers/ChatCompletionHandler.cs b/src/Plugins/Platforms/BotSharp.Plugin.AureOpenAI/Providers/ChatCompletionHandler.cs similarity index 96% rename from src/Plugins/Platforms/BotSharp.Platform.AureAi/Handlers/ChatCompletionHandler.cs rename to src/Plugins/Platforms/BotSharp.Plugin.AureOpenAI/Providers/ChatCompletionHandler.cs index f1f42521..066e8db7 100644 --- a/src/Plugins/Platforms/BotSharp.Platform.AureAi/Handlers/ChatCompletionHandler.cs +++ b/src/Plugins/Platforms/BotSharp.Plugin.AureOpenAI/Providers/ChatCompletionHandler.cs @@ -1,7 +1,7 @@ using Azure; using Azure.AI.OpenAI; -using BotSharp.Abstraction; using BotSharp.Abstraction.Models; +using BotSharp.Abstraction.TextCompletions; using System; using System.Collections.Generic; using System.IO; @@ -9,7 +9,7 @@ using System.Threading.Tasks; namespace BotSharp.Platform.AzureAi; -public class ChatCompletionHandler : IChatCompletionHandler +public class ChatCompletionHandler : ITextCompletionProvider { private readonly AzureAiSettings _settings; diff --git a/src/Plugins/UiAdapters/BotSharp.UiAdapter.ChatbotUI/BotSharp.UIAdapter.ChatbotUI.csproj b/src/Plugins/UIs/BotSharp.Plugin.ChatbotUI/BotSharp.Plugin.ChatbotUI.csproj similarity index 100% rename from src/Plugins/UiAdapters/BotSharp.UiAdapter.ChatbotUI/BotSharp.UIAdapter.ChatbotUI.csproj rename to src/Plugins/UIs/BotSharp.Plugin.ChatbotUI/BotSharp.Plugin.ChatbotUI.csproj diff --git a/src/Plugins/UiAdapters/BotSharp.UiAdapter.ChatbotUI/Chatbot-UI.md b/src/Plugins/UIs/BotSharp.Plugin.ChatbotUI/Chatbot-UI.md similarity index 100% rename from src/Plugins/UiAdapters/BotSharp.UiAdapter.ChatbotUI/Chatbot-UI.md rename to src/Plugins/UIs/BotSharp.Plugin.ChatbotUI/Chatbot-UI.md diff --git a/src/Plugins/UiAdapters/BotSharp.UiAdapter.ChatbotUI/ChatbotUiController.cs b/src/Plugins/UIs/BotSharp.Plugin.ChatbotUI/ChatbotUiController.cs similarity index 94% rename from src/Plugins/UiAdapters/BotSharp.UiAdapter.ChatbotUI/ChatbotUiController.cs rename to src/Plugins/UIs/BotSharp.Plugin.ChatbotUI/ChatbotUiController.cs index 32d26de8..a3b2d225 100644 --- a/src/Plugins/UiAdapters/BotSharp.UiAdapter.ChatbotUI/ChatbotUiController.cs +++ b/src/Plugins/UIs/BotSharp.Plugin.ChatbotUI/ChatbotUiController.cs @@ -1,6 +1,5 @@ using BotSharp.Abstraction; using BotSharp.Abstraction.Models; -using ChatbotUI.ViewModels; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; @@ -13,11 +12,13 @@ using System.Text; using System.Threading.Tasks; using System; using Azure.AI.OpenAI; +using BotSharp.Abstraction.ApiAdapters; +using BotSharp.Plugin.ChatbotUI.ViewModels; -namespace BotSharp.Platform.AzureAi.Controllers; +namespace BotSharp.Plugin.ChatbotUI.Controllers; [ApiController] -public class ChatbotUiController : ControllerBase, IBotUiAdapter +public class ChatbotUiController : ControllerBase, IApiAdapter { private readonly ILogger _logger; private readonly IPlatformMidware _platform; diff --git a/src/Plugins/UiAdapters/BotSharp.UiAdapter.ChatbotUI/ViewModels/OpenAiChatOutput.cs b/src/Plugins/UIs/BotSharp.Plugin.ChatbotUI/ViewModels/OpenAiChatOutput.cs similarity index 71% rename from src/Plugins/UiAdapters/BotSharp.UiAdapter.ChatbotUI/ViewModels/OpenAiChatOutput.cs rename to src/Plugins/UIs/BotSharp.Plugin.ChatbotUI/ViewModels/OpenAiChatOutput.cs index c9de4233..34e55524 100644 --- a/src/Plugins/UiAdapters/BotSharp.UiAdapter.ChatbotUI/ViewModels/OpenAiChatOutput.cs +++ b/src/Plugins/UIs/BotSharp.Plugin.ChatbotUI/ViewModels/OpenAiChatOutput.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace ChatbotUI.ViewModels; +namespace BotSharp.Plugin.ChatbotUI.ViewModels; public class OpenAiChatOutput { diff --git a/src/Plugins/UiAdapters/BotSharp.UiAdapter.ChatbotUI/ViewModels/OpenAiChoice.cs b/src/Plugins/UIs/BotSharp.Plugin.ChatbotUI/ViewModels/OpenAiChoice.cs similarity index 82% rename from src/Plugins/UiAdapters/BotSharp.UiAdapter.ChatbotUI/ViewModels/OpenAiChoice.cs rename to src/Plugins/UIs/BotSharp.Plugin.ChatbotUI/ViewModels/OpenAiChoice.cs index cc780949..21c2597e 100644 --- a/src/Plugins/UiAdapters/BotSharp.UiAdapter.ChatbotUI/ViewModels/OpenAiChoice.cs +++ b/src/Plugins/UIs/BotSharp.Plugin.ChatbotUI/ViewModels/OpenAiChoice.cs @@ -1,7 +1,7 @@ using Azure.AI.OpenAI; using System.Text.Json.Serialization; -namespace ChatbotUI.ViewModels; +namespace BotSharp.Plugin.ChatbotUI.ViewModels; public class OpenAiChoice { diff --git a/src/Plugins/UiAdapters/BotSharp.UiAdapter.ChatbotUI/ViewModels/OpenAiMessageBody.cs b/src/Plugins/UIs/BotSharp.Plugin.ChatbotUI/ViewModels/OpenAiMessageBody.cs similarity index 70% rename from src/Plugins/UiAdapters/BotSharp.UiAdapter.ChatbotUI/ViewModels/OpenAiMessageBody.cs rename to src/Plugins/UIs/BotSharp.Plugin.ChatbotUI/ViewModels/OpenAiMessageBody.cs index b508afd0..da6db1f3 100644 --- a/src/Plugins/UiAdapters/BotSharp.UiAdapter.ChatbotUI/ViewModels/OpenAiMessageBody.cs +++ b/src/Plugins/UIs/BotSharp.Plugin.ChatbotUI/ViewModels/OpenAiMessageBody.cs @@ -1,4 +1,4 @@ -namespace ChatbotUI.ViewModels; +namespace BotSharp.Plugin.ChatbotUI.ViewModels; public class OpenAiMessageBody { diff --git a/src/Plugins/UiAdapters/BotSharp.UiAdapter.ChatbotUI/ViewModels/OpenAiMessageInput.cs b/src/Plugins/UIs/BotSharp.Plugin.ChatbotUI/ViewModels/OpenAiMessageInput.cs similarity index 92% rename from src/Plugins/UiAdapters/BotSharp.UiAdapter.ChatbotUI/ViewModels/OpenAiMessageInput.cs rename to src/Plugins/UIs/BotSharp.Plugin.ChatbotUI/ViewModels/OpenAiMessageInput.cs index b59e0f11..2cbbf286 100644 --- a/src/Plugins/UiAdapters/BotSharp.UiAdapter.ChatbotUI/ViewModels/OpenAiMessageInput.cs +++ b/src/Plugins/UIs/BotSharp.Plugin.ChatbotUI/ViewModels/OpenAiMessageInput.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text.Json.Serialization; -namespace ChatbotUI.ViewModels; +namespace BotSharp.Plugin.ChatbotUI.ViewModels; public class OpenAiMessageInput { diff --git a/src/Plugins/UiAdapters/BotSharp.UiAdapter.ChatbotUI/ViewModels/OpenAiModels.cs b/src/Plugins/UIs/BotSharp.Plugin.ChatbotUI/ViewModels/OpenAiModels.cs similarity index 77% rename from src/Plugins/UiAdapters/BotSharp.UiAdapter.ChatbotUI/ViewModels/OpenAiModels.cs rename to src/Plugins/UIs/BotSharp.Plugin.ChatbotUI/ViewModels/OpenAiModels.cs index e6779227..f84c4c9e 100644 --- a/src/Plugins/UiAdapters/BotSharp.UiAdapter.ChatbotUI/ViewModels/OpenAiModels.cs +++ b/src/Plugins/UIs/BotSharp.Plugin.ChatbotUI/ViewModels/OpenAiModels.cs @@ -1,7 +1,7 @@ using BotSharp.Abstraction.Models; using System.Collections.Generic; -namespace ChatbotUI.ViewModels; +namespace BotSharp.Plugin.ChatbotUI.ViewModels; public class OpenAiModels { diff --git a/src/Plugins/UiAdapters/BotSharp.UiAdapter.HuggingChatUI/BotSharp.UIAdapter.HuggingChatUI.csproj b/src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/BotSharp.Plugin.HuggingChatUI.csproj similarity index 100% rename from src/Plugins/UiAdapters/BotSharp.UiAdapter.HuggingChatUI/BotSharp.UIAdapter.HuggingChatUI.csproj rename to src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/BotSharp.Plugin.HuggingChatUI.csproj diff --git a/src/Plugins/UiAdapters/BotSharp.UiAdapter.HuggingChatUI/HuggingChat-UI.md b/src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/HuggingChat-UI.md similarity index 91% rename from src/Plugins/UiAdapters/BotSharp.UiAdapter.HuggingChatUI/HuggingChat-UI.md rename to src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/HuggingChat-UI.md index 908f15b1..c0b0618c 100644 --- a/src/Plugins/UiAdapters/BotSharp.UiAdapter.HuggingChatUI/HuggingChat-UI.md +++ b/src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/HuggingChat-UI.md @@ -18,7 +18,7 @@ export const BASE_URL = `http://localhost:5500${base}`; Add BotSharp host in the API endpoint ```svelte -import { BASE_URL } from '$lib/clientConfig.js' +import { BASE_URL } from '$lib/clientConfig' # Change all ${base} to ${BASE_URL} ${base}/conversation -> ${BASE_URL}/conversation ``` diff --git a/src/Plugins/UiAdapters/BotSharp.UiAdapter.HuggingChatUI/HuggingChatUiController.cs b/src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/HuggingChatUiController.cs similarity index 50% rename from src/Plugins/UiAdapters/BotSharp.UiAdapter.HuggingChatUI/HuggingChatUiController.cs rename to src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/HuggingChatUiController.cs index ff1e7f90..d9a1c38c 100644 --- a/src/Plugins/UiAdapters/BotSharp.UiAdapter.HuggingChatUI/HuggingChatUiController.cs +++ b/src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/HuggingChatUiController.cs @@ -1,11 +1,13 @@ using BotSharp.Abstraction; -using HuggingChatUI.ViewModels; +using BotSharp.Abstraction.ApiAdapters; +using BotSharp.Plugin.HuggingChatUI.ViewModels; using Microsoft.AspNetCore.Mvc; using System; +using System.Threading.Tasks; -namespace HuggingChatUI; +namespace BotSharp.Plugin.HuggingChatUI.Controllers; -public class HuggingChatUiController : ControllerBase, IBotUiAdapter +public class HuggingChatUiController : ControllerBase, IApiAdapter { private readonly IPlatformMidware _platform; public HuggingChatUiController(IPlatformMidware platform) @@ -14,12 +16,12 @@ public class HuggingChatUiController : ControllerBase, IBotUiAdapter } [HttpPost("conversation")] - public ConversationViewModel NewSession([FromBody] ConversationCreationModel conversationCreationModel) + public async Task NewSession([FromBody] ConversationCreationModel conversationCreationModel) { - var session = _platform.SessionService.NewSession(""); + var session = await _platform.SessionService.NewSession("anonymous"); return new ConversationViewModel { - ConversationId = session.SessionId.Replace("-", "").Substring(0, 24) + ConversationId = session.SessionId }; } diff --git a/src/Plugins/UiAdapters/BotSharp.UiAdapter.HuggingChatUI/ViewModels/ConversationCreationModel.cs b/src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/ViewModels/ConversationCreationModel.cs similarity index 61% rename from src/Plugins/UiAdapters/BotSharp.UiAdapter.HuggingChatUI/ViewModels/ConversationCreationModel.cs rename to src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/ViewModels/ConversationCreationModel.cs index bc163860..53dee353 100644 --- a/src/Plugins/UiAdapters/BotSharp.UiAdapter.HuggingChatUI/ViewModels/ConversationCreationModel.cs +++ b/src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/ViewModels/ConversationCreationModel.cs @@ -1,4 +1,4 @@ -namespace HuggingChatUI.ViewModels; +namespace BotSharp.Plugin.HuggingChatUI.ViewModels; public class ConversationCreationModel { diff --git a/src/Plugins/UiAdapters/BotSharp.UiAdapter.HuggingChatUI/ViewModels/ConversationViewModel.cs b/src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/ViewModels/ConversationViewModel.cs similarity index 62% rename from src/Plugins/UiAdapters/BotSharp.UiAdapter.HuggingChatUI/ViewModels/ConversationViewModel.cs rename to src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/ViewModels/ConversationViewModel.cs index 34415754..79ad81f5 100644 --- a/src/Plugins/UiAdapters/BotSharp.UiAdapter.HuggingChatUI/ViewModels/ConversationViewModel.cs +++ b/src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/ViewModels/ConversationViewModel.cs @@ -1,4 +1,4 @@ -namespace HuggingChatUI.ViewModels; +namespace BotSharp.Plugin.HuggingChatUI.ViewModels; public class ConversationViewModel { diff --git a/src/WebStarter/Program.cs b/src/WebStarter/Program.cs index 72b1fbdc..6624336a 100644 --- a/src/WebStarter/Program.cs +++ b/src/WebStarter/Program.cs @@ -12,7 +12,6 @@ builder.Services.AddHttpContextAccessor(); // Add BotSharp builder.Services.AddBotSharp(builder.Configuration); -builder.Services.AddBotSharpPlatform(builder.Configuration); // builder.Services.AddAzureOpenAiPlatform(builder.Configuration); builder.Services.AddCors(options => diff --git a/src/WebStarter/Prompts/chat-samples.txt b/src/WebStarter/Prompts/chat-samples.txt new file mode 100644 index 00000000..313d48b7 --- /dev/null +++ b/src/WebStarter/Prompts/chat-samples.txt @@ -0,0 +1,2 @@ +user: Hi +assistant: Hello, I'm a AI assistant to help you schedule meeting. \ No newline at end of file diff --git a/src/WebStarter/WebStarter.csproj b/src/WebStarter/WebStarter.csproj index e137d64e..89d1f353 100644 --- a/src/WebStarter/WebStarter.csproj +++ b/src/WebStarter/WebStarter.csproj @@ -27,10 +27,11 @@ - - - - + + + + + diff --git a/src/WebStarter/appsettings.json b/src/WebStarter/appsettings.json index 72eb9980..1507001f 100644 --- a/src/WebStarter/appsettings.json +++ b/src/WebStarter/appsettings.json @@ -14,7 +14,7 @@ "LlamaSharp": { "Interactive": true, - "ModelPath": "C:\\Users\\haipi\\Downloads\\ggml-vic13b-q5_1.bin", + "ModelPath": "C:\\Users\\haipi\\Downloads\\wizard-vicuna-13B.ggmlv3.q8_0.bin", "InstructionFile": "Prompts\\chat-with-bob.txt", "ChatSampleFile": "Prompts\\chat-samples.txt", "MaxContextLength": 2048, @@ -31,8 +31,9 @@ "Database": { "MongoDb": { - "Master": "mongodb://localhost:27017" + "Master": "mongodb://localhost:27017/chat-ui" }, + "UseCamelCase": true, "Assemblies": [ "BotSharp.Core" ] } }