Add Pizza bot example.
This commit is contained in:
parent
55f1ff9ae1
commit
9393508a46
13
BotSharp.sln
13
BotSharp.sln
|
|
@ -45,7 +45,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.MetaMesseng
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.OpenAPI", "src\Infrastructure\BotSharp.OpenAPI\BotSharp.OpenAPI.csproj", "{7E63F5F8-4EA0-498B-ABFE-2BBE4D7DDBA7}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.OpenAPI", "src\Infrastructure\BotSharp.OpenAPI\BotSharp.OpenAPI.csproj", "{7E63F5F8-4EA0-498B-ABFE-2BBE4D7DDBA7}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Plugin.LLamaSharp", "src\Plugins\BotSharp.Plugin.LLamaSharp\BotSharp.Plugin.LLamaSharp.csproj", "{46B7B54F-1425-4C9D-824A-9B826855D249}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.LLamaSharp", "src\Plugins\BotSharp.Plugin.LLamaSharp\BotSharp.Plugin.LLamaSharp.csproj", "{46B7B54F-1425-4C9D-824A-9B826855D249}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.PizzaBot", "tests\BotSharp.Plugin.PizzaBot\BotSharp.Plugin.PizzaBot.csproj", "{A1118A2C-C6D7-4E22-9462-964AEC7CC46E}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
|
@ -167,6 +169,14 @@ Global
|
||||||
{46B7B54F-1425-4C9D-824A-9B826855D249}.Release|Any CPU.Build.0 = Release|Any CPU
|
{46B7B54F-1425-4C9D-824A-9B826855D249}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{46B7B54F-1425-4C9D-824A-9B826855D249}.Release|x64.ActiveCfg = Release|Any CPU
|
{46B7B54F-1425-4C9D-824A-9B826855D249}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
{46B7B54F-1425-4C9D-824A-9B826855D249}.Release|x64.Build.0 = Release|Any CPU
|
{46B7B54F-1425-4C9D-824A-9B826855D249}.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
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
@ -190,6 +200,7 @@ Global
|
||||||
{8300F66D-9EB8-438A-BF0F-70DFBE07D9DE} = {64264688-0F5C-4AB0-8F2B-B59B717CCE00}
|
{8300F66D-9EB8-438A-BF0F-70DFBE07D9DE} = {64264688-0F5C-4AB0-8F2B-B59B717CCE00}
|
||||||
{7E63F5F8-4EA0-498B-ABFE-2BBE4D7DDBA7} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
|
{7E63F5F8-4EA0-498B-ABFE-2BBE4D7DDBA7} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
|
||||||
{46B7B54F-1425-4C9D-824A-9B826855D249} = {D5293208-2BEF-42FC-A64C-5954F61720BA}
|
{46B7B54F-1425-4C9D-824A-9B826855D249} = {D5293208-2BEF-42FC-A64C-5954F61720BA}
|
||||||
|
{A1118A2C-C6D7-4E22-9462-964AEC7CC46E} = {32FAFFFE-A4CB-4FEE-BF7C-84518BBC6DCC}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19}
|
SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ public class RoutingRecord
|
||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("required")]
|
[JsonPropertyName("required")]
|
||||||
public List<string> RequiredFields { get; set; }
|
public List<string> RequiredFields { get; set; } = new List<string>();
|
||||||
|
|
||||||
[JsonPropertyName("redirect_to")]
|
[JsonPropertyName("redirect_to")]
|
||||||
public string RedirectTo { get; set; }
|
public string RedirectTo { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\tests\BotSharp.Plugin.PizzaBot\BotSharp.Plugin.PizzaBot.csproj" />
|
||||||
<ProjectReference Include="..\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
|
<ProjectReference Include="..\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
|
||||||
<ProjectReference Include="..\Infrastructure\BotSharp.OpenAPI\BotSharp.OpenAPI.csproj" />
|
<ProjectReference Include="..\Infrastructure\BotSharp.OpenAPI\BotSharp.OpenAPI.csproj" />
|
||||||
<ProjectReference Include="..\Plugins\BotSharp.Plugin.AzureOpenAI\BotSharp.Plugin.AzureOpenAI.csproj" />
|
<ProjectReference Include="..\Plugins\BotSharp.Plugin.AzureOpenAI\BotSharp.Plugin.AzureOpenAI.csproj" />
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
"Router": {
|
"Router": {
|
||||||
"RouterId": "",
|
"RouterId": "01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a",
|
||||||
"ReasonerId": ""
|
"ReasonerId": "03d3fb55-9ada-423b-a6b4-f9ecddf4b26e"
|
||||||
},
|
},
|
||||||
|
|
||||||
"Agent": {
|
"Agent": {
|
||||||
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
"Conversation": {
|
"Conversation": {
|
||||||
"DataDir": "conversations",
|
"DataDir": "conversations",
|
||||||
|
"ShowVerboseLog": false,
|
||||||
"ChatCompletion": "AzureOpenAI.Providers.ChatCompletionProvider"
|
"ChatCompletion": "AzureOpenAI.Providers.ChatCompletionProvider"
|
||||||
// "ChatCompletion": "LLamaSharp.ChatCompletionProvider"
|
// "ChatCompletion": "LLamaSharp.ChatCompletionProvider"
|
||||||
},
|
},
|
||||||
|
|
@ -103,7 +104,8 @@
|
||||||
"BotSharp.Plugin.MetaAI",
|
"BotSharp.Plugin.MetaAI",
|
||||||
"BotSharp.Plugin.Qdrant",
|
"BotSharp.Plugin.Qdrant",
|
||||||
"BotSharp.Plugin.PaddleSharp",
|
"BotSharp.Plugin.PaddleSharp",
|
||||||
"BotSharp.Plugin.WeChat"
|
"BotSharp.Plugin.WeChat",
|
||||||
|
"BotSharp.Plugin.PizzaBot"
|
||||||
],
|
],
|
||||||
"Plugins": [
|
"Plugins": [
|
||||||
"KnowledgeBasePlugin",
|
"KnowledgeBasePlugin",
|
||||||
|
|
@ -113,7 +115,8 @@
|
||||||
"MetaAiPlugin",
|
"MetaAiPlugin",
|
||||||
"QdrantPlugin",
|
"QdrantPlugin",
|
||||||
"PaddleSharpPlugin",
|
"PaddleSharpPlugin",
|
||||||
"WeChatPlugin"
|
"WeChatPlugin",
|
||||||
|
"PizzaBotPlugin"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netstandard2.1</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<LangVersion>10</LangVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\src\Infrastructure\BotSharp.Core\BotSharp.Core.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
14
tests/BotSharp.Plugin.PizzaBot/Functions/GetPizzaPricesFn.cs
Normal file
14
tests/BotSharp.Plugin.PizzaBot/Functions/GetPizzaPricesFn.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
using BotSharp.Abstraction.Conversations.Models;
|
||||||
|
|
||||||
|
namespace BotSharp.Plugin.PizzaBot.Functions;
|
||||||
|
|
||||||
|
public class GetPizzaPricesFn : IFunctionCallback
|
||||||
|
{
|
||||||
|
public string Name => "get_pizza_price";
|
||||||
|
|
||||||
|
public async Task<bool> Execute(RoleDialogModel message)
|
||||||
|
{
|
||||||
|
message.ExecutionResult = "Pepperoni Pizza: $3.5/slice, Cheese Pizza: $2.5/slice, Margherita Pizza: $3.0/slice";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
14
tests/BotSharp.Plugin.PizzaBot/Functions/GetPizzaTypesFn.cs
Normal file
14
tests/BotSharp.Plugin.PizzaBot/Functions/GetPizzaTypesFn.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
using BotSharp.Abstraction.Conversations.Models;
|
||||||
|
|
||||||
|
namespace BotSharp.Plugin.PizzaBot.Functions;
|
||||||
|
|
||||||
|
public class GetPizzaTypesFn : IFunctionCallback
|
||||||
|
{
|
||||||
|
public string Name => "get_pizza_types";
|
||||||
|
|
||||||
|
public async Task<bool> Execute(RoleDialogModel message)
|
||||||
|
{
|
||||||
|
message.ExecutionResult = "Pepperoni Pizza, Cheese Pizza, Margherita Pizza";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
14
tests/BotSharp.Plugin.PizzaBot/Functions/MakeOrderFn.cs
Normal file
14
tests/BotSharp.Plugin.PizzaBot/Functions/MakeOrderFn.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
using BotSharp.Abstraction.Conversations.Models;
|
||||||
|
|
||||||
|
namespace BotSharp.Plugin.PizzaBot.Functions;
|
||||||
|
|
||||||
|
public class MakeOrderFn : IFunctionCallback
|
||||||
|
{
|
||||||
|
public string Name => "make_order";
|
||||||
|
|
||||||
|
public async Task<bool> Execute(RoleDialogModel message)
|
||||||
|
{
|
||||||
|
message.ExecutionResult = "The order number is P123-01";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
14
tests/BotSharp.Plugin.PizzaBot/Functions/OrderFoundFn.cs
Normal file
14
tests/BotSharp.Plugin.PizzaBot/Functions/OrderFoundFn.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
using BotSharp.Abstraction.Conversations.Models;
|
||||||
|
|
||||||
|
namespace BotSharp.Plugin.PizzaBot.Functions;
|
||||||
|
|
||||||
|
public class OrderFoundFn : IFunctionCallback
|
||||||
|
{
|
||||||
|
public string Name => "order_found";
|
||||||
|
|
||||||
|
public async Task<bool> Execute(RoleDialogModel message)
|
||||||
|
{
|
||||||
|
message.ExecutionResult = "The order number is P123-01";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
17
tests/BotSharp.Plugin.PizzaBot/Hooks/PizzaBotAgentHook.cs
Normal file
17
tests/BotSharp.Plugin.PizzaBot/Hooks/PizzaBotAgentHook.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
namespace BotSharp.Plugin.PizzaBot.Hooks;
|
||||||
|
|
||||||
|
public class PizzaBotAgentHook : AgentHookBase
|
||||||
|
{
|
||||||
|
public PizzaBotAgentHook(IServiceProvider services, AgentSettings settings)
|
||||||
|
: base(services, settings)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool OnInstructionLoaded(string template, Dictionary<string, object> dict)
|
||||||
|
{
|
||||||
|
dict["current_date"] = $"{DateTime.Now:MMM dd, yyyy}";
|
||||||
|
dict["current_time"] = $"{DateTime.Now:hh:mm t}";
|
||||||
|
dict["current_weekday"] = $"{DateTime.Now:dddd}";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
19
tests/BotSharp.Plugin.PizzaBot/PizzaBotPlugin.cs
Normal file
19
tests/BotSharp.Plugin.PizzaBot/PizzaBotPlugin.cs
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
using BotSharp.Abstraction.Agents;
|
||||||
|
using BotSharp.Plugin.PizzaBot.Hooks;
|
||||||
|
|
||||||
|
namespace BotSharp.Plugin.PizzaBot;
|
||||||
|
|
||||||
|
public class PizzaBotPlugin : IBotSharpPlugin
|
||||||
|
{
|
||||||
|
public void RegisterDI(IServiceCollection services, IConfiguration config)
|
||||||
|
{
|
||||||
|
// Register callback function
|
||||||
|
services.AddScoped<IFunctionCallback, GetPizzaTypesFn>();
|
||||||
|
services.AddScoped<IFunctionCallback, GetPizzaPricesFn>();
|
||||||
|
services.AddScoped<IFunctionCallback, MakeOrderFn>();
|
||||||
|
services.AddScoped<IFunctionCallback, OrderFoundFn>();
|
||||||
|
|
||||||
|
// Register hooks
|
||||||
|
services.AddScoped<IAgentHook, PizzaBotAgentHook>();
|
||||||
|
}
|
||||||
|
}
|
||||||
12
tests/BotSharp.Plugin.PizzaBot/Using.cs
Normal file
12
tests/BotSharp.Plugin.PizzaBot/Using.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
global using System;
|
||||||
|
global using System.Collections.Generic;
|
||||||
|
global using System.Text;
|
||||||
|
global using System.Threading.Tasks;
|
||||||
|
global using System.ComponentModel.DataAnnotations;
|
||||||
|
global using Microsoft.Extensions.Configuration;
|
||||||
|
global using Microsoft.Extensions.DependencyInjection;
|
||||||
|
global using BotSharp.Abstraction.Plugins;
|
||||||
|
global using BotSharp.Abstraction.Functions;
|
||||||
|
global using BotSharp.Plugin.PizzaBot.Functions;
|
||||||
|
global using BotSharp.Abstraction.Agents.Settings;
|
||||||
|
global using BotSharp.Core.Agents.Services;
|
||||||
Loading…
Reference in a new issue