HuggingFace inference (WIP).
This commit is contained in:
parent
0b31f7cfee
commit
1a96803f14
20
BotSharp.sln
20
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}
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.0" />
|
||||
<PackageReference Include="System.Text.Json" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -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<ConversationViewModel> 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
namespace BotSharp.Plugin.HuggingFace.HuggingChat.ViewModels;
|
||||
|
||||
public class ChatInput
|
||||
{
|
||||
public string Inputs { get; set; }
|
||||
}
|
||||
|
|
@ -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; }
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
namespace BotSharp.Plugin.HuggingChatUI.ViewModels;
|
||||
namespace BotSharp.Plugin.HuggingFace.HuggingChat.ViewModels;
|
||||
|
||||
public class ConversationCreationModel
|
||||
{
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
namespace BotSharp.Plugin.HuggingChatUI.ViewModels;
|
||||
namespace BotSharp.Plugin.HuggingFace.HuggingChat.ViewModels;
|
||||
|
||||
public class ConversationViewModel
|
||||
{
|
||||
|
|
@ -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<ConversationViewModel> 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";
|
||||
}
|
||||
}
|
||||
|
|
@ -30,8 +30,8 @@
|
|||
<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\Platforms\BotSharp.Plugin.HuggingFace\BotSharp.Plugin.HuggingFace.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>
|
||||
|
|
|
|||
Loading…
Reference in a new issue