From 4c6c035b0797a5e5e8cf8b5d4f514a717ee06e9f Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Mon, 25 Dec 2023 21:16:41 -0600 Subject: [PATCH] Plugin IconUrl. --- Directory.Build.props | 1 + .../Agents/Models/AgentLlmConfig.cs | 6 + .../Plugins/IBotSharpPlugin.cs | 1 + .../Plugins/Models/PluginDef.cs | 2 + .../Filters/ConversationFilter.cs | 4 + .../Agents/Services/AgentService.GetAgents.cs | 10 +- .../Services/AgentService.UpdateAgent.cs | 5 +- .../Services/ConversationService.cs | 1 - .../BotSharp.Core/Plugins/PluginLoader.cs | 3 +- .../Controllers/AgentController.cs | 107 ++---------------- .../Controllers/ConversationController.cs | 18 +++ .../ViewModels/Agents/AgentUpdateModel.cs | 13 ++- .../ViewModels/Agents/AgentViewModel.cs | 1 + .../AzureOpenAiPlugin.cs | 3 +- .../BotSharp.Plugin.ChatHub/ChatHubPlugin.cs | 1 + .../GoogleAiPlugin.cs | 3 + .../BotSharp.Plugin.HuggingFace.csproj | 2 +- .../HuggingFacePlugin.cs | 3 + .../KnowledgeBasePlugin.cs | 2 + .../MemVecDb/MemVecDbPlugin.cs | 2 + .../LLamaSharpPlugin.cs | 8 +- .../Providers/ChatCompletionProvider.cs | 2 +- .../BotSharp.Plugin.MetaAI/MetaAiPlugin.cs | 3 + .../MetaMessengerPlugin.cs | 2 + .../MongoStoragePlugin.cs | 5 +- .../PaddleSharpPlugin.cs | 3 + .../BotSharp.Plugin.Qdrant/QdrantPlugin.cs | 3 + .../BotSharp.Plugin.WeChat/WeChatPlugin.cs | 76 +++++++------ src/WebStarter/appsettings.json | 1 + 29 files changed, 136 insertions(+), 155 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 85cb53b2..22d1de35 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,6 @@ + net6.0 10.0 ..\..\..\packages 0.20.0 diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentLlmConfig.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentLlmConfig.cs index 266f14f2..e902efc5 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentLlmConfig.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentLlmConfig.cs @@ -2,6 +2,12 @@ namespace BotSharp.Abstraction.Agents.Models; public class AgentLlmConfig { + /// + /// Is inherited from default Agent Settings + /// + [JsonPropertyName("is_inherit")] + public bool IsInherit { get; set; } + /// /// Completion Provider /// diff --git a/src/Infrastructure/BotSharp.Abstraction/Plugins/IBotSharpPlugin.cs b/src/Infrastructure/BotSharp.Abstraction/Plugins/IBotSharpPlugin.cs index eb1b31af..a5bcfd1e 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Plugins/IBotSharpPlugin.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Plugins/IBotSharpPlugin.cs @@ -7,5 +7,6 @@ public interface IBotSharpPlugin { string Name => ""; string Description => ""; + string IconUrl => "https://avatars.githubusercontent.com/u/44989469?s=200&v=4"; void RegisterDI(IServiceCollection services, IConfiguration config); } diff --git a/src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginDef.cs b/src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginDef.cs index c297286b..e0040d46 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginDef.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Plugins/Models/PluginDef.cs @@ -6,4 +6,6 @@ public class PluginDef public string Name { get; set; } public string Description { get; set; } public string Assembly { get; set; } + [JsonPropertyName("icon_url")] + public string IconUrl { get; set; } } diff --git a/src/Infrastructure/BotSharp.Abstraction/Repositories/Filters/ConversationFilter.cs b/src/Infrastructure/BotSharp.Abstraction/Repositories/Filters/ConversationFilter.cs index de0ca68b..3d236d9e 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Repositories/Filters/ConversationFilter.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Repositories/Filters/ConversationFilter.cs @@ -3,6 +3,10 @@ namespace BotSharp.Abstraction.Repositories.Filters; public class ConversationFilter { public Pagination Pager { get; set; } = new Pagination(); + /// + /// Conversation Id + /// + public string? Id { get; set; } public string? AgentId { get; set; } public string? Status { get; set; } public string? Channel { get; set; } diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.GetAgents.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.GetAgents.cs index 379502a6..13099add 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.GetAgents.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.GetAgents.cs @@ -26,7 +26,15 @@ public partial class AgentService { _logger.LogError($"Can't find agent {id}"); return null; - }; + } + + // Load llm config + var agentSetting = _services.GetRequiredService(); + if (profile.LlmConfig == null) + { + profile.LlmConfig = agentSetting.LlmConfig; + profile.LlmConfig.IsInherit = true; + } return profile; } diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs index e0a225e2..b8c329e3 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs @@ -27,7 +27,10 @@ public partial class AgentService record.Templates = agent.Templates ?? new List(); record.Responses = agent.Responses ?? new List(); record.Samples = agent.Samples ?? new List(); - record.LlmConfig = agent.LlmConfig; + if (!agent.LlmConfig.IsInherit) + { + record.LlmConfig = agent.LlmConfig; + } _db.UpdateAgent(record, updateField); await Task.CompletedTask; diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs index a9d8067c..d6a15072 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs @@ -112,7 +112,6 @@ public partial class ConversationService : IConversationService var dialogs = _storage.GetDialogs(_conversationId); return dialogs - .Where(x => x.CreatedAt > DateTime.UtcNow.AddHours(-24)) .TakeLast(lastCount) .ToList(); } diff --git a/src/Infrastructure/BotSharp.Core/Plugins/PluginLoader.cs b/src/Infrastructure/BotSharp.Core/Plugins/PluginLoader.cs index aefe2e8b..12437024 100644 --- a/src/Infrastructure/BotSharp.Core/Plugins/PluginLoader.cs +++ b/src/Infrastructure/BotSharp.Core/Plugins/PluginLoader.cs @@ -54,7 +54,8 @@ public class PluginLoader Id = module.GetType().FullName, Name = name, Description = module.Description, - Assembly = assemblyName + Assembly = assemblyName, + IconUrl = module.IconUrl }); Console.Write($"Loaded plugin "); Console.Write(name, Color.Green); diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs index 12d17e51..ec7087d6 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs @@ -1,3 +1,6 @@ +using BotSharp.Abstraction.Agents.Models; +using BotSharp.Abstraction.Functions.Models; + namespace BotSharp.OpenAPI.Controllers; [Authorize] @@ -46,7 +49,7 @@ public class AgentController : ControllerBase, IApiAdapter await _agentService.UpdateAgentFromFile(agentId); } - [HttpPut("/agent/{agentId}/all")] + [HttpPut("/agent/{agentId}")] public async Task UpdateAgent([FromRoute] string agentId, [FromBody] AgentUpdateModel agent) { var model = agent.ToAgent(); @@ -54,107 +57,11 @@ public class AgentController : ControllerBase, IApiAdapter await _agentService.UpdateAgent(model, AgentField.All); } - [HttpPut("/agent/{agentId}/name")] - public async Task UpdateAgentName([FromRoute] string agentId, [FromBody] AgentUpdateModel agent) + [HttpPatch("/agent/{agentId}/{field}")] + public async Task PatchAgentByField([FromRoute] string agentId, AgentField field, [FromBody] AgentUpdateModel agent) { var model = agent.ToAgent(); model.Id = agentId; - await _agentService.UpdateAgent(model, AgentField.Name); - } - - [HttpPut("/agent/{agentId}/description")] - public async Task UpdateAgentDescription([FromRoute] string agentId, [FromBody] AgentUpdateModel agent) - { - var model = agent.ToAgent(); - model.Id = agentId; - await _agentService.UpdateAgent(model, AgentField.Description); - } - - [HttpPut("/agent/{agentId}/is-public")] - public async Task UpdateAgentIsPublic([FromRoute] string agentId, [FromBody] AgentUpdateModel agent) - { - var model = agent.ToAgent(); - model.Id = agentId; - await _agentService.UpdateAgent(model, AgentField.IsPublic); - } - - [HttpPut("/agent/{agentId}/disabled")] - public async Task UpdateAgentDisabled([FromRoute] string agentId, [FromBody] AgentUpdateModel agent) - { - var model = agent.ToAgent(); - model.Id = agentId; - await _agentService.UpdateAgent(model, AgentField.Disabled); - } - - [HttpPut("/agent/{agentId}/allow-routing")] - public async Task UpdateAgentAllowRouting([FromRoute] string agentId, [FromBody] AgentUpdateModel agent) - { - var model = agent.ToAgent(); - model.Id = agentId; - await _agentService.UpdateAgent(model, AgentField.AllowRouting); - } - - [HttpPut("/agent/{agentId}/profiles")] - public async Task UpdateAgentProfiles([FromRoute] string agentId, [FromBody] AgentUpdateModel agent) - { - var model = agent.ToAgent(); - model.Id = agentId; - await _agentService.UpdateAgent(model, AgentField.Profiles); - } - - [HttpPut("/agent/{agentId}/routing-rules")] - public async Task UpdateAgentRoutingRules([FromRoute] string agentId, [FromBody] AgentUpdateModel agent) - { - var model = agent.ToAgent(); - model.Id = agentId; - await _agentService.UpdateAgent(model, AgentField.RoutingRule); - } - - [HttpPut("/agent/{agentId}/instruction")] - public async Task UpdateAgentInstruction([FromRoute] string agentId, [FromBody] AgentUpdateModel agent) - { - var model = agent.ToAgent(); - model.Id = agentId; - await _agentService.UpdateAgent(model, AgentField.Instruction); - } - - [HttpPut("/agent/{agentId}/functions")] - public async Task UpdateAgentFunctions([FromRoute] string agentId, [FromBody] AgentUpdateModel agent) - { - var model = agent.ToAgent(); - model.Id = agentId; - await _agentService.UpdateAgent(model, AgentField.Function); - } - - [HttpPut("/agent/{agentId}/templates")] - public async Task UpdateAgentTemplates([FromRoute] string agentId, [FromBody] AgentUpdateModel agent) - { - var model = agent.ToAgent(); - model.Id = agentId; - await _agentService.UpdateAgent(model, AgentField.Template); - } - - [HttpPut("/agent/{agentId}/responses")] - public async Task UpdateAgentResponses([FromRoute] string agentId, [FromBody] AgentUpdateModel agent) - { - var model = agent.ToAgent(); - model.Id = agentId; - await _agentService.UpdateAgent(model, AgentField.Response); - } - - [HttpPut("/agent/{agentId}/samples")] - public async Task UpdateAgentSamples([FromRoute] string agentId, [FromBody] AgentUpdateModel agent) - { - var model = agent.ToAgent(); - model.Id = agentId; - await _agentService.UpdateAgent(model, AgentField.Sample); - } - - [HttpPut("/agent/{agentId}/llm-config")] - public async Task UpdateAgentLlmConfig([FromRoute] string agentId, [FromBody] AgentUpdateModel agent) - { - var model = agent.ToAgent(); - model.Id = agentId; - await _agentService.UpdateAgent(model, AgentField.LlmConfig); + await _agentService.UpdateAgent(model, field); } } \ No newline at end of file diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs index d5605b25..6cb41643 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs @@ -81,6 +81,24 @@ public class ConversationController : ControllerBase, IApiAdapter return dialogs; } + [HttpGet("/conversation/{conversationId}")] + public async Task GetConversation([FromRoute] string conversationId) + { + var service = _services.GetRequiredService(); + var conversations = await service.GetConversations(new ConversationFilter + { + Id = conversationId + }); + + var userService = _services.GetRequiredService(); + var result = ConversationViewModel.FromSession(conversations.Items.First()); + + var user = await userService.GetUser(result.User.Id); + result.User = UserViewModel.FromUser(user); + + return result; + } + [HttpDelete("/conversation/{conversationId}")] public async Task DeleteConversation([FromRoute] string conversationId) { diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs index b394b3bb..74589b2b 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs @@ -1,18 +1,19 @@ using BotSharp.Abstraction.Agents.Models; using BotSharp.Abstraction.Functions.Models; using BotSharp.Abstraction.Routing.Models; +using System.Text.Json.Serialization; namespace BotSharp.OpenAPI.ViewModels.Agents; public class AgentUpdateModel { - public string? Name { get; set; } = string.Empty; - public string? Description { get; set; } + public string Name { get; set; } = string.Empty; + public string Description { get; set; } = string.Empty; /// /// Instruction /// - public string? Instruction { get; set; } + public string Instruction { get; set; } = string.Empty; /// /// Templates @@ -22,7 +23,7 @@ public class AgentUpdateModel /// /// Samples /// - public string? Samples { get; set; } + public List? Samples { get; set; } /// /// Functions @@ -33,8 +34,10 @@ public class AgentUpdateModel /// Routes /// public List? Responses { get; set; } + [JsonPropertyName("is_public")] public bool IsPublic { get; set; } + [JsonPropertyName("allow_routing")] public bool AllowRouting { get; set; } @@ -44,8 +47,10 @@ public class AgentUpdateModel /// Profile by channel /// public List? Profiles { get; set; } + [JsonPropertyName("routing_rules")] public List? RoutingRules { get; set; } + [JsonPropertyName("llm_config")] public AgentLlmConfig? LlmConfig { get; set; } diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs index 13f9211a..8e7b16a7 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs @@ -15,6 +15,7 @@ public class AgentViewModel public List Functions { get; set; } public List Responses { get; set; } public List Samples { get; set; } + [JsonPropertyName("is_public")] public bool IsPublic { get; set; } [JsonPropertyName("allow_routing")] diff --git a/src/Plugins/BotSharp.Plugin.AzureOpenAI/AzureOpenAiPlugin.cs b/src/Plugins/BotSharp.Plugin.AzureOpenAI/AzureOpenAiPlugin.cs index 624ecfe5..d4f40b62 100644 --- a/src/Plugins/BotSharp.Plugin.AzureOpenAI/AzureOpenAiPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.AzureOpenAI/AzureOpenAiPlugin.cs @@ -15,7 +15,8 @@ namespace BotSharp.Platform.AzureAi; public class AzureOpenAiPlugin : IBotSharpPlugin { public string Name => "Azure OpenAI"; - public string Description => "Azure OpenAI Service"; + public string Description => "Azure OpenAI Service (ChatGPT 3.5 Turbo / 4.0)"; + public string IconUrl => "https://nanfor.com/cdn/shop/files/cursos-propios-Azure-openAI.jpg?v=1692877741"; public void RegisterDI(IServiceCollection services, IConfiguration config) { diff --git a/src/Plugins/BotSharp.Plugin.ChatHub/ChatHubPlugin.cs b/src/Plugins/BotSharp.Plugin.ChatHub/ChatHubPlugin.cs index 9f9fe0b0..dcba858b 100644 --- a/src/Plugins/BotSharp.Plugin.ChatHub/ChatHubPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.ChatHub/ChatHubPlugin.cs @@ -9,6 +9,7 @@ namespace BotSharp.Plugin.ChatHub; public class ChatHubPlugin : IBotSharpPlugin { public string Name => "Chat Hub"; + public string Description => "A communication channel connects agents and users in real-time."; public void RegisterDI(IServiceCollection services, IConfiguration config) { // Register hooks diff --git a/src/Plugins/BotSharp.Plugin.GoogleAI/GoogleAiPlugin.cs b/src/Plugins/BotSharp.Plugin.GoogleAI/GoogleAiPlugin.cs index ebf01107..fd6b06c8 100644 --- a/src/Plugins/BotSharp.Plugin.GoogleAI/GoogleAiPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.GoogleAI/GoogleAiPlugin.cs @@ -6,6 +6,9 @@ namespace BotSharp.Plugin.GoogleAI; public class GoogleAiPlugin : IBotSharpPlugin { + public string Name => "Google AI"; + public string Description => "Making AI helpful for everyone (PaLM 2, Gemini)"; + public string IconUrl => "https://vectorseek.com/wp-content/uploads/2021/12/Google-AI-Logo-Vector.png"; public void RegisterDI(IServiceCollection services, IConfiguration config) { var settings = new GoogleAiSettings(); diff --git a/src/Plugins/BotSharp.Plugin.HuggingFace/BotSharp.Plugin.HuggingFace.csproj b/src/Plugins/BotSharp.Plugin.HuggingFace/BotSharp.Plugin.HuggingFace.csproj index f8514ef1..1bf7f256 100644 --- a/src/Plugins/BotSharp.Plugin.HuggingFace/BotSharp.Plugin.HuggingFace.csproj +++ b/src/Plugins/BotSharp.Plugin.HuggingFace/BotSharp.Plugin.HuggingFace.csproj @@ -6,7 +6,7 @@ $(LangVersion) $(BotSharpVersion) $(GeneratePackageOnBuild) - True + $(GenerateDocumentationFile) diff --git a/src/Plugins/BotSharp.Plugin.HuggingFace/HuggingFacePlugin.cs b/src/Plugins/BotSharp.Plugin.HuggingFace/HuggingFacePlugin.cs index 87098557..78adad84 100644 --- a/src/Plugins/BotSharp.Plugin.HuggingFace/HuggingFacePlugin.cs +++ b/src/Plugins/BotSharp.Plugin.HuggingFace/HuggingFacePlugin.cs @@ -8,6 +8,9 @@ namespace BotSharp.Plugin.HuggingFace; public class HuggingFacePlugin : IBotSharpPlugin { + public string Name => "Hugging Face"; + public string Description => "The Home of Machine Learning - Create, discover and collaborate on ML better."; + public string IconUrl => "https://upload.wikimedia.org/wikipedia/he/e/ee/Hugging_Face_logo.png"; public void RegisterDI(IServiceCollection services, IConfiguration config) { var settings = new HuggingFaceSettings(); diff --git a/src/Plugins/BotSharp.Plugin.KnowledgeBase/KnowledgeBasePlugin.cs b/src/Plugins/BotSharp.Plugin.KnowledgeBase/KnowledgeBasePlugin.cs index bc36b09f..85f3971c 100644 --- a/src/Plugins/BotSharp.Plugin.KnowledgeBase/KnowledgeBasePlugin.cs +++ b/src/Plugins/BotSharp.Plugin.KnowledgeBase/KnowledgeBasePlugin.cs @@ -4,6 +4,8 @@ namespace BotSharp.Plugin.KnowledgeBase; public class KnowledgeBasePlugin : IBotSharpPlugin { + public string Name => "Knowledge Base"; + public string Description => "Embedding private data and feed them into LLM in the conversation."; public void RegisterDI(IServiceCollection services, IConfiguration config) { var settings = new KnowledgeBaseSettings(); diff --git a/src/Plugins/BotSharp.Plugin.KnowledgeBase/MemVecDb/MemVecDbPlugin.cs b/src/Plugins/BotSharp.Plugin.KnowledgeBase/MemVecDb/MemVecDbPlugin.cs index 114527af..e88aefa1 100644 --- a/src/Plugins/BotSharp.Plugin.KnowledgeBase/MemVecDb/MemVecDbPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.KnowledgeBase/MemVecDb/MemVecDbPlugin.cs @@ -4,6 +4,8 @@ namespace BotSharp.Plugin.KnowledgeBase.MemVecDb; public class MemVecDbPlugin : IBotSharpPlugin { + public string Name => "Memory Vector DB"; + public string Description => "Store text embedding, search similar text from memory."; public void RegisterDI(IServiceCollection services, IConfiguration config) { services.AddSingleton(); diff --git a/src/Plugins/BotSharp.Plugin.LLamaSharp/LLamaSharpPlugin.cs b/src/Plugins/BotSharp.Plugin.LLamaSharp/LLamaSharpPlugin.cs index c8a4e301..3e060526 100644 --- a/src/Plugins/BotSharp.Plugin.LLamaSharp/LLamaSharpPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.LLamaSharp/LLamaSharpPlugin.cs @@ -1,14 +1,14 @@ -using BotSharp.Abstraction.MLTasks; using BotSharp.Abstraction.Plugins; using BotSharp.Plugin.LLamaSharp.Providers; -using BotSharp.Plugin.LLamaSharp.Settings; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; namespace BotSharp.Plugins.LLamaSharp; public class LLamaSharpPlugin : IBotSharpPlugin { + public string Name => "LLamaSharp"; + public string Description => "The C#/.NET binding of llama.cpp. Run local LLaMA/GPT model easily and fast in C#!"; + public string IconUrl => "https://raw.githubusercontent.com/SciSharp/LLamaSharp/master/Assets/LLamaSharpLogo.png"; + public void RegisterDI(IServiceCollection services, IConfiguration config) { var llamaSharpSettings = new LlamaSharpSettings(); diff --git a/src/Plugins/BotSharp.Plugin.LLamaSharp/Providers/ChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.LLamaSharp/Providers/ChatCompletionProvider.cs index d114b5ee..09aac6ee 100644 --- a/src/Plugins/BotSharp.Plugin.LLamaSharp/Providers/ChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.LLamaSharp/Providers/ChatCompletionProvider.cs @@ -55,7 +55,7 @@ public class ChatCompletionProvider : IChatCompletion _logger.LogInformation(prompt); } - foreach (var response in executor.InferAsync(prompt, inferenceParams).ToArrayAsync().Result) + foreach (var response in executor.InferAsync(prompt, inferenceParams).GetAsyncEnumerator().Current) { Console.Write(response); totalResponse += response; diff --git a/src/Plugins/BotSharp.Plugin.MetaAI/MetaAiPlugin.cs b/src/Plugins/BotSharp.Plugin.MetaAI/MetaAiPlugin.cs index f9516687..df5a3d0e 100644 --- a/src/Plugins/BotSharp.Plugin.MetaAI/MetaAiPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.MetaAI/MetaAiPlugin.cs @@ -11,6 +11,9 @@ namespace BotSharp.Plugin.MetaAI; public class MetaAiPlugin : IBotSharpPlugin { + public string Name => "Meta AI"; + public string Description => "Innovating with the freedom to explore, discover and apply AI at scale."; + public string IconUrl => "https://static.xx.fbcdn.net/rsrc.php/yJ/r/C1E_YZIckM5.svg"; public void RegisterDI(IServiceCollection services, IConfiguration config) { var settings = new MetaAiSettings(); diff --git a/src/Plugins/BotSharp.Plugin.MetaMessenger/MetaMessengerPlugin.cs b/src/Plugins/BotSharp.Plugin.MetaMessenger/MetaMessengerPlugin.cs index 5ca6e387..3bc19755 100644 --- a/src/Plugins/BotSharp.Plugin.MetaMessenger/MetaMessengerPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.MetaMessenger/MetaMessengerPlugin.cs @@ -8,6 +8,8 @@ namespace BotSharp.Plugin.MetaMessenger; public class MetaMessengerPlugin : IBotSharpPlugin { public string Name => "Meta Messenger"; + public string Description => "Messaging service that allows users to connect with others and share content."; + public string IconUrl => "https://static.xx.fbcdn.net/rsrc.php/yJ/r/C1E_YZIckM5.svg"; public void RegisterDI(IServiceCollection services, IConfiguration config) { diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/MongoStoragePlugin.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/MongoStoragePlugin.cs index e41704b8..ac142536 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/MongoStoragePlugin.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/MongoStoragePlugin.cs @@ -1,6 +1,4 @@ using BotSharp.Plugin.MongoStorage.Repository; -using MongoDB.Bson.Serialization; -using MongoDB.Bson.Serialization.Serializers; namespace BotSharp.Plugin.MongoStorage; @@ -10,7 +8,8 @@ namespace BotSharp.Plugin.MongoStorage; public class MongoStoragePlugin : IBotSharpPlugin { public string Name => "MongoDB Storage"; - public string Description => "MongoDB as the repository"; + public string Description => "MongoDB as the repository, store data in document."; + public string IconUrl => "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRrFrT-_0VYV4PraApwSUmsf4pBGWgvLTaLZGUd7942FxjErsA5iaL4n5Q7CplOmVtwEQ&usqp=CAU"; public void RegisterDI(IServiceCollection services, IConfiguration config) { diff --git a/src/Plugins/BotSharp.Plugin.PaddleSharp/PaddleSharpPlugin.cs b/src/Plugins/BotSharp.Plugin.PaddleSharp/PaddleSharpPlugin.cs index 94796b64..91ae91b9 100644 --- a/src/Plugins/BotSharp.Plugin.PaddleSharp/PaddleSharpPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.PaddleSharp/PaddleSharpPlugin.cs @@ -10,6 +10,9 @@ namespace BotSharp.Plugin.PaddleOCR; public class PaddleSharpPlugin : IBotSharpPlugin { + public string Name => "PaddlePaddle"; + public string Description => "An Open-Source Deep Learning Platform Originated from Industrial Practice"; + public string IconUrl => "https://miro.medium.com/v2/resize:fit:549/1*oZeecXkOoTzEYp-btIKwxw.jpeg"; public void RegisterDI(IServiceCollection services, IConfiguration config) { var settings = new PaddleSharpSettings(); diff --git a/src/Plugins/BotSharp.Plugin.Qdrant/QdrantPlugin.cs b/src/Plugins/BotSharp.Plugin.Qdrant/QdrantPlugin.cs index 6d330259..92ce9372 100644 --- a/src/Plugins/BotSharp.Plugin.Qdrant/QdrantPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.Qdrant/QdrantPlugin.cs @@ -7,6 +7,9 @@ namespace BotSharp.Plugin.Qdrant; public class QdrantPlugin : IBotSharpPlugin { + public string Name => "Qdrant"; + public string Description => "Vector Database - Make the most of your Unstructured Data"; + public string IconUrl => "https://qdrant.tech/images/logo_with_text.png"; public void RegisterDI(IServiceCollection services, IConfiguration config) { var settings = new QdrantSetting(); diff --git a/src/Plugins/BotSharp.Plugin.WeChat/WeChatPlugin.cs b/src/Plugins/BotSharp.Plugin.WeChat/WeChatPlugin.cs index 806b03e5..82c184a6 100644 --- a/src/Plugins/BotSharp.Plugin.WeChat/WeChatPlugin.cs +++ b/src/Plugins/BotSharp.Plugin.WeChat/WeChatPlugin.cs @@ -14,52 +14,54 @@ using Senparc.CO2NET.RegisterServices; using Microsoft.Extensions.Logging; using BotSharp.Plugin.WeChat.Users; -namespace BotSharp.Plugin.WeChat +namespace BotSharp.Plugin.WeChat; + +public class WeChatPlugin : IBotSharpAppPlugin { + public string Name => "Tecent Wechat"; + public string Description => "Free messaging and calling app, support voice,photo,video and text messages."; + public string IconUrl => "https://i.pinimg.com/originals/66/c9/44/66c94415043811725165e59b371a0aa2.png"; - public class WeChatPlugin : IBotSharpAppPlugin + public void RegisterDI(IServiceCollection services, IConfiguration config) { - public void RegisterDI(IServiceCollection services, IConfiguration config) + services.AddScoped (); + + services.AddMemoryCache(); + + services.Configure(config.GetSection("WeChat")); + + if (!Senparc.CO2NET.RegisterServices.RegisterServiceExtension.SenparcGlobalServicesRegistered) { - services.AddScoped (); - - services.AddMemoryCache(); - - services.Configure(config.GetSection("WeChat")); - - if (!Senparc.CO2NET.RegisterServices.RegisterServiceExtension.SenparcGlobalServicesRegistered) - { - services = services.AddSenparcGlobalServices(config); - } - WeChatBackgroundService.AgentId = config["WeChat:AgentId"]; - - services.AddSingleton(); - - services.AddHostedService(s => s.GetRequiredService()); - - services.TryAddSingleton(s => s.GetRequiredService()); + services = services.AddSenparcGlobalServices(config); } + WeChatBackgroundService.AgentId = config["WeChat:AgentId"]; - public void Configure(IApplicationBuilder app) + services.AddSingleton(); + + services.AddHostedService(s => s.GetRequiredService()); + + services.TryAddSingleton(s => s.GetRequiredService()); + } + + public void Configure(IApplicationBuilder app) + { + var env = app.ApplicationServices.GetRequiredService(); + var logger = app.ApplicationServices.GetRequiredService>(); + + var register = app.UseSenparcGlobal(env); + register.UseSenparcWeixin(null, (svc, settings) => { - var env = app.ApplicationServices.GetRequiredService(); - var logger = app.ApplicationServices.GetRequiredService>(); + svc.RegisterMpAccount(settings, "WeChat"); + }, app.ApplicationServices); - var register = app.UseSenparcGlobal(env); - register.UseSenparcWeixin(null, (svc, settings) => - { - svc.RegisterMpAccount(settings, "WeChat"); - }, app.ApplicationServices); + app.UseMessageHandlerForMp("/WeChatAsync", BotSharpMessageHandler.GenerateMessageHandler, options => + { + options.AccountSettingFunc = context => Senparc.Weixin.Config.SenparcWeixinSetting; + options.EnbleResponseLog = false; + options.EnableRequestLog = false; + }); - app.UseMessageHandlerForMp("/WeChatAsync", BotSharpMessageHandler.GenerateMessageHandler, options => - { - options.AccountSettingFunc = context => Senparc.Weixin.Config.SenparcWeixinSetting; - options.EnbleResponseLog = false; - options.EnableRequestLog = false; - }); + logger.LogInformation("WeChat Message Handler is running on /WeChatAsync."); - logger.LogInformation("WeChat Message Handler is running on /WeChatAsync."); - - } } } diff --git a/src/WebStarter/appsettings.json b/src/WebStarter/appsettings.json index 718ca4bc..68856631 100644 --- a/src/WebStarter/appsettings.json +++ b/src/WebStarter/appsettings.json @@ -154,6 +154,7 @@ "BotSharp.Plugin.AzureOpenAI", "BotSharp.Plugin.GoogleAI", "BotSharp.Plugin.MetaAI", + "BotSharp.Plugin.MetaMessenger", // "BotSharp.Plugin.Twilio", "BotSharp.Plugin.HuggingFace", "BotSharp.Plugin.LLamaSharp",