Plugin IconUrl.
This commit is contained in:
parent
0eb9745170
commit
4c6c035b07
|
|
@ -1,5 +1,6 @@
|
|||
<Project>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<LangVersion>10.0</LangVersion>
|
||||
<OutputPath>..\..\..\packages</OutputPath>
|
||||
<BotSharpVersion>0.20.0</BotSharpVersion>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,12 @@ namespace BotSharp.Abstraction.Agents.Models;
|
|||
|
||||
public class AgentLlmConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Is inherited from default Agent Settings
|
||||
/// </summary>
|
||||
[JsonPropertyName("is_inherit")]
|
||||
public bool IsInherit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Completion Provider
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,10 @@ namespace BotSharp.Abstraction.Repositories.Filters;
|
|||
public class ConversationFilter
|
||||
{
|
||||
public Pagination Pager { get; set; } = new Pagination();
|
||||
/// <summary>
|
||||
/// Conversation Id
|
||||
/// </summary>
|
||||
public string? Id { get; set; }
|
||||
public string? AgentId { get; set; }
|
||||
public string? Status { get; set; }
|
||||
public string? Channel { get; set; }
|
||||
|
|
|
|||
|
|
@ -26,7 +26,15 @@ public partial class AgentService
|
|||
{
|
||||
_logger.LogError($"Can't find agent {id}");
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
// Load llm config
|
||||
var agentSetting = _services.GetRequiredService<AgentSettings>();
|
||||
if (profile.LlmConfig == null)
|
||||
{
|
||||
profile.LlmConfig = agentSetting.LlmConfig;
|
||||
profile.LlmConfig.IsInherit = true;
|
||||
}
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,10 @@ public partial class AgentService
|
|||
record.Templates = agent.Templates ?? new List<AgentTemplate>();
|
||||
record.Responses = agent.Responses ?? new List<AgentResponse>();
|
||||
record.Samples = agent.Samples ?? new List<string>();
|
||||
record.LlmConfig = agent.LlmConfig;
|
||||
if (!agent.LlmConfig.IsInherit)
|
||||
{
|
||||
record.LlmConfig = agent.LlmConfig;
|
||||
}
|
||||
|
||||
_db.UpdateAgent(record, updateField);
|
||||
await Task.CompletedTask;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -81,6 +81,24 @@ public class ConversationController : ControllerBase, IApiAdapter
|
|||
return dialogs;
|
||||
}
|
||||
|
||||
[HttpGet("/conversation/{conversationId}")]
|
||||
public async Task<ConversationViewModel> GetConversation([FromRoute] string conversationId)
|
||||
{
|
||||
var service = _services.GetRequiredService<IConversationService>();
|
||||
var conversations = await service.GetConversations(new ConversationFilter
|
||||
{
|
||||
Id = conversationId
|
||||
});
|
||||
|
||||
var userService = _services.GetRequiredService<IUserService>();
|
||||
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<bool> DeleteConversation([FromRoute] string conversationId)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Instruction
|
||||
/// </summary>
|
||||
public string? Instruction { get; set; }
|
||||
public string Instruction { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Templates
|
||||
|
|
@ -22,7 +23,7 @@ public class AgentUpdateModel
|
|||
/// <summary>
|
||||
/// Samples
|
||||
/// </summary>
|
||||
public string? Samples { get; set; }
|
||||
public List<string>? Samples { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Functions
|
||||
|
|
@ -33,8 +34,10 @@ public class AgentUpdateModel
|
|||
/// Routes
|
||||
/// </summary>
|
||||
public List<AgentResponse>? 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
|
||||
/// </summary>
|
||||
public List<string>? Profiles { get; set; }
|
||||
[JsonPropertyName("routing_rules")]
|
||||
|
||||
public List<RoutingRuleUpdateModel>? RoutingRules { get; set; }
|
||||
[JsonPropertyName("llm_config")]
|
||||
|
||||
public AgentLlmConfig? LlmConfig { get; set; }
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ public class AgentViewModel
|
|||
public List<FunctionDef> Functions { get; set; }
|
||||
public List<AgentResponse> Responses { get; set; }
|
||||
public List<string> Samples { get; set; }
|
||||
[JsonPropertyName("is_public")]
|
||||
public bool IsPublic { get; set; }
|
||||
|
||||
[JsonPropertyName("allow_routing")]
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<LangVersion>$(LangVersion)</LangVersion>
|
||||
<VersionPrefix>$(BotSharpVersion)</VersionPrefix>
|
||||
<GeneratePackageOnBuild>$(GeneratePackageOnBuild)</GeneratePackageOnBuild>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
<GenerateDocumentationFile>$(GenerateDocumentationFile)</GenerateDocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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<IVectorDb, MemVectorDatabase>();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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<IWeChatAccountUserService,WeChatAccountUserService> ();
|
||||
|
||||
services.AddMemoryCache();
|
||||
|
||||
services.Configure<SenparcWeixinSetting>(config.GetSection("WeChat"));
|
||||
|
||||
if (!Senparc.CO2NET.RegisterServices.RegisterServiceExtension.SenparcGlobalServicesRegistered)
|
||||
{
|
||||
services.AddScoped<IWeChatAccountUserService,WeChatAccountUserService> ();
|
||||
|
||||
services.AddMemoryCache();
|
||||
|
||||
services.Configure<SenparcWeixinSetting>(config.GetSection("WeChat"));
|
||||
|
||||
if (!Senparc.CO2NET.RegisterServices.RegisterServiceExtension.SenparcGlobalServicesRegistered)
|
||||
{
|
||||
services = services.AddSenparcGlobalServices(config);
|
||||
}
|
||||
WeChatBackgroundService.AgentId = config["WeChat:AgentId"];
|
||||
|
||||
services.AddSingleton<WeChatBackgroundService>();
|
||||
|
||||
services.AddHostedService(s => s.GetRequiredService<WeChatBackgroundService>());
|
||||
|
||||
services.TryAddSingleton<IMessageQueue>(s => s.GetRequiredService<WeChatBackgroundService>());
|
||||
services = services.AddSenparcGlobalServices(config);
|
||||
}
|
||||
WeChatBackgroundService.AgentId = config["WeChat:AgentId"];
|
||||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
services.AddSingleton<WeChatBackgroundService>();
|
||||
|
||||
services.AddHostedService(s => s.GetRequiredService<WeChatBackgroundService>());
|
||||
|
||||
services.TryAddSingleton<IMessageQueue>(s => s.GetRequiredService<WeChatBackgroundService>());
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app)
|
||||
{
|
||||
var env = app.ApplicationServices.GetRequiredService<IHostEnvironment>();
|
||||
var logger = app.ApplicationServices.GetRequiredService<ILogger<WeChatPlugin>>();
|
||||
|
||||
var register = app.UseSenparcGlobal(env);
|
||||
register.UseSenparcWeixin(null, (svc, settings) =>
|
||||
{
|
||||
var env = app.ApplicationServices.GetRequiredService<IHostEnvironment>();
|
||||
var logger = app.ApplicationServices.GetRequiredService<ILogger<WeChatPlugin>>();
|
||||
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.");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in a new issue