diff --git a/PizzaBot.sln b/PizzaBot.sln new file mode 100644 index 00000000..94158a93 --- /dev/null +++ b/PizzaBot.sln @@ -0,0 +1,46 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33712.159 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebStarter", "src\WebStarter\WebStarter.csproj", "{07AD18C5-CE7B-495A-815F-170E93CCC42A}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{32FAFFFE-A4CB-4FEE-BF7C-84518BBC6DCC}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.PizzaBot", "tests\BotSharp.Plugin.PizzaBot\BotSharp.Plugin.PizzaBot.csproj", "{A1118A2C-C6D7-4E22-9462-964AEC7CC46E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {07AD18C5-CE7B-495A-815F-170E93CCC42A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {07AD18C5-CE7B-495A-815F-170E93CCC42A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {07AD18C5-CE7B-495A-815F-170E93CCC42A}.Debug|x64.ActiveCfg = Debug|Any CPU + {07AD18C5-CE7B-495A-815F-170E93CCC42A}.Debug|x64.Build.0 = Debug|Any CPU + {07AD18C5-CE7B-495A-815F-170E93CCC42A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {07AD18C5-CE7B-495A-815F-170E93CCC42A}.Release|Any CPU.Build.0 = Release|Any CPU + {07AD18C5-CE7B-495A-815F-170E93CCC42A}.Release|x64.ActiveCfg = Release|Any CPU + {07AD18C5-CE7B-495A-815F-170E93CCC42A}.Release|x64.Build.0 = Release|Any CPU + {A1118A2C-C6D7-4E22-9462-964AEC7CC46E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A1118A2C-C6D7-4E22-9462-964AEC7CC46E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A1118A2C-C6D7-4E22-9462-964AEC7CC46E}.Debug|x64.ActiveCfg = Debug|Any CPU + {A1118A2C-C6D7-4E22-9462-964AEC7CC46E}.Debug|x64.Build.0 = Debug|Any CPU + {A1118A2C-C6D7-4E22-9462-964AEC7CC46E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A1118A2C-C6D7-4E22-9462-964AEC7CC46E}.Release|Any CPU.Build.0 = Release|Any CPU + {A1118A2C-C6D7-4E22-9462-964AEC7CC46E}.Release|x64.ActiveCfg = Release|Any CPU + {A1118A2C-C6D7-4E22-9462-964AEC7CC46E}.Release|x64.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {A1118A2C-C6D7-4E22-9462-964AEC7CC46E} = {32FAFFFE-A4CB-4FEE-BF7C-84518BBC6DCC} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19} + EndGlobalSection +EndGlobal diff --git a/docs/index.rst b/docs/index.rst index 6d710b2d..fbd85b59 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -40,6 +40,7 @@ The main documentation for the site is organized into the following sections: :caption: Get Started with BotSharp quick-start/overview + quick-start/get-started quick-start/installation .. _agent-docs: diff --git a/docs/quick-start/assets/PizzaBotSample1.png b/docs/quick-start/assets/PizzaBotSample1.png new file mode 100644 index 00000000..2c69f9df Binary files /dev/null and b/docs/quick-start/assets/PizzaBotSample1.png differ diff --git a/docs/quick-start/assets/PizzaBotSample2.png b/docs/quick-start/assets/PizzaBotSample2.png new file mode 100644 index 00000000..1a7c6493 Binary files /dev/null and b/docs/quick-start/assets/PizzaBotSample2.png differ diff --git a/docs/quick-start/assets/PizzaBotSample3.png b/docs/quick-start/assets/PizzaBotSample3.png new file mode 100644 index 00000000..b689ab76 Binary files /dev/null and b/docs/quick-start/assets/PizzaBotSample3.png differ diff --git a/docs/quick-start/assets/PizzaBotSample4.png b/docs/quick-start/assets/PizzaBotSample4.png new file mode 100644 index 00000000..519b62ee Binary files /dev/null and b/docs/quick-start/assets/PizzaBotSample4.png differ diff --git a/docs/quick-start/get-started.md b/docs/quick-start/get-started.md new file mode 100644 index 00000000..eadcc765 --- /dev/null +++ b/docs/quick-start/get-started.md @@ -0,0 +1,21 @@ +# Get Started + +### Get started with Pizza Bot + +In order to allow developers to experience the convenience of BotSharp as quickly as possible, we have designed a basic sample project PizzaBot. This example allows you to run it quickly on your local machine. This example requires `llama-2` quantized model downloaded with `gguf` format if you want to run locally. + +```console +git clone https://github.com/SciSharp/BotSharp +``` + +Double click `PizzaBot` to start the solution. +![Pizza Bot](assets/PizzaBotSample1.png) + +Hit `WebStarter` to run it in Debug mode. +![Pizza Bot Starter](assets/PizzaBotSample2.png) + +Here you go, you will see this running screen. +![Pizza Bot Starter](assets/PizzaBotSample3.png) + +Next, try to access the chat from `Open API`, we public our [Postman collection](https://www.postman.com/orange-flare-634868/workspace/botsharp/collection/1346299-d1a31c49-825d-4449-bdc8-936c66ff6bfd). Remember to set the environment as `localhost`. +![Pizza Bot Starter](assets/PizzaBotSample4.png) diff --git a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs index ad792f7f..1f71192a 100644 --- a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs @@ -119,8 +119,6 @@ public class ChatCompletionProvider : IChatCompletion } else { - _logger.LogInformation($"[{agent.Name}] {message.Role}: {message.Content}"); - var msg = new RoleDialogModel(AgentRole.Assistant, message.Content) { CurrentAgentId= agent.Id diff --git a/src/Plugins/BotSharp.Plugin.LLamaSharp/Providers/ChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.LLamaSharp/Providers/ChatCompletionProvider.cs index 191d087f..02ab50e7 100644 --- a/src/Plugins/BotSharp.Plugin.LLamaSharp/Providers/ChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.LLamaSharp/Providers/ChatCompletionProvider.cs @@ -13,6 +13,7 @@ using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq; +using System.Text; using System.Threading.Tasks; namespace BotSharp.Plugin.LLamaSharp.Providers; @@ -51,9 +52,9 @@ public class ChatCompletionProvider : IChatCompletion var inferenceParams = new InferenceParams() { - Temperature = 0.9f, - AntiPrompts = new List { $"{AgentRole.User}:" }, - MaxTokens = 256 + Temperature = 0.1f, + AntiPrompts = new List { $"{AgentRole.User}:", "[/INST]" }, + MaxTokens = 64 }; string totalResponse = ""; @@ -77,8 +78,6 @@ public class ChatCompletionProvider : IChatCompletion totalResponse = totalResponse.Replace(anti, "").Trim(); } - _logger.LogInformation($"[{agent.Name}] {AgentRole.Assistant}: {totalResponse}"); - var msg = new RoleDialogModel(AgentRole.Assistant, totalResponse) { CurrentAgentId = agent.Id diff --git a/src/WebStarter/Program.cs b/src/WebStarter/Program.cs index 1b8a0dc7..94ba66aa 100644 --- a/src/WebStarter/Program.cs +++ b/src/WebStarter/Program.cs @@ -1,7 +1,6 @@ using BotSharp.Abstraction.Users; using BotSharp.Core; using BotSharp.Core.Users.Services; -using EntityFrameworkCore.BootKit; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.IdentityModel.Tokens; using System.Text; diff --git a/src/WebStarter/WebStarter.csproj b/src/WebStarter/WebStarter.csproj index 1c7a50e5..b0d9b1fc 100644 --- a/src/WebStarter/WebStarter.csproj +++ b/src/WebStarter/WebStarter.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -26,15 +26,30 @@ + + + + + + + + + + + + + + + + - - - + + @@ -49,5 +64,9 @@ + + + + diff --git a/src/WebStarter/appsettings.json b/src/WebStarter/appsettings.json index 23c898a7..826c5a7b 100644 --- a/src/WebStarter/appsettings.json +++ b/src/WebStarter/appsettings.json @@ -106,8 +106,8 @@ "PluginLoader": { "Assemblies": [ - "BotSharp.Plugin.MongoStorage", "BotSharp.Core", + "BotSharp.Plugin.MongoStorage", "BotSharp.Plugin.AzureOpenAI", "BotSharp.Plugin.MetaAI", "BotSharp.Plugin.HuggingFace", diff --git a/src/WebStarter/data/agents/c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd/agent.json b/src/WebStarter/data/agents/c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd/agent.json new file mode 100644 index 00000000..b196e2f0 --- /dev/null +++ b/src/WebStarter/data/agents/c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd/agent.json @@ -0,0 +1,7 @@ +{ + "name": "Ordering", + "description": "Make pizza order according to user's preference.", + "createdDateTime": "2023-07-26T02:29:25.123224Z", + "updatedDateTime": "2023-07-26T02:29:25.123274Z", + "id": "c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd" +} \ No newline at end of file diff --git a/src/WebStarter/data/agents/c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd/functions.json b/src/WebStarter/data/agents/c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd/functions.json new file mode 100644 index 00000000..2315c87a --- /dev/null +++ b/src/WebStarter/data/agents/c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd/functions.json @@ -0,0 +1,51 @@ +[ + { + "name": "get_pizza_price", + "description": "call this function to get the pizza price", + "parameters": { + "type": "object", + "properties": { + "pizza_type": { + "type": "string", + "description": "The pizza type." + }, + "quantity": { + "type": "string", + "description": "quantity of pizza." + } + }, + "required": ["pizza_type", "quantity"] + } + }, + { + "name": "get_pizza_types", + "description": "get all pizza types.", + "parameters": { + "type": "object", + "properties": {}, + "required": [] + } + }, + { + "name": "place_an_order", + "description": "Place an order when user has confirmed the pizza type and quantity.", + "parameters": { + "type": "object", + "properties": { + "pizza_type": { + "type": "string", + "description": "The pizza type." + }, + "quantity": { + "type": "number", + "description": "quantity of pizza." + }, + "unit_price": { + "type": "number", + "description": "unit price" + } + }, + "required": ["pizza_type", "quantity", "unit_price"] + } + } +] diff --git a/src/WebStarter/data/agents/c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd/instruction.liquid b/src/WebStarter/data/agents/c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd/instruction.liquid new file mode 100644 index 00000000..6368d9b4 --- /dev/null +++ b/src/WebStarter/data/agents/c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd/instruction.liquid @@ -0,0 +1,9 @@ +You are now a Pizza Ordering agent, and you can help customers order a pizza according to the user's preferences. + +Follow below step to place order: +1: Ask user preferences. +2: Confirm with user the pizza type and quantity. +3: Call function place_an_order to purchase. + +Use below information to help ordering process: +* Today is {{current_date}}, the time now is {{current_time}}, day of week is {{current_weekday}}. \ No newline at end of file diff --git a/src/WebStarter/data/agents/c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd/responses/func.get_pizza_price.0.liquid b/src/WebStarter/data/agents/c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd/responses/func.get_pizza_price.0.liquid new file mode 100644 index 00000000..2aa8f2bd --- /dev/null +++ b/src/WebStarter/data/agents/c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd/responses/func.get_pizza_price.0.liquid @@ -0,0 +1,6 @@ +{% if pizza_type == "cheese" -%} + The price for a slice of cheese pizza is {{ cheese_unit_price }}. Would you like to proceed the order? +{%- endif %} +{% if quantity == nil -%} + How many slices would you like to order? +{%- endif %} \ No newline at end of file diff --git a/src/WebStarter/data/users/456e35c5-caf0-4d45-9084-b44a8ca717e4/agents.json b/src/WebStarter/data/users/456e35c5-caf0-4d45-9084-b44a8ca717e4/agents.json index 3bb0ecf7..83e8c2af 100644 --- a/src/WebStarter/data/users/456e35c5-caf0-4d45-9084-b44a8ca717e4/agents.json +++ b/src/WebStarter/data/users/456e35c5-caf0-4d45-9084-b44a8ca717e4/agents.json @@ -6,13 +6,6 @@ "createdTime": "2023-08-14T18:14:11.6829767Z", "id": "1273379c-4419-460a-b0a2-5695afd097f5" }, - { - "userId": "456e35c5-caf0-4d45-9084-b44a8ca717e4", - "agentId": "ff431273-0c28-4647-88bf-86d82443c579", - "updatedTime": "2023-08-14T18:14:11.6833783Z", - "createdTime": "2023-08-14T18:14:11.6829767Z", - "id": "5ed47062-3dba-4b96-a7d7-5dbab48b71ad" - }, { "userId": "456e35c5-caf0-4d45-9084-b44a8ca717e4", "agentId": "c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd", diff --git a/tests/BotSharp.Plugin.PizzaBot/BotSharp.Plugin.PizzaBot.csproj b/tests/BotSharp.Plugin.PizzaBot/BotSharp.Plugin.PizzaBot.csproj index 43ec9965..2bc35d74 100644 --- a/tests/BotSharp.Plugin.PizzaBot/BotSharp.Plugin.PizzaBot.csproj +++ b/tests/BotSharp.Plugin.PizzaBot/BotSharp.Plugin.PizzaBot.csproj @@ -8,7 +8,7 @@ - +