diff --git a/README.md b/README.md index 11c9e34c..fac34c94 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ It's written in C# running on .Net Core that is full cross-platform framework, t **BotSharp** is in accordance with components principle strictly, decouples every part that is needed in the platform builder. So you can choose different UI/UX, or pick up a different LLM providers. They are all modulized based on unified interfaces. **BotSharp** provides an advanced Agent abstraction layer to efficiently manage complex application scenarios in enterprises, allowing enterprise developers to efficiently integrate AI into business systems. +![](./docs/architecture/assets/llm_diagram.png) + ### Some Features * Built-in multi-agents and conversation with state management. diff --git a/docs/architecture/assets/llm_diagram.png b/docs/architecture/assets/llm_diagram.png new file mode 100644 index 00000000..7a44a709 Binary files /dev/null and b/docs/architecture/assets/llm_diagram.png differ diff --git a/src/Infrastructure/BotSharp.Core/Instructs/InstructService.cs b/src/Infrastructure/BotSharp.Core/Instructs/InstructService.cs index 2243e5e7..d9f0fd6c 100644 --- a/src/Infrastructure/BotSharp.Core/Instructs/InstructService.cs +++ b/src/Infrastructure/BotSharp.Core/Instructs/InstructService.cs @@ -22,6 +22,15 @@ public partial class InstructService : IInstructService foreach (var hook in hooks) { await hook.BeforeCompletion(message); + + // Interrupted by hook + if (message.StopCompletion) + { + return new InstructResult + { + Text = message.Content + }; + } } var completer = CompletionProvider.GetTextCompletion(_services); diff --git a/src/Plugins/BotSharp.Plugin.LLamaSharp/BotSharp.Plugin.LLamaSharp.csproj b/src/Plugins/BotSharp.Plugin.LLamaSharp/BotSharp.Plugin.LLamaSharp.csproj index 986936bc..9e4874cc 100644 --- a/src/Plugins/BotSharp.Plugin.LLamaSharp/BotSharp.Plugin.LLamaSharp.csproj +++ b/src/Plugins/BotSharp.Plugin.LLamaSharp/BotSharp.Plugin.LLamaSharp.csproj @@ -10,7 +10,7 @@ - + diff --git a/src/Plugins/BotSharp.Plugin.LLamaSharp/LlamaAiModel.cs b/src/Plugins/BotSharp.Plugin.LLamaSharp/LlamaAiModel.cs index 7f9a7748..9d55dead 100644 --- a/src/Plugins/BotSharp.Plugin.LLamaSharp/LlamaAiModel.cs +++ b/src/Plugins/BotSharp.Plugin.LLamaSharp/LlamaAiModel.cs @@ -35,7 +35,7 @@ public class LlamaAiModel _params = new ModelParams(Path.Combine(_settings.ModelDir, model)) { - ContextSize = _settings.MaxContextLength, + ContextSize = (uint)_settings.MaxContextLength, Seed = 1337, GpuLayerCount = _settings.NumberOfGpuLayer }; diff --git a/src/Plugins/BotSharp.Plugin.LLamaSharp/Providers/ChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.LLamaSharp/Providers/ChatCompletionProvider.cs index 46a82dfd..adf452e0 100644 --- a/src/Plugins/BotSharp.Plugin.LLamaSharp/Providers/ChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.LLamaSharp/Providers/ChatCompletionProvider.cs @@ -50,7 +50,7 @@ public class ChatCompletionProvider : IChatCompletion _logger.LogInformation(prompt); } - foreach (var response in executor.Infer(prompt, inferenceParams)) + foreach (var response in executor.InferAsync(prompt, inferenceParams).ToArrayAsync().Result) { Console.Write(response); totalResponse += response; @@ -108,7 +108,7 @@ public class ChatCompletionProvider : IChatCompletion _logger.LogInformation(prompt); } - foreach (var response in executor.Infer(prompt, inferenceParams)) + await foreach (var response in executor.InferAsync(prompt, inferenceParams)) { Console.Write(response); totalResponse += response; @@ -151,7 +151,7 @@ public class ChatCompletionProvider : IChatCompletion _logger.LogInformation(agent.Instruction); } - foreach (var response in executor.Infer(agent.Instruction, inferenceParams)) + await foreach (var response in executor.InferAsync(agent.Instruction, inferenceParams)) { Console.Write(response); totalResponse += response; diff --git a/src/Plugins/BotSharp.Plugin.LLamaSharp/Providers/TextCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.LLamaSharp/Providers/TextCompletionProvider.cs index c5a66f6f..daba2cd5 100644 --- a/src/Plugins/BotSharp.Plugin.LLamaSharp/Providers/TextCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.LLamaSharp/Providers/TextCompletionProvider.cs @@ -36,7 +36,7 @@ public class TextCompletionProvider : ITextCompletion _tokenStatistics.StartTimer(); string completion = ""; - foreach (var response in executor.Infer(text, inferenceParams)) + await foreach (var response in executor.InferAsync(text, inferenceParams)) { Console.Write(response); completion += response; diff --git a/src/WebStarter/WebStarter.csproj b/src/WebStarter/WebStarter.csproj index 90130588..b05729a7 100644 --- a/src/WebStarter/WebStarter.csproj +++ b/src/WebStarter/WebStarter.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -35,7 +35,7 @@ - + diff --git a/tests/BotSharp.Plugin.PizzaBot/Hooks/PizzaBotAgentHook.cs b/tests/BotSharp.Plugin.PizzaBot/Hooks/PizzaBotAgentHook.cs index 040b4cd7..76ac568b 100644 --- a/tests/BotSharp.Plugin.PizzaBot/Hooks/PizzaBotAgentHook.cs +++ b/tests/BotSharp.Plugin.PizzaBot/Hooks/PizzaBotAgentHook.cs @@ -4,6 +4,8 @@ namespace BotSharp.Plugin.PizzaBot.Hooks; public class PizzaBotAgentHook : AgentHookBase { + public override string SelfId => "01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a"; + public PizzaBotAgentHook(IServiceProvider services, AgentSettings settings) : base(services, settings) {