Refactor plugins mechanism.

This commit is contained in:
Haiping Chen 2023-06-06 19:59:32 -05:00
parent 545e8a4030
commit 229fcfe6ea
45 changed files with 187 additions and 175 deletions

View file

@ -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}

View file

@ -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.

View file

@ -0,0 +1,5 @@
namespace BotSharp.Abstraction.ApiAdapters;
public interface IApiAdapter
{
}

View file

@ -4,7 +4,7 @@ namespace BotSharp.Abstraction.Conversations;
public interface ISessionService
{
SessionModel NewSession(string userId);
Task<SessionModel> NewSession(string userId);
List<string> GetAllSessions(string userId);
void DeleteSession(string sessionId);
}

View file

@ -0,0 +1,7 @@
namespace BotSharp.Abstraction.Conversations.Models;
public class MessageModel
{
public string From { get; set; }
public string Content { get; set; }
}

View file

@ -1,9 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace BotSharp.Abstraction;
public interface IBotUiAdapter
{
}

View file

@ -0,0 +1,5 @@
namespace BotSharp.Abstraction.Plugins;
public interface IBotSharpPlugin
{
}

View file

@ -1,8 +1,8 @@
using BotSharp.Abstraction.Models;
namespace BotSharp.Abstraction;
namespace BotSharp.Abstraction.TextCompletions;
public interface IChatCompletionHandler
public interface ITextCompletionProvider
{
string GetInstruction();
List<RoleDialogModel> GetChatSamples();

View file

@ -56,7 +56,9 @@
<ItemGroup>
<PackageReference Include="CherubNLP" Version="0.5.0" />
<PackageReference Include="Colorful.Console" Version="1.2.15" />
<PackageReference Include="EntityFrameworkCore.BootKit" Version="6.2.0" />
<PackageReference Include="EntityFrameworkCore.BootKit" Version="6.2.1" />
<PackageReference Include="LLamaSharp" Version="0.3.0" />
<PackageReference Include="LLamaSharp.Backend.Cuda11" Version="0.3.0" />
</ItemGroup>
<ItemGroup>

View file

@ -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<MongoDbContext>(myDatabaseSettings, x);
});
services.AddSingleton(x =>
{
var settings = new LlamaSharpSettings();
config.Bind("LlamaSharp", settings);
return settings;
});
services.AddSingleton<ITextCompletionProvider, LlamaSharpCompletionProvider>();
}
}

View file

@ -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<SessionModel> NewSession(string userId)
{
var mongo = _services.CreateScope().ServiceProvider.GetRequiredService<MongoDbContext>();
var record = new Conversation
{
CreatedAt = DateTime.UtcNow,
Messages = new List<MessageModel>(),
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
};
}
}

View file

@ -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<RoleDialogModel> conversations,
Func<string, Task> onChunkReceived)
{
var handlers = _services.GetServices<IChatCompletionHandler>().ToList();
var handlers = _services.GetServices<ITextCompletionProvider>().ToList();
for (int i = 0; i < handlers.Count(); i++)
{
var handler = handlers[i];

View file

@ -1,23 +1,17 @@
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,

View file

@ -1,4 +1,4 @@
namespace BotSharp.Platform.Native.Settings;
namespace BotSharp.Core.Plugins.TextCompletions.LLamaSharp;
public class LlamaSharpSettings
{

View file

@ -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<MessageModel> Messages { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
}

View file

@ -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<IMongoDbCollection, DbContext4MongoDb>(new DatabaseBind
{
ServiceProvider = serviceProvider,
MasterConnection = new MongoDbConnection("mongodb://user:password@localhost:27017"),
CreateDbIfNotExist = true
MasterConnection = new MongoDbConnection(settings.MongoDb.Master),
IsRelational = false
});
}
return dc;

View file

@ -1,5 +1,8 @@
using MongoDB.Bson;
namespace BotSharp.Core.Repository;
public interface IMongoDbCollection
{
ObjectId Id { get; set; }
}

View file

@ -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<Conversation> Conversations
=> Collection<Conversation>("conversations");
}

View file

@ -1,7 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
</Project>

View file

@ -2,15 +2,8 @@
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>10</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="LLamaSharp" Version="0.3.0" />
<PackageReference Include="LLamaSharp.Backend.Cuda11" Version="0.3.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Infrastructure\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
</ItemGroup>

View file

@ -23,4 +23,8 @@
<PackageReference Include="Senparc.Weixin.MP.MVC" Version="7.12.5.7" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Infrastructure\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
</ItemGroup>
</Project>

View file

@ -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<IChatCompletionHandler, ChatCompletionHandler>();
return services;
}
}

View file

@ -1,9 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>10</LangVersion>
</PropertyGroup>
</Project>

View file

@ -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<IChatCompletionHandler, ChatCompletionHandler>();
services.AddScoped<ITextCompletionProvider, ChatCompletionHandler>();
return services;
}
}

View file

@ -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;

View file

@ -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<ChatbotUiController> _logger;
private readonly IPlatformMidware _platform;

View file

@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace ChatbotUI.ViewModels;
namespace BotSharp.Plugin.ChatbotUI.ViewModels;
public class OpenAiChatOutput
{

View file

@ -1,7 +1,7 @@
using Azure.AI.OpenAI;
using System.Text.Json.Serialization;
namespace ChatbotUI.ViewModels;
namespace BotSharp.Plugin.ChatbotUI.ViewModels;
public class OpenAiChoice
{

View file

@ -1,4 +1,4 @@
namespace ChatbotUI.ViewModels;
namespace BotSharp.Plugin.ChatbotUI.ViewModels;
public class OpenAiMessageBody
{

View file

@ -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
{

View file

@ -1,7 +1,7 @@
using BotSharp.Abstraction.Models;
using System.Collections.Generic;
namespace ChatbotUI.ViewModels;
namespace BotSharp.Plugin.ChatbotUI.ViewModels;
public class OpenAiModels
{

View file

@ -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
```

View file

@ -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<ConversationViewModel> 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
};
}

View file

@ -1,4 +1,4 @@
namespace HuggingChatUI.ViewModels;
namespace BotSharp.Plugin.HuggingChatUI.ViewModels;
public class ConversationCreationModel
{

View file

@ -1,4 +1,4 @@
namespace HuggingChatUI.ViewModels;
namespace BotSharp.Plugin.HuggingChatUI.ViewModels;
public class ConversationViewModel
{

View file

@ -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 =>

View file

@ -0,0 +1,2 @@
user: Hi
assistant: Hello, I'm a AI assistant to help you schedule meeting.

View file

@ -27,10 +27,11 @@
<ItemGroup>
<ProjectReference Include="..\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
<ProjectReference Include="..\Plugins\Platforms\BotSharp.Platform.AureAi\BotSharp.Platform.AzureAi.csproj" />
<ProjectReference Include="..\Plugins\Platforms\BotSharp.Platform.Native\BotSharp.Platform.Native.csproj" />
<ProjectReference Include="..\Plugins\UiAdapters\BotSharp.UiAdapter.ChatbotUI\BotSharp.UIAdapter.ChatbotUI.csproj" />
<ProjectReference Include="..\Plugins\UiAdapters\BotSharp.UiAdapter.HuggingChatUI\BotSharp.UIAdapter.HuggingChatUI.csproj" />
<ProjectReference Include="..\Plugins\Messages\BotSharp.Channel.FacebookMessenger\BotSharp.Plugin.FacebookMessenger.csproj" />
<ProjectReference Include="..\Plugins\Messages\BotSharp.Channel.Weixin\BotSharp.Plugin.Weixin.csproj" />
<ProjectReference Include="..\Plugins\Platforms\BotSharp.Plugin.AureOpenAI\BotSharp.Plugin.AzureOpenAI.csproj" />
<ProjectReference Include="..\Plugins\UIs\BotSharp.Plugin.ChatbotUI\BotSharp.Plugin.ChatbotUI.csproj" />
<ProjectReference Include="..\Plugins\UIs\BotSharp.Plugin.HuggingChatUI\BotSharp.Plugin.HuggingChatUI.csproj" />
</ItemGroup>
</Project>

View file

@ -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" ]
}
}