diff --git a/BotSharp.sln b/BotSharp.sln index 40548e48..964017ae 100644 --- a/BotSharp.sln +++ b/BotSharp.sln @@ -27,7 +27,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.Weixin", "s EndProject 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.Plugin.HuggingChatUI", "src\Plugins\UIs\BotSharp.Plugin.HuggingChatUI\BotSharp.Plugin.HuggingChatUI.csproj", "{17640C6E-2797-4D51-AF97-F2D1B5C47623}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.HuggingFace", "src\Plugins\Platforms\BotSharp.Plugin.HuggingFace\BotSharp.Plugin.HuggingFace.csproj", "{48889657-1BFF-4FDD-B702-CFA5F866BC20}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -93,14 +93,14 @@ Global {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 + {48889657-1BFF-4FDD-B702-CFA5F866BC20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {48889657-1BFF-4FDD-B702-CFA5F866BC20}.Debug|Any CPU.Build.0 = Debug|Any CPU + {48889657-1BFF-4FDD-B702-CFA5F866BC20}.Debug|x64.ActiveCfg = Debug|Any CPU + {48889657-1BFF-4FDD-B702-CFA5F866BC20}.Debug|x64.Build.0 = Debug|Any CPU + {48889657-1BFF-4FDD-B702-CFA5F866BC20}.Release|Any CPU.ActiveCfg = Release|Any CPU + {48889657-1BFF-4FDD-B702-CFA5F866BC20}.Release|Any CPU.Build.0 = Release|Any CPU + {48889657-1BFF-4FDD-B702-CFA5F866BC20}.Release|x64.ActiveCfg = Release|Any CPU + {48889657-1BFF-4FDD-B702-CFA5F866BC20}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -115,7 +115,7 @@ Global {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} + {48889657-1BFF-4FDD-B702-CFA5F866BC20} = {D5293208-2BEF-42FC-A64C-5954F61720BA} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19} diff --git a/src/Infrastructure/BotSharp.Abstraction/TextGeneratives/TextToken.cs b/src/Infrastructure/BotSharp.Abstraction/TextGeneratives/TextToken.cs new file mode 100644 index 00000000..426ce8cc --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/TextGeneratives/TextToken.cs @@ -0,0 +1,9 @@ +namespace BotSharp.Abstraction.TextGeneratives; + +public class TextToken +{ + public int Id { get; set; } + public string Text { get; set; } = string.Empty; + public float Logprob { get;set; } + public bool Special { get; set; } +} diff --git a/src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/BotSharp.Plugin.HuggingChatUI.csproj b/src/Plugins/Platforms/BotSharp.Plugin.HuggingFace/BotSharp.Plugin.HuggingFace.csproj similarity index 86% rename from src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/BotSharp.Plugin.HuggingChatUI.csproj rename to src/Plugins/Platforms/BotSharp.Plugin.HuggingFace/BotSharp.Plugin.HuggingFace.csproj index 6e134e84..877bb599 100644 --- a/src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/BotSharp.Plugin.HuggingChatUI.csproj +++ b/src/Plugins/Platforms/BotSharp.Plugin.HuggingFace/BotSharp.Plugin.HuggingFace.csproj @@ -8,6 +8,7 @@ + diff --git a/src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/HuggingChat-UI.md b/src/Plugins/Platforms/BotSharp.Plugin.HuggingFace/HuggingChat-UI.md similarity index 100% rename from src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/HuggingChat-UI.md rename to src/Plugins/Platforms/BotSharp.Plugin.HuggingFace/HuggingChat-UI.md diff --git a/src/Plugins/Platforms/BotSharp.Plugin.HuggingFace/HuggingChat/HuggingChatController.cs b/src/Plugins/Platforms/BotSharp.Plugin.HuggingFace/HuggingChat/HuggingChatController.cs new file mode 100644 index 00000000..b77e429a --- /dev/null +++ b/src/Plugins/Platforms/BotSharp.Plugin.HuggingFace/HuggingChat/HuggingChatController.cs @@ -0,0 +1,61 @@ +using BotSharp.Abstraction; +using BotSharp.Abstraction.ApiAdapters; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Net.Http.Headers; +using Newtonsoft.Json.Serialization; +using Newtonsoft.Json; +using System; +using System.Text; +using System.Threading.Tasks; +using BotSharp.Plugin.HuggingFace.HuggingChat.ViewModels; + +namespace BotSharp.Plugin.HuggingFace.HuggingChat; + +public class HuggingChatController : ControllerBase, IApiAdapter +{ + private readonly IPlatformMidware _platform; + public HuggingChatController(IPlatformMidware platform) + { + _platform = platform; + } + + [HttpPost("/conversation")] + public async Task NewSession([FromBody] ConversationCreationModel conversationCreationModel) + { + var session = await _platform.SessionService.NewSession("anonymous"); + return new ConversationViewModel + { + ConversationId = session.SessionId + }; + } + + [HttpPost("/conversation/{id}/summarize")] + public string SummarizeTitle([FromRoute] string id) + { + return "SummarizeTitle"; + } + + [HttpPost("/models/OpenAssistant/{model}")] + public async Task SendMessage([FromRoute] string model, [FromBody] ChatInput message) + { + Response.StatusCode = 200; + Response.Headers.Add(HeaderNames.ContentType, "text/event-stream"); + Response.Headers.Add(HeaderNames.CacheControl, "no-cache"); + Response.Headers.Add(HeaderNames.Connection, "keep-alive"); + var outputStream = Response.Body; + + var response = new ChatResponse + { + + }; + + var json = JsonConvert.SerializeObject(response, new JsonSerializerSettings + { + Formatting = Formatting.None, + ContractResolver = new CamelCasePropertyNamesContractResolver() + }); + + var buffer = Encoding.UTF8.GetBytes(json); + await outputStream.WriteAsync(buffer, 0, buffer.Length); + } +} diff --git a/src/Plugins/Platforms/BotSharp.Plugin.HuggingFace/HuggingChat/ViewModels/ChatInput.cs b/src/Plugins/Platforms/BotSharp.Plugin.HuggingFace/HuggingChat/ViewModels/ChatInput.cs new file mode 100644 index 00000000..ec4be48b --- /dev/null +++ b/src/Plugins/Platforms/BotSharp.Plugin.HuggingFace/HuggingChat/ViewModels/ChatInput.cs @@ -0,0 +1,6 @@ +namespace BotSharp.Plugin.HuggingFace.HuggingChat.ViewModels; + +public class ChatInput +{ + public string Inputs { get; set; } +} diff --git a/src/Plugins/Platforms/BotSharp.Plugin.HuggingFace/HuggingChat/ViewModels/ChatResponse.cs b/src/Plugins/Platforms/BotSharp.Plugin.HuggingFace/HuggingChat/ViewModels/ChatResponse.cs new file mode 100644 index 00000000..97291918 --- /dev/null +++ b/src/Plugins/Platforms/BotSharp.Plugin.HuggingFace/HuggingChat/ViewModels/ChatResponse.cs @@ -0,0 +1,12 @@ +using BotSharp.Abstraction.TextGeneratives; +using System.Text.Json.Serialization; + +namespace BotSharp.Plugin.HuggingFace.HuggingChat.ViewModels; + +public class ChatResponse +{ + public TextToken Token { get; set; } + [JsonPropertyName("generated_text")] + public string GeneratedText { get; set; } + public string Details { get; set; } +} diff --git a/src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/ViewModels/ConversationCreationModel.cs b/src/Plugins/Platforms/BotSharp.Plugin.HuggingFace/HuggingChat/ViewModels/ConversationCreationModel.cs similarity index 56% rename from src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/ViewModels/ConversationCreationModel.cs rename to src/Plugins/Platforms/BotSharp.Plugin.HuggingFace/HuggingChat/ViewModels/ConversationCreationModel.cs index 53dee353..4426c00b 100644 --- a/src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/ViewModels/ConversationCreationModel.cs +++ b/src/Plugins/Platforms/BotSharp.Plugin.HuggingFace/HuggingChat/ViewModels/ConversationCreationModel.cs @@ -1,4 +1,4 @@ -namespace BotSharp.Plugin.HuggingChatUI.ViewModels; +namespace BotSharp.Plugin.HuggingFace.HuggingChat.ViewModels; public class ConversationCreationModel { diff --git a/src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/ViewModels/ConversationViewModel.cs b/src/Plugins/Platforms/BotSharp.Plugin.HuggingFace/HuggingChat/ViewModels/ConversationViewModel.cs similarity index 58% rename from src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/ViewModels/ConversationViewModel.cs rename to src/Plugins/Platforms/BotSharp.Plugin.HuggingFace/HuggingChat/ViewModels/ConversationViewModel.cs index 79ad81f5..8414c5f7 100644 --- a/src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/ViewModels/ConversationViewModel.cs +++ b/src/Plugins/Platforms/BotSharp.Plugin.HuggingFace/HuggingChat/ViewModels/ConversationViewModel.cs @@ -1,4 +1,4 @@ -namespace BotSharp.Plugin.HuggingChatUI.ViewModels; +namespace BotSharp.Plugin.HuggingFace.HuggingChat.ViewModels; public class ConversationViewModel { diff --git a/src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/HuggingChatUiController.cs b/src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/HuggingChatUiController.cs deleted file mode 100644 index d9a1c38c..00000000 --- a/src/Plugins/UIs/BotSharp.Plugin.HuggingChatUI/HuggingChatUiController.cs +++ /dev/null @@ -1,33 +0,0 @@ -using BotSharp.Abstraction; -using BotSharp.Abstraction.ApiAdapters; -using BotSharp.Plugin.HuggingChatUI.ViewModels; -using Microsoft.AspNetCore.Mvc; -using System; -using System.Threading.Tasks; - -namespace BotSharp.Plugin.HuggingChatUI.Controllers; - -public class HuggingChatUiController : ControllerBase, IApiAdapter -{ - private readonly IPlatformMidware _platform; - public HuggingChatUiController(IPlatformMidware platform) - { - _platform = platform; - } - - [HttpPost("conversation")] - public async Task NewSession([FromBody] ConversationCreationModel conversationCreationModel) - { - var session = await _platform.SessionService.NewSession("anonymous"); - return new ConversationViewModel - { - ConversationId = session.SessionId - }; - } - - [HttpPost("conversation/{id}/summarize")] - public string SummarizeTitle([FromRoute] string id) - { - return "SummarizeTitle"; - } -} diff --git a/src/WebStarter/WebStarter.csproj b/src/WebStarter/WebStarter.csproj index 89d1f353..cdbe052c 100644 --- a/src/WebStarter/WebStarter.csproj +++ b/src/WebStarter/WebStarter.csproj @@ -30,8 +30,8 @@ + -