From 0fe19821ccd314f79c325fe9a4577205dd687d94 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Sun, 8 Oct 2023 17:51:46 -0500 Subject: [PATCH] Add readme of plugin. --- docs/architecture/plugin.md | 42 ++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/docs/architecture/plugin.md b/docs/architecture/plugin.md index 621d13bc..601967e8 100644 --- a/docs/architecture/plugin.md +++ b/docs/architecture/plugin.md @@ -1 +1,41 @@ -# Plug-in \ No newline at end of file +# Plug-in + +**BotSharp** adopts a `plug-in` architecture design, and the modules are independent of each other. With `Conversation` as the core, each plug-in completes various functionalities (such as adding LLM provider and Text Embedding provider) through the Hook mechanism. Regarding the Hooks provided by the system, you can refer to the special [Hook section](hooks.md). + +Here we will introduce how to add a new plug-in to extend your LLM application. We still use the example of PizzaBot to illustrate how to complete this task. + +1. Add Class Library + Added a new class library called BotSharp.Plugin.PizzaBot and add referece to the web start application + +2. Implement Interface + Add a new class named `PizzaBotPlugin` and implement interface `IBotSharpPlugin`. + ```csharp + namespace BotSharp.Plugin.PizzaBot; + + public class PizzaBotPlugin : IBotSharpPlugin + { + public void RegisterDI(IServiceCollection services, IConfiguration config) + { + // Register callback function + services.AddScoped(); + + // Register hooks + services.AddScoped(); + } + } + ``` + +3. Add to Settings + Add plugin to appsettings.json. + ```json + "PluginLoader": { + "Assemblies": [ + "BotSharp.Plugin.PizzaBot" + ] + } + ``` + +After starting the web project, you should see a successful loading message printed in the Console. +```shell +Loaded plugin PizzaBotPlugin from BotSharp.Plugin.PizzaBot. +``` \ No newline at end of file