Remove IPlatformMidware.

This commit is contained in:
Haiping Chen 2023-06-09 21:56:04 -05:00
parent e7fb76d7f5
commit 071a64ea21
13 changed files with 75 additions and 57 deletions

View file

@ -29,6 +29,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.FacebookMes
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.WeChat", "src\Plugins\BotSharp.Plugin.WeChat\BotSharp.Plugin.WeChat.csproj", "{2323A7A3-E938-488D-A57E-638638054BC4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{32FAFFFE-A4CB-4FEE-BF7C-84518BBC6DCC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTest", "tests\UnitTest\UnitTest.csproj", "{0B6E1D7F-ABDE-47F6-8B2D-4483C2CFF2D6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -101,6 +105,14 @@ Global
{2323A7A3-E938-488D-A57E-638638054BC4}.Release|Any CPU.Build.0 = Release|Any CPU
{2323A7A3-E938-488D-A57E-638638054BC4}.Release|x64.ActiveCfg = Release|Any CPU
{2323A7A3-E938-488D-A57E-638638054BC4}.Release|x64.Build.0 = Release|Any CPU
{0B6E1D7F-ABDE-47F6-8B2D-4483C2CFF2D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0B6E1D7F-ABDE-47F6-8B2D-4483C2CFF2D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0B6E1D7F-ABDE-47F6-8B2D-4483C2CFF2D6}.Debug|x64.ActiveCfg = Debug|Any CPU
{0B6E1D7F-ABDE-47F6-8B2D-4483C2CFF2D6}.Debug|x64.Build.0 = Debug|Any CPU
{0B6E1D7F-ABDE-47F6-8B2D-4483C2CFF2D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0B6E1D7F-ABDE-47F6-8B2D-4483C2CFF2D6}.Release|Any CPU.Build.0 = Release|Any CPU
{0B6E1D7F-ABDE-47F6-8B2D-4483C2CFF2D6}.Release|x64.ActiveCfg = Release|Any CPU
{0B6E1D7F-ABDE-47F6-8B2D-4483C2CFF2D6}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -116,6 +128,7 @@ Global
{68C7C9E9-496B-4004-A1F8-75FFB8C06C76} = {42226933-0A0D-48E8-85EC-AFE773A1F841}
{0149F6C2-4CF8-4904-A545-54F3278BEA74} = {64264688-0F5C-4AB0-8F2B-B59B717CCE00}
{2323A7A3-E938-488D-A57E-638638054BC4} = {64264688-0F5C-4AB0-8F2B-B59B717CCE00}
{0B6E1D7F-ABDE-47F6-8B2D-4483C2CFF2D6} = {32FAFFFE-A4CB-4FEE-BF7C-84518BBC6DCC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19}

View file

@ -1,11 +0,0 @@
using BotSharp.Abstraction.Conversations;
using BotSharp.Abstraction.Models;
namespace BotSharp.Abstraction;
public interface IPlatformMidware
{
ISessionService SessionService { get; }
Task GetChatCompletionsAsync(List<RoleDialogModel> conversations,
Func<string, Task> onChunkReceived);
}

View file

@ -62,15 +62,19 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="CherubNLP" Version="0.5.0" />
<PackageReference Include="Colorful.Console" Version="1.2.15" />
<PackageReference Include="EntityFrameworkCore.BootKit" Version="6.2.1" />
<PackageReference Include="LLamaSharp" Version="0.3.0" />
<PackageReference Include="LLamaSharp.Backend.Cuda11" Version="0.3.0" />
<PackageReference Include="TensorFlow.Keras" Version="0.10.5" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Infrastructures\" />
</ItemGroup>
</Project>

View file

@ -3,7 +3,6 @@ using BotSharp.Abstraction.TextGeneratives;
using BotSharp.Core.Conversations;
using BotSharp.Core.Plugins.TextGeneratives.LLamaSharp;
using BotSharp.Core.Repository;
using BotSharp.Core.Services;
using EntityFrameworkCore.BootKit;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
@ -15,11 +14,13 @@ public static class BotSharpServiceCollectionExtensions
{
public static IServiceCollection AddBotSharp(this IServiceCollection services, IConfiguration config)
{
services.AddScoped<IPlatformMidware, PlatformMidware>();
services.AddSingleton<ISessionService, SessionService>();
services.AddSingleton<IConversationService, ConversationService>();
RegisterRepository(services, config);
RegisterPlugins(services, config);
return services;
}
@ -66,4 +67,9 @@ public static class BotSharpServiceCollectionExtensions
});
services.AddSingleton<IChatCompletionProvider, ChatCompletionProvider>();
}
public static void RegisterPlugins(IServiceCollection services, IConfiguration config)
{
}
}

View file

@ -1,32 +0,0 @@
using BotSharp.Abstraction.Conversations;
using BotSharp.Abstraction.Models;
using BotSharp.Abstraction.TextGeneratives;
using Microsoft.Extensions.DependencyInjection;
namespace BotSharp.Core.Services;
public class PlatformMidware : IPlatformMidware
{
private readonly IServiceProvider _services;
private readonly ISessionService _sessionService;
public PlatformMidware(IServiceProvider services)
{
_services = services;
_sessionService = services.GetRequiredService<ISessionService>();
}
public ISessionService SessionService => _sessionService;
public async Task GetChatCompletionsAsync(List<RoleDialogModel> conversations,
Func<string, Task> onChunkReceived)
{
var handlers = _services.GetServices<IChatCompletionProvider>().ToList();
for (int i = 0; i < handlers.Count(); i++)
{
var handler = handlers[i];
await handler.GetChatCompletionsAsync(conversations,
onChunkReceived);
}
}
}

View file

@ -0,0 +1,6 @@
namespace BotSharp.Core.Plugins.TextGeneratives.LLamaSharp;
public class LLamaSharpPlugin : IBotSharpPlugin
{
}

View file

@ -3,4 +3,5 @@ global using System.Collections.Generic;
global using System.Text;
global using System.Threading.Tasks;
global using BotSharp.Abstraction;
global using System.Linq;
global using System.Linq;
global using BotSharp.Abstraction.Plugins;

View file

@ -1,4 +1,3 @@
using BotSharp.Abstraction;
using BotSharp.Abstraction.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
@ -14,6 +13,7 @@ using System;
using Azure.AI.OpenAI;
using BotSharp.Abstraction.ApiAdapters;
using BotSharp.Plugin.ChatbotUI.ViewModels;
using BotSharp.Abstraction.TextGeneratives;
namespace BotSharp.Plugin.ChatbotUI.Controllers;
@ -21,13 +21,13 @@ namespace BotSharp.Plugin.ChatbotUI.Controllers;
public class ChatbotUiController : ControllerBase, IApiAdapter
{
private readonly ILogger<ChatbotUiController> _logger;
private readonly IPlatformMidware _platform;
private readonly IChatCompletionProvider _chatCompletionProvider;
public ChatbotUiController(ILogger<ChatbotUiController> logger,
IPlatformMidware platform)
IChatCompletionProvider chatCompletionProvider)
{
_logger = logger;
_platform = platform;
_chatCompletionProvider = chatCompletionProvider;
}
[HttpGet("/v1/models")]
@ -64,7 +64,7 @@ public class ChatbotUiController : ControllerBase, IApiAdapter
Content = x.Content
}).ToList();
await _platform.GetChatCompletionsAsync(conversations,
await _chatCompletionProvider.GetChatCompletionsAsync(conversations,
async content =>
{
await OnChunkReceived(outputStream, content);

View file

@ -16,13 +16,13 @@ namespace BotSharp.Plugin.HuggingFace.HuggingChat;
public class HuggingChatController : ControllerBase, IApiAdapter
{
private readonly IPlatformMidware _platform;
public HuggingChatController(IPlatformMidware platform)
private readonly IChatCompletionProvider _chatCompletionProvider;
public HuggingChatController(IChatCompletionProvider chatCompletionProvider)
{
_platform = platform;
_chatCompletionProvider = chatCompletionProvider;
}
[HttpPost("/conversation")]
/*[HttpPost("/conversation")]
public async Task<ConversationViewModel> NewSession([FromBody] ConversationCreationModel conversationCreationModel)
{
var session = await _platform.SessionService.NewSession("anonymous");
@ -36,7 +36,7 @@ public class HuggingChatController : ControllerBase, IApiAdapter
public string SummarizeTitle([FromRoute] string id)
{
return "SummarizeTitle";
}
}*/
[HttpPost("/models/OpenAssistant/{model}")]
public async Task SendMessage([FromRoute] string model, [FromBody] ChatInput message)

View file

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,11 @@
namespace UnitTest
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
}
}
}

1
tests/UnitTest/Usings.cs Normal file
View file

@ -0,0 +1 @@
global using Microsoft.VisualStudio.TestTools.UnitTesting;