From 2f25a55f80ee07b7b6443dad61806e52a635e263 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Sat, 3 Jun 2023 09:57:08 -0500 Subject: [PATCH] Rename to BotSharp.Platform.Native --- BotSharp.sln | 22 +++++++++---------- .../BotSharpServiceCollectionExtensions.cs | 6 +++-- .../Conversations/SessionService.cs | 10 ++++++--- .../BotSharp.Platform.Native.csproj} | 0 .../BotSharplServiceCollectionExtensions.cs} | 8 +++---- .../Handlers/ChatCompletionHandler.cs | 3 ++- .../Settings}/LlamaSharpSettings.cs | 2 +- src/WebStarter/Program.cs | 4 ++-- src/WebStarter/WebStarter.csproj | 2 +- 9 files changed, 32 insertions(+), 25 deletions(-) rename src/Plugins/Platforms/{BotSharp.Platform.Community/BotSharp.Platform.Community.csproj => BotSharp.Platform.Native/BotSharp.Platform.Native.csproj} (100%) rename src/Plugins/Platforms/{BotSharp.Platform.Community/LlamaSharplServiceCollectionExtensions.cs => BotSharp.Platform.Native/BotSharplServiceCollectionExtensions.cs} (63%) rename src/Plugins/Platforms/{BotSharp.Platform.Community => BotSharp.Platform.Native}/Handlers/ChatCompletionHandler.cs (96%) rename src/Plugins/Platforms/{BotSharp.Platform.Community => BotSharp.Platform.Native/Settings}/LlamaSharpSettings.cs (91%) diff --git a/BotSharp.sln b/BotSharp.sln index f2dfb5fa..e1b8f1fa 100644 --- a/BotSharp.sln +++ b/BotSharp.sln @@ -25,12 +25,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Channel.FacebookMe 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}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Platform.Community", "src\Plugins\Platforms\BotSharp.Platform.Community\BotSharp.Platform.Community.csproj", "{9101ADE3-F77A-4806-B3AF-1FFC38D0C88D}" -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}" 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}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -87,14 +87,6 @@ Global {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 - {9101ADE3-F77A-4806-B3AF-1FFC38D0C88D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9101ADE3-F77A-4806-B3AF-1FFC38D0C88D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9101ADE3-F77A-4806-B3AF-1FFC38D0C88D}.Debug|x64.ActiveCfg = Debug|Any CPU - {9101ADE3-F77A-4806-B3AF-1FFC38D0C88D}.Debug|x64.Build.0 = Debug|Any CPU - {9101ADE3-F77A-4806-B3AF-1FFC38D0C88D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9101ADE3-F77A-4806-B3AF-1FFC38D0C88D}.Release|Any CPU.Build.0 = Release|Any CPU - {9101ADE3-F77A-4806-B3AF-1FFC38D0C88D}.Release|x64.ActiveCfg = Release|Any CPU - {9101ADE3-F77A-4806-B3AF-1FFC38D0C88D}.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 @@ -111,6 +103,14 @@ Global {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 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -124,9 +124,9 @@ Global {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} - {9101ADE3-F77A-4806-B3AF-1FFC38D0C88D} = {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} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19} diff --git a/src/Infrastructure/BotSharp.Core/BotSharpServiceCollectionExtensions.cs b/src/Infrastructure/BotSharp.Core/BotSharpServiceCollectionExtensions.cs index 34cddefa..f8b495ce 100644 --- a/src/Infrastructure/BotSharp.Core/BotSharpServiceCollectionExtensions.cs +++ b/src/Infrastructure/BotSharp.Core/BotSharpServiceCollectionExtensions.cs @@ -11,11 +11,13 @@ namespace BotSharp.Core; public static class BotSharpServiceCollectionExtensions { - public static IServiceCollection AddBotSharp(this IServiceCollection services) + public static IServiceCollection AddBotSharp(this IServiceCollection services, IConfiguration config) { services.AddScoped(); + services.AddSingleton(); services.AddSingleton(); + RegisterRepository(services, config); return services; } @@ -33,7 +35,7 @@ public static class BotSharpServiceCollectionExtensions return app; } - public static void RegisterRepository(this IServiceCollection services, IConfiguration config) + public static void RegisterRepository(IServiceCollection services, IConfiguration config) { var databaseSettings = new DatabaseSettings(); config.Bind("Database", databaseSettings); diff --git a/src/Infrastructure/BotSharp.Core/Conversations/SessionService.cs b/src/Infrastructure/BotSharp.Core/Conversations/SessionService.cs index d35e92e7..1964814d 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/SessionService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/SessionService.cs @@ -1,15 +1,17 @@ using BotSharp.Abstraction.Conversations; using BotSharp.Abstraction.Conversations.Models; +using BotSharp.Core.Repository; +using Microsoft.Extensions.DependencyInjection; namespace BotSharp.Core.Conversations; public class SessionService : ISessionService { - Dictionary> _sessions; + private readonly IServiceProvider _services; - public SessionService() + public SessionService(IServiceProvider services) { - _sessions = new Dictionary>(); + _services = services; } public void DeleteSession(string sessionId) @@ -24,6 +26,8 @@ public class SessionService : ISessionService public SessionModel NewSession(string userId) { + var mongo = _services.CreateScope().ServiceProvider.GetRequiredService(); + return new SessionModel { SessionId = Guid.NewGuid().ToString() diff --git a/src/Plugins/Platforms/BotSharp.Platform.Community/BotSharp.Platform.Community.csproj b/src/Plugins/Platforms/BotSharp.Platform.Native/BotSharp.Platform.Native.csproj similarity index 100% rename from src/Plugins/Platforms/BotSharp.Platform.Community/BotSharp.Platform.Community.csproj rename to src/Plugins/Platforms/BotSharp.Platform.Native/BotSharp.Platform.Native.csproj diff --git a/src/Plugins/Platforms/BotSharp.Platform.Community/LlamaSharplServiceCollectionExtensions.cs b/src/Plugins/Platforms/BotSharp.Platform.Native/BotSharplServiceCollectionExtensions.cs similarity index 63% rename from src/Plugins/Platforms/BotSharp.Platform.Community/LlamaSharplServiceCollectionExtensions.cs rename to src/Plugins/Platforms/BotSharp.Platform.Native/BotSharplServiceCollectionExtensions.cs index ae78df12..cf32c3e8 100644 --- a/src/Plugins/Platforms/BotSharp.Platform.Community/LlamaSharplServiceCollectionExtensions.cs +++ b/src/Plugins/Platforms/BotSharp.Platform.Native/BotSharplServiceCollectionExtensions.cs @@ -1,14 +1,14 @@ using BotSharp.Abstraction; -using BotSharp.Platform.Community; -using BotSharp.Platform.Community.Handlers; +using BotSharp.Platform.Native.Handlers; +using BotSharp.Platform.Native.Settings; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; namespace BotSharp.Core; -public static class LlamaSharplServiceCollectionExtensions +public static class BotSharplServiceCollectionExtensions { - public static IServiceCollection AddLlamaSharp(this IServiceCollection services, IConfiguration config) + public static IServiceCollection AddBotSharpCommunityPlatform(this IServiceCollection services, IConfiguration config) { services.AddSingleton(x => { diff --git a/src/Plugins/Platforms/BotSharp.Platform.Community/Handlers/ChatCompletionHandler.cs b/src/Plugins/Platforms/BotSharp.Platform.Native/Handlers/ChatCompletionHandler.cs similarity index 96% rename from src/Plugins/Platforms/BotSharp.Platform.Community/Handlers/ChatCompletionHandler.cs rename to src/Plugins/Platforms/BotSharp.Platform.Native/Handlers/ChatCompletionHandler.cs index 5cdacc42..f03e264a 100644 --- a/src/Plugins/Platforms/BotSharp.Platform.Community/Handlers/ChatCompletionHandler.cs +++ b/src/Plugins/Platforms/BotSharp.Platform.Native/Handlers/ChatCompletionHandler.cs @@ -1,5 +1,6 @@ using BotSharp.Abstraction; using BotSharp.Abstraction.Models; +using BotSharp.Platform.Native.Settings; using LLama; using System; using System.Collections.Generic; @@ -9,7 +10,7 @@ using System.Runtime; using System.Text; using System.Threading.Tasks; -namespace BotSharp.Platform.Community.Handlers; +namespace BotSharp.Platform.Native.Handlers; public class ChatCompletionHandler : IChatCompletionHandler { diff --git a/src/Plugins/Platforms/BotSharp.Platform.Community/LlamaSharpSettings.cs b/src/Plugins/Platforms/BotSharp.Platform.Native/Settings/LlamaSharpSettings.cs similarity index 91% rename from src/Plugins/Platforms/BotSharp.Platform.Community/LlamaSharpSettings.cs rename to src/Plugins/Platforms/BotSharp.Platform.Native/Settings/LlamaSharpSettings.cs index 39ffbcd5..7246b40d 100644 --- a/src/Plugins/Platforms/BotSharp.Platform.Community/LlamaSharpSettings.cs +++ b/src/Plugins/Platforms/BotSharp.Platform.Native/Settings/LlamaSharpSettings.cs @@ -1,4 +1,4 @@ -namespace BotSharp.Platform.Community; +namespace BotSharp.Platform.Native.Settings; public class LlamaSharpSettings { diff --git a/src/WebStarter/Program.cs b/src/WebStarter/Program.cs index 80e606ed..1cc3ca61 100644 --- a/src/WebStarter/Program.cs +++ b/src/WebStarter/Program.cs @@ -11,8 +11,8 @@ builder.Services.AddSwaggerGen(); builder.Services.AddHttpContextAccessor(); // Add BotSharp -builder.Services.AddBotSharp(); -builder.Services.AddLlamaSharp(builder.Configuration); +builder.Services.AddBotSharp(builder.Configuration); +builder.Services.AddBotSharpCommunityPlatform(builder.Configuration); // builder.Services.AddAzureOpenAi(builder.Configuration); builder.Services.AddCors(options => diff --git a/src/WebStarter/WebStarter.csproj b/src/WebStarter/WebStarter.csproj index 762e49fb..e137d64e 100644 --- a/src/WebStarter/WebStarter.csproj +++ b/src/WebStarter/WebStarter.csproj @@ -28,7 +28,7 @@ - +