This commit is contained in:
Haiping Chen 2023-11-22 10:27:55 -06:00
parent 2bdabdc04e
commit be88bfa121
12 changed files with 264 additions and 4 deletions

View file

@ -69,7 +69,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.SemanticKer
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.Twilio", "src\Plugins\BotSharp.Plugin.Twilio\BotSharp.Plugin.Twilio.csproj", "{E627F1E3-BE03-443A-83A2-86A855A278EB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Plugin.WebDriver", "src\Plugins\BotSharp.Plugin.WebDriver\BotSharp.Plugin.WebDriver.csproj", "{F06B22CB-B143-4680-8FFF-35B9E50E6C47}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.WebDriver", "src\Plugins\BotSharp.Plugin.WebDriver\BotSharp.Plugin.WebDriver.csproj", "{F06B22CB-B143-4680-8FFF-35B9E50E6C47}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.ChatHub", "src\Plugins\BotSharp.Plugin.ChatHub\BotSharp.Plugin.ChatHub.csproj", "{EDCD9C20-2D9D-4098-A16E-03F97B306CB8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Plugin.TelegramBots", "src\Plugins\BotSharp.Plugin.TelegramBots\BotSharp.Plugin.TelegramBots.csproj", "{DCA18996-4D3A-4E98-BCD0-1FB77C59253E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -263,6 +267,22 @@ Global
{F06B22CB-B143-4680-8FFF-35B9E50E6C47}.Release|Any CPU.Build.0 = Release|Any CPU
{F06B22CB-B143-4680-8FFF-35B9E50E6C47}.Release|x64.ActiveCfg = Release|Any CPU
{F06B22CB-B143-4680-8FFF-35B9E50E6C47}.Release|x64.Build.0 = Release|Any CPU
{EDCD9C20-2D9D-4098-A16E-03F97B306CB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EDCD9C20-2D9D-4098-A16E-03F97B306CB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EDCD9C20-2D9D-4098-A16E-03F97B306CB8}.Debug|x64.ActiveCfg = Debug|Any CPU
{EDCD9C20-2D9D-4098-A16E-03F97B306CB8}.Debug|x64.Build.0 = Debug|Any CPU
{EDCD9C20-2D9D-4098-A16E-03F97B306CB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EDCD9C20-2D9D-4098-A16E-03F97B306CB8}.Release|Any CPU.Build.0 = Release|Any CPU
{EDCD9C20-2D9D-4098-A16E-03F97B306CB8}.Release|x64.ActiveCfg = Release|Any CPU
{EDCD9C20-2D9D-4098-A16E-03F97B306CB8}.Release|x64.Build.0 = Release|Any CPU
{DCA18996-4D3A-4E98-BCD0-1FB77C59253E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DCA18996-4D3A-4E98-BCD0-1FB77C59253E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DCA18996-4D3A-4E98-BCD0-1FB77C59253E}.Debug|x64.ActiveCfg = Debug|Any CPU
{DCA18996-4D3A-4E98-BCD0-1FB77C59253E}.Debug|x64.Build.0 = Debug|Any CPU
{DCA18996-4D3A-4E98-BCD0-1FB77C59253E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DCA18996-4D3A-4E98-BCD0-1FB77C59253E}.Release|Any CPU.Build.0 = Release|Any CPU
{DCA18996-4D3A-4E98-BCD0-1FB77C59253E}.Release|x64.ActiveCfg = Release|Any CPU
{DCA18996-4D3A-4E98-BCD0-1FB77C59253E}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -298,6 +318,8 @@ Global
{BC57D428-A1A4-4D38-A2D0-AC6CA943F247} = {32FAFFFE-A4CB-4FEE-BF7C-84518BBC6DCC}
{E627F1E3-BE03-443A-83A2-86A855A278EB} = {64264688-0F5C-4AB0-8F2B-B59B717CCE00}
{F06B22CB-B143-4680-8FFF-35B9E50E6C47} = {51AFE054-AE99-497D-A593-69BAEFB5106F}
{EDCD9C20-2D9D-4098-A16E-03F97B306CB8} = {64264688-0F5C-4AB0-8F2B-B59B717CCE00}
{DCA18996-4D3A-4E98-BCD0-1FB77C59253E} = {64264688-0F5C-4AB0-8F2B-B59B717CCE00}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19}

View file

@ -61,7 +61,7 @@ The core module is mainly composed of abstraction and framework function impleme
BotSharp uses component design, the kernel is kept to a minimum, and business functions are implemented by external components. The modular design also allows contributors to better participate. Below are the bulit-in plugins:
#### Data Storages
- BotSharp.Plugin.MongoStorage
- BotSharp.Plugin.FileRepository
- BotSharp.Plugin.MongoStorage
#### LLMs
@ -74,11 +74,13 @@ BotSharp uses component design, the kernel is kept to a minimum, and business fu
#### Messaging / Channel
- BotSharp.OpenAPI
- BotSharp.Plugin.ChatHub
- BotSharp.Plugin.MetaMessenger
- BotSharp.Plugin.Twilio
- BotSharp.Plugin.TelegramBots
- BotSharp.Plugin.WeChat
#### RAGS
#### RAGs
- BotSharp.Plugin.KnowledgeBase
- BotSharp.Plugin.Qdrant

View file

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>$(LangVersion)</LangVersion>
<VersionPrefix>$(BotSharpVersion)</VersionPrefix>
<GeneratePackageOnBuild>$(GeneratePackageOnBuild)</GeneratePackageOnBuild>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Infrastructure\BotSharp.OpenAPI\BotSharp.OpenAPI.csproj" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,17 @@
using BotSharp.Plugin.ChatHub.Hooks;
using Microsoft.Extensions.Configuration;
namespace BotSharp.Plugin.ChatHub;
/// <summary>
/// The dialogue channel connects users, AI assistants and customer service representatives.
/// </summary>
public class ChatHubPlugin : IBotSharpPlugin
{
public string Name => "Chat Hub";
public void RegisterDI(IServiceCollection services, IConfiguration config)
{
// Register hooks
services.AddScoped<IConversationHook, ChatHubConversationHook>();
}
}

View file

@ -0,0 +1,25 @@
using BotSharp.Abstraction.ApiAdapters;
using Microsoft.AspNetCore.SignalR;
namespace BotSharp.Plugin.ChatHub.Controllers;
[Authorize]
[ApiController]
public class ChatHubController : ControllerBase, IApiAdapter
{
private readonly IServiceProvider _services;
private readonly ILogger _logger;
private readonly IHubContext<SignalRHub> _chatHub;
private readonly IUserIdentity _user;
public ChatHubController(IServiceProvider services,
ILogger<ChatHubController> logger,
IHubContext<SignalRHub> chatHub,
IUserIdentity user)
{
_services = services;
_logger = logger;
_chatHub = chatHub;
_user = user;
}
}

View file

@ -0,0 +1,67 @@
using Microsoft.AspNetCore.SignalR;
namespace BotSharp.Plugin.ChatHub.Hooks;
public class ChatHubConversationHook : ConversationHookBase
{
private readonly IServiceProvider _services;
private readonly IHubContext<SignalRHub> _chatHub;
public ChatHubConversationHook(IServiceProvider services,
IHubContext<SignalRHub> chatHub)
{
_services = services;
_chatHub = chatHub;
}
public override async Task OnConversationInitialized(Conversation conversation)
{
var userService = _services.GetRequiredService<IUserService>();
var conv = ConversationViewModel.FromSession(conversation);
var user = await userService.GetUser(conv.User.Id);
conv.User = UserViewModel.FromUser(user);
await _chatHub.Clients.All.SendAsync("OnConversationInitFromClient", conv);
await base.OnConversationInitialized(conversation);
}
public override async Task OnMessageReceived(RoleDialogModel message)
{
var conv = _services.GetRequiredService<IConversationService>();
var userService = _services.GetRequiredService<IUserService>();
var sender = await userService.GetMyProfile();
// Update console conversation UI for CSR
await _chatHub.Clients.All.SendAsync("OnMessageReceivedFromClient", new ChatResponseModel()
{
ConversationId = conv.ConversationId,
MessageId = message.MessageId,
Text = message.Content,
Sender = UserViewModel.FromUser(sender)
});
await base.OnMessageReceived(message);
}
public override async Task OnResponseGenerated(RoleDialogModel message)
{
var conv = _services.GetRequiredService<IConversationService>();
await _chatHub.Clients.All.SendAsync("OnMessageReceivedFromAssistant", new ChatResponseModel()
{
ConversationId = conv.ConversationId,
MessageId = message.MessageId,
Text = message.Content,
Sender = new UserViewModel()
{
FirstName = "AI",
LastName = "Assistant",
Role = AgentRole.Assistant
}
});
await base.OnResponseGenerated(message);
}
}

View file

@ -0,0 +1,47 @@
using Microsoft.AspNetCore.SignalR;
namespace BotSharp.Plugin.ChatHub;
public class SignalRHub : Hub
{
private readonly IServiceProvider _services;
private readonly ILogger _logger;
private readonly IUserIdentity _user;
public SignalRHub(IServiceProvider services,
ILogger<SignalRHub> logger,
IUserIdentity user)
{
_services = services;
_logger = logger;
_user = user;
}
public async Task OnMessageReceivedFromClient(string message)
{
// await Clients.User(_user.Id).SendAsync("ReceiveMessage", message);
}
/// <summary>
/// Received message from client
/// </summary>
/// <param name="user"></param>
/// <param name="message"></param>
/// <returns></returns>
public async Task SendMessage(string user, string message)
{
// await Clients.User(_user.Id).SendAsync("ReceiveMessage", message);
}
public async Task SendMessageToCaller(string user, string message)
=> await Clients.Caller.SendAsync("ReceiveMessage", user, message);
public async Task SendMessageToGroup(string user, string message)
=> await Clients.Group("SignalR Users").SendAsync("ReceiveMessage", user, message);
public override Task OnConnectedAsync()
{
Console.WriteLine($"SignalR Hub: {Context.UserIdentifier} connected in {Context.ConnectionId} [{DateTime.Now}]");
return base.OnConnectedAsync();
}
}

View file

@ -0,0 +1,22 @@
global using System;
global using System.Collections.Generic;
global using System.Text;
global using System.Threading.Tasks;
global using System.Linq;
global using System.Text.Json;
global using Microsoft.AspNetCore.Authorization;
global using Microsoft.AspNetCore.Mvc;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.Logging;
global using BotSharp.Abstraction.Plugins;
global using BotSharp.Abstraction.Agents;
global using BotSharp.Abstraction.Conversations;
global using BotSharp.Abstraction.Knowledges;
global using BotSharp.Abstraction.Users;
global using BotSharp.Abstraction.Utilities;
global using BotSharp.Abstraction.Agents.Settings;
global using BotSharp.Abstraction.Conversations.Settings;
global using BotSharp.Abstraction.Agents.Enums;
global using BotSharp.Abstraction.Conversations.Models;
global using BotSharp.OpenAPI.ViewModels.Conversations;
global using BotSharp.OpenAPI.ViewModels.Users;

View file

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>$(LangVersion)</LangVersion>
<VersionPrefix>$(BotSharpVersion)</VersionPrefix>
<GeneratePackageOnBuild>$(GeneratePackageOnBuild)</GeneratePackageOnBuild>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Infrastructure\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,18 @@
using BotSharp.Abstraction.Plugins;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
namespace BotSharp.Plugin.TelegramBots
{
public class TelegramBotsPlugin : IBotSharpPlugin
{
public string Name => "Telegram Bots";
public string Description => "Bots are small applications that run entirely within the Telegram app.";
public void RegisterDI(IServiceCollection services, IConfiguration config)
{
}
}
}

View file

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
@ -65,6 +65,8 @@
<ItemGroup>
<ProjectReference Include="..\..\tests\BotSharp.Plugin.PizzaBot\BotSharp.Plugin.PizzaBot.csproj" />
<ProjectReference Include="..\Plugins\BotSharp.Plugin.ChatHub\BotSharp.Plugin.ChatHub.csproj" />
<ProjectReference Include="..\Plugins\BotSharp.Plugin.TelegramBots\BotSharp.Plugin.TelegramBots.csproj" />
</ItemGroup>
</Project>

View file

@ -146,7 +146,9 @@
"BotSharp.Plugin.KnowledgeBase",
"BotSharp.Plugin.Qdrant",
"BotSharp.Plugin.PaddleSharp",
// "BotSharp.Plugin.ChatHub",
"BotSharp.Plugin.WeChat",
// "BotSharp.Plugin.TelegramBots",
// "BotSharp.Plugin.RoutingSpeeder",
"BotSharp.Plugin.PizzaBot"
]