From 8fcada182f1a4f9ac37ac82291113d786daf7a70 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Thu, 19 Oct 2023 22:47:14 -0500 Subject: [PATCH] Optimize router prompt. --- BotSharp.sln | 11 --- .../Functions/Models/FunctionCallFromLlm.cs | 3 +- .../Routing/IRouterInstance.cs | 1 - .../Routing/Models/RoutingArgs.cs | 2 + .../Agents/Services/AgentService.LoadAgent.cs | 3 + .../Services/ConversationStateService.cs | 4 +- .../Handlers/ConversationEndRoutingHandler.cs | 7 ++ .../HumanInterventionNeededHandler.cs | 7 ++ .../Handlers/ResponseToUserRoutingHandler.cs | 8 +- .../Handlers/RouteToAgentRoutingHandler.cs | 3 + .../Routing/Hooks/RoutingAgentHook.cs | 3 - .../BotSharp.Core/Routing/RouterInstance.cs | 9 --- .../RoutingService.GetNextInstruction.cs | 9 ++- .../BotSharp.Core/Routing/RoutingService.cs | 3 +- .../Templating/ResponseTemplateService.cs | 1 - .../Templating/TemplateRender.cs | 1 + .../Providers/ChatCompletionProvider.cs | 32 ++++---- .../instruction.liquid | 31 ++++---- .../templates/next_step_prompt.liquid | 21 +----- .../instruction.liquid | 2 +- .../agent.json | 1 + .../BotSharp.TestingConsole.csproj | 20 ----- .../IBotSharpOpenAPI.cs | 17 ----- tests/BotSharp.TestingConsole/Program.cs | 74 ------------------- 24 files changed, 79 insertions(+), 194 deletions(-) delete mode 100644 tests/BotSharp.TestingConsole/BotSharp.TestingConsole.csproj delete mode 100644 tests/BotSharp.TestingConsole/IBotSharpOpenAPI.cs delete mode 100644 tests/BotSharp.TestingConsole/Program.cs diff --git a/BotSharp.sln b/BotSharp.sln index 6313d06a..d0a61d4d 100644 --- a/BotSharp.sln +++ b/BotSharp.sln @@ -63,8 +63,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.MongoStorag EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.GoogleAI", "src\Plugins\BotSharp.Plugin.GoogleAI\BotSharp.Plugin.GoogleAI.csproj", "{8BC29F8A-78D6-422C-B522-10687ADC38ED}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.TestingConsole", "tests\BotSharp.TestingConsole\BotSharp.TestingConsole.csproj", "{5E7EC98F-4A22-4D62-8FF6-746C497CF955}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -225,14 +223,6 @@ Global {8BC29F8A-78D6-422C-B522-10687ADC38ED}.Release|Any CPU.Build.0 = Release|Any CPU {8BC29F8A-78D6-422C-B522-10687ADC38ED}.Release|x64.ActiveCfg = Release|Any CPU {8BC29F8A-78D6-422C-B522-10687ADC38ED}.Release|x64.Build.0 = Release|Any CPU - {5E7EC98F-4A22-4D62-8FF6-746C497CF955}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5E7EC98F-4A22-4D62-8FF6-746C497CF955}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5E7EC98F-4A22-4D62-8FF6-746C497CF955}.Debug|x64.ActiveCfg = Debug|Any CPU - {5E7EC98F-4A22-4D62-8FF6-746C497CF955}.Debug|x64.Build.0 = Debug|Any CPU - {5E7EC98F-4A22-4D62-8FF6-746C497CF955}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5E7EC98F-4A22-4D62-8FF6-746C497CF955}.Release|Any CPU.Build.0 = Release|Any CPU - {5E7EC98F-4A22-4D62-8FF6-746C497CF955}.Release|x64.ActiveCfg = Release|Any CPU - {5E7EC98F-4A22-4D62-8FF6-746C497CF955}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -264,7 +254,6 @@ Global {5CD330E1-9E5A-4112-8346-6E31CA98EF78} = {2635EC9B-2E5F-4313-AC21-0B847F31F36C} {DB3DE37B-1208-4ED3-9615-A52AD0AAD69C} = {5CD330E1-9E5A-4112-8346-6E31CA98EF78} {8BC29F8A-78D6-422C-B522-10687ADC38ED} = {D5293208-2BEF-42FC-A64C-5954F61720BA} - {5E7EC98F-4A22-4D62-8FF6-746C497CF955} = {32FAFFFE-A4CB-4FEE-BF7C-84518BBC6DCC} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19} diff --git a/src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionCallFromLlm.cs b/src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionCallFromLlm.cs index bb28514e..7ea31a47 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionCallFromLlm.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Functions/Models/FunctionCallFromLlm.cs @@ -9,7 +9,8 @@ public class FunctionCallFromLlm : RoutingArgs public string? Question { get; set; } [JsonPropertyName("args")] - public JsonDocument Arguments { get; set; } = JsonDocument.Parse("{}"); + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public JsonDocument? Arguments { get; set; } public override string ToString() { diff --git a/src/Infrastructure/BotSharp.Abstraction/Routing/IRouterInstance.cs b/src/Infrastructure/BotSharp.Abstraction/Routing/IRouterInstance.cs index e6734844..4e51e18a 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Routing/IRouterInstance.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Routing/IRouterInstance.cs @@ -9,6 +9,5 @@ public interface IRouterInstance RoutingItem[] GetRoutingItems(); List GetHandlers(); IRouterInstance Load(); - IRouterInstance WithDialogs(List dialogs); RoutingRule[] GetRulesByName(string name); } diff --git a/src/Infrastructure/BotSharp.Abstraction/Routing/Models/RoutingArgs.cs b/src/Infrastructure/BotSharp.Abstraction/Routing/Models/RoutingArgs.cs index c9a2bb0f..bca8018e 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Routing/Models/RoutingArgs.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Routing/Models/RoutingArgs.cs @@ -21,12 +21,14 @@ public class RoutingArgs /// Agent for next action based on user latest response /// [JsonPropertyName("next_action_agent")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string AgentName { get; set; } /// /// Agent who can achieve user original goal /// [JsonPropertyName("user_goal_agent")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string OriginalAgent { get; set; } public override string ToString() diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs index d57226ae..f5f54a7e 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs @@ -5,6 +5,9 @@ namespace BotSharp.Core.Agents.Services; public partial class AgentService { +#if !DEBUG + [MemoryCache(10 * 60)] +#endif public async Task LoadAgent(string id) { var hooks = _services.GetServices(); diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs index a03e35ec..30754faf 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs @@ -41,7 +41,7 @@ public class ConversationStateService : IConversationStateService, IDisposable if (!_states.ContainsKey(name) || _states[name] != currentValue) { _states[name] = currentValue; - _logger.LogInformation($"Set state: {name} = {value}"); + _logger.LogInformation($"[STATE] {name} = {value}"); foreach (var hook in hooks) { hook.OnStateChanged(name, preValue, currentValue).Wait(); @@ -62,7 +62,7 @@ public class ConversationStateService : IConversationStateService, IDisposable foreach (var data in _savedStates) { _states[data.Key] = data.Value; - _logger.LogInformation($"Loaded state: {data.Key}={data.Value}"); + _logger.LogInformation($"[STATE] {data.Key} : {data.Value}"); } } diff --git a/src/Infrastructure/BotSharp.Core/Routing/Handlers/ConversationEndRoutingHandler.cs b/src/Infrastructure/BotSharp.Core/Routing/Handlers/ConversationEndRoutingHandler.cs index 039b90e8..9a54373a 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Handlers/ConversationEndRoutingHandler.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Handlers/ConversationEndRoutingHandler.cs @@ -1,4 +1,5 @@ using BotSharp.Abstraction.Functions.Models; +using BotSharp.Abstraction.Models; using BotSharp.Abstraction.Routing; using BotSharp.Abstraction.Routing.Settings; @@ -12,6 +13,12 @@ public class ConversationEndRoutingHandler : RoutingHandlerBase, IRoutingHandler public bool IsReasoning => false; + public List Parameters => new List + { + new NameDesc("reason", "why end conversation"), + new NameDesc("response", "response content to user") + }; + public ConversationEndRoutingHandler(IServiceProvider services, ILogger logger, RoutingSettings settings) : base(services, logger, settings) { diff --git a/src/Infrastructure/BotSharp.Core/Routing/Handlers/HumanInterventionNeededHandler.cs b/src/Infrastructure/BotSharp.Core/Routing/Handlers/HumanInterventionNeededHandler.cs index bdd6e302..0b0030bb 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Handlers/HumanInterventionNeededHandler.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Handlers/HumanInterventionNeededHandler.cs @@ -1,4 +1,5 @@ using BotSharp.Abstraction.Functions.Models; +using BotSharp.Abstraction.Models; using BotSharp.Abstraction.Routing; using BotSharp.Abstraction.Routing.Settings; @@ -12,6 +13,12 @@ public class HumanInterventionNeededHandler : RoutingHandlerBase, IRoutingHandle private readonly RoutingSettings _settings; + public List Parameters => new List + { + new NameDesc("reason", "why need customer service representative (human being)"), + new NameDesc("response", "response content to user") + }; + public HumanInterventionNeededHandler(IServiceProvider services, ILogger logger, RoutingSettings settings) : base(services, logger, settings) { diff --git a/src/Infrastructure/BotSharp.Core/Routing/Handlers/ResponseToUserRoutingHandler.cs b/src/Infrastructure/BotSharp.Core/Routing/Handlers/ResponseToUserRoutingHandler.cs index b28e4d47..6c16e69f 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Handlers/ResponseToUserRoutingHandler.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Handlers/ResponseToUserRoutingHandler.cs @@ -9,10 +9,16 @@ public class ResponseToUserRoutingHandler : RoutingHandlerBase, IRoutingHandler { public string Name => "response_to_user"; - public string Description => "You know how to response according to the context without asking specific agent."; + public string Description => "Response according to the context without asking specific agent."; public bool IsReasoning => false; + public List Parameters => new List + { + new NameDesc("reason", "why response to user"), + new NameDesc("response", "response content") + }; + public ResponseToUserRoutingHandler(IServiceProvider services, ILogger logger, RoutingSettings settings) : base(services, logger, settings) { diff --git a/src/Infrastructure/BotSharp.Core/Routing/Handlers/RouteToAgentRoutingHandler.cs b/src/Infrastructure/BotSharp.Core/Routing/Handlers/RouteToAgentRoutingHandler.cs index e85d9192..2ab5a595 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Handlers/RouteToAgentRoutingHandler.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Handlers/RouteToAgentRoutingHandler.cs @@ -15,6 +15,9 @@ public class RouteToAgentRoutingHandler : RoutingHandlerBase, IRoutingHandler public List Parameters => new List { + new NameDesc("reason", "why route to agent"), + new NameDesc("next_action_agent", "agent for next action based on user latest response"), + new NameDesc("user_goal_agent", "agent who can achieve user original goal"), new NameDesc("args", "useful parameters of next action agent") }; diff --git a/src/Infrastructure/BotSharp.Core/Routing/Hooks/RoutingAgentHook.cs b/src/Infrastructure/BotSharp.Core/Routing/Hooks/RoutingAgentHook.cs index 8d0de63d..cf802720 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/Hooks/RoutingAgentHook.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/Hooks/RoutingAgentHook.cs @@ -1,8 +1,5 @@ using BotSharp.Abstraction.Functions.Models; -using BotSharp.Abstraction.Models; -using BotSharp.Abstraction.Repositories; using BotSharp.Abstraction.Routing; -using BotSharp.Abstraction.Routing.Models; namespace BotSharp.Core.Routing.Hooks; diff --git a/src/Infrastructure/BotSharp.Core/Routing/RouterInstance.cs b/src/Infrastructure/BotSharp.Core/Routing/RouterInstance.cs index fb5d2039..5eb4e306 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RouterInstance.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RouterInstance.cs @@ -33,15 +33,6 @@ public class RouterInstance : IRouterInstance return this; } - public IRouterInstance WithDialogs(List dialogs) - { - foreach (var dialog in dialogs.TakeLast(20)) - { - _router.Instruction += $"\r\n{dialog.Role}: {dialog.Content}"; - } - return this; - } - public List GetHandlers() { return _services.GetServices() diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetNextInstruction.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetNextInstruction.cs index e628bb46..7304f5fe 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetNextInstruction.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetNextInstruction.cs @@ -61,6 +61,13 @@ public partial class RoutingService { try { + var conversation = ""; + foreach (var dialog in _dialogs.TakeLast(20)) + { + conversation += $"{dialog.Role}: {dialog.Content}\r\n"; + } + content = $"{conversation}\r\n###\r\n{content}"; + response = completion.GetChatCompletions(_routerInstance.Router, new List { new RoleDialogModel(AgentRole.User, content) @@ -107,7 +114,7 @@ public partial class RoutingService } #if !DEBUG - [MemoryCache(60 * 60)] + [MemoryCache(10 * 60)] #endif private string GetNextStepPrompt() { diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs index e10239a8..cb0e5246 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs @@ -63,7 +63,7 @@ public partial class RoutingService : IRoutingService public async Task InstructLoop() { - _routerInstance.Load().WithDialogs(Dialogs); + _routerInstance.Load(); var router = _routerInstance.Router; var result = new RoleDialogModel(AgentRole.Assistant, "Can you repeat your request again?") @@ -97,7 +97,6 @@ public partial class RoutingService : IRoutingService result = await handler.Handle(this, inst); message = result.Content.Replace("\r\n", " "); - router.Instruction += $"\r\n{result.Role}: {message}"; stop = !_settings.EnableReasoning; } diff --git a/src/Infrastructure/BotSharp.Core/Templating/ResponseTemplateService.cs b/src/Infrastructure/BotSharp.Core/Templating/ResponseTemplateService.cs index 9adce256..07d70fd9 100644 --- a/src/Infrastructure/BotSharp.Core/Templating/ResponseTemplateService.cs +++ b/src/Infrastructure/BotSharp.Core/Templating/ResponseTemplateService.cs @@ -1,7 +1,6 @@ using BotSharp.Abstraction.Repositories; using BotSharp.Abstraction.Routing.Models; using BotSharp.Abstraction.Templating; -using System.IO; using System.Reflection; namespace BotSharp.Core.Templating; diff --git a/src/Infrastructure/BotSharp.Core/Templating/TemplateRender.cs b/src/Infrastructure/BotSharp.Core/Templating/TemplateRender.cs index f03df0a1..06d6e9db 100644 --- a/src/Infrastructure/BotSharp.Core/Templating/TemplateRender.cs +++ b/src/Infrastructure/BotSharp.Core/Templating/TemplateRender.cs @@ -21,6 +21,7 @@ public class TemplateRender : ITemplateRender _options.MemberAccessStrategy.MemberNameStrategy = MemberNameStrategies.SnakeCase; _options.MemberAccessStrategy.Register(); + _options.MemberAccessStrategy.Register(); _options.MemberAccessStrategy.Register(); _options.MemberAccessStrategy.Register(); _options.MemberAccessStrategy.Register(); diff --git a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs index 450d5095..98fba046 100644 --- a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs +++ b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ChatCompletionProvider.cs @@ -248,23 +248,27 @@ public class ChatCompletionProvider : IChatCompletion var convSetting = _services.GetRequiredService(); if (convSetting.ShowVerboseLog) { - _logger.LogInformation("VERBOSE COMPLETION MESSAGES"); - var verbose = string.Join("\r\n", chatCompletionsOptions.Messages.Select(x => + if (chatCompletionsOptions.Messages.Count > 0) { - return x.Role == ChatRole.Function ? - $"{x.Role}: {x.Name} => {x.Content}" : - $"{x.Role}: {x.Content}"; - })); + _logger.LogInformation("VERBOSE COMPLETION MESSAGES"); + var verbose = string.Join("\r\n", chatCompletionsOptions.Messages.Select(x => + { + return x.Role == ChatRole.Function ? + $"{x.Role}: {x.Name} => {x.Content}" : + $"{x.Role}: {x.Content}"; + })); + _logger.LogInformation(verbose); + } - _logger.LogInformation(verbose); - - _logger.LogInformation("VERBOSE FUNCTIONS"); - verbose = string.Join("\r\n", chatCompletionsOptions.Functions.Select(x => + if (chatCompletionsOptions.Functions.Count > 0) { - return $"{x.Name}: {x.Description}\r\n{x.Parameters}"; - })); - - _logger.LogInformation(verbose); + _logger.LogInformation("VERBOSE FUNCTIONS"); + var verbose = string.Join("\r\n", chatCompletionsOptions.Functions.Select(x => + { + return $"{x.Name}: {x.Description}\r\n{x.Parameters}"; + })); + _logger.LogInformation(verbose); + } } return chatCompletionsOptions; diff --git a/src/WebStarter/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/instruction.liquid b/src/WebStarter/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/instruction.liquid index 949877c8..5989c175 100644 --- a/src/WebStarter/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/instruction.liquid +++ b/src/WebStarter/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/instruction.liquid @@ -1,31 +1,30 @@ You're {{router.name}} ({{router.description}}). Follow these steps to handle user request: -1. Read the CONVERSATION context. -2. Select a appropriate function from FUNCTIONS. -3. Determine which agent is suitable according to CONVERSATION context. -4. Re-think about selected function is from FUNCTIONS to handle the request. +1. Read the [CONVERSATION] content. +2. Select a appropriate function from [FUNCTIONS]. +3. Determine which agent is suitable to handle this conversation. +4. Re-think about the selected function or agent is the best choice. -FUNCTIONS +[FUNCTIONS] {% for handler in routing_handlers %} -# {{ handler.name }} -{{ handler.description}} +# {{ handler.description}} {% if handler.parameters and handler.parameters != empty -%} -Parameters: +Response: { "function": "{{ handler.name }}", {% for p in handler.parameters -%} - {{ p.name }}: {{ p.description }}{{ "\r\n " }} - {%- endfor %} + "{{ p.name }}": "{{ p.description }}"{{ ",\r\n " }} + {%- endfor %}} {%- endif %} {% endfor %} -AGENTS +[AGENTS] {% for agent in routing_agents %} -* {{ agent.name }} +* Agent: {{ agent.name }} {{ agent.description}} {% if agent.required_fields and agent.required_fields != empty -%} -Required: +Required args: { {% for f in agent.required_fields -%} - {{ f.name }}: {{ f.description }}{{ "\r\n " }} - {%- endfor %} + "{{ f.name }}": "{{ f.description }}"{{ ",\r\n " }} + {%- endfor %}} {%- endif %} {% endfor %} -CONVERSATION \ No newline at end of file +[CONVERSATION] diff --git a/src/WebStarter/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/next_step_prompt.liquid b/src/WebStarter/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/next_step_prompt.liquid index 799c5674..24132c96 100644 --- a/src/WebStarter/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/next_step_prompt.liquid +++ b/src/WebStarter/data/agents/01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a/templates/next_step_prompt.liquid @@ -1,20 +1 @@ -What is the next step based on the CONVERSATION? Or you can handle without asking specific agent. - -Response must be in JSON format -{% if enabled_reasoning %} -{ - "function":"route_to_agent" -} -{% else %} -{ - "function":"route_to_agent", - "reason":"the reason why you select this function or agent", - "response":"content of replying to user", - "next_action_agent":"agent for next action based on user latest response", - "user_goal_agent":"agent who can achieve user original goal", - "args": {} -} -{% endif %} - -If the user has no other tasks need help with, set function as conversation_end with reason and reply user courteously. -If the user wants to reach out to customer service representative (human being), set function as human_intervention_needed with reason and reply user courteously. \ No newline at end of file +What is the next step based on the CONVERSATION? Response must be in appropriate JSON format. \ No newline at end of file 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 index 19250653..73b33cc3 100644 --- a/src/WebStarter/data/agents/c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd/instruction.liquid +++ b/src/WebStarter/data/agents/c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd/instruction.liquid @@ -7,4 +7,4 @@ Follow below step to place order: 4: Ask user how to pay for this order. 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 +* Today is {{current_date}}, the time now is {{current_time}}, day of week is {{current_weekday}}. diff --git a/src/WebStarter/data/agents/fe8c60aa-b114-4ef3-93cb-a8efeac80f75/agent.json b/src/WebStarter/data/agents/fe8c60aa-b114-4ef3-93cb-a8efeac80f75/agent.json index a69b758e..22eaa329 100644 --- a/src/WebStarter/data/agents/fe8c60aa-b114-4ef3-93cb-a8efeac80f75/agent.json +++ b/src/WebStarter/data/agents/fe8c60aa-b114-4ef3-93cb-a8efeac80f75/agent.json @@ -8,6 +8,7 @@ "routingRules": [ { "field": "order_number", + "description": "order number", "required": true, "redirectTo": "c2b57a74-ae4e-4c81-b3ad-9ac5bff982bd" } diff --git a/tests/BotSharp.TestingConsole/BotSharp.TestingConsole.csproj b/tests/BotSharp.TestingConsole/BotSharp.TestingConsole.csproj deleted file mode 100644 index 35c76b3d..00000000 --- a/tests/BotSharp.TestingConsole/BotSharp.TestingConsole.csproj +++ /dev/null @@ -1,20 +0,0 @@ - - - - Exe - net6.0 - enable - enable - False - - - - - - - - - - - - diff --git a/tests/BotSharp.TestingConsole/IBotSharpOpenAPI.cs b/tests/BotSharp.TestingConsole/IBotSharpOpenAPI.cs deleted file mode 100644 index 6844099f..00000000 --- a/tests/BotSharp.TestingConsole/IBotSharpOpenAPI.cs +++ /dev/null @@ -1,17 +0,0 @@ -using BotSharp.Abstraction.Conversations.Models; -using BotSharp.OpenAPI.ViewModels.Conversations; -using Refit; - -namespace BotSharp.TestingConsole; - -public interface IBotSharpOpenAPI -{ - [Post("/conversation/{agentId}")] - Task NewConversation([Header("Authorization")] string authorization, string agentId); - - [Post("/conversation/{agentId}/{conversationId}")] - Task SendMessage([Header("Authorization")] string authorization, string agentId, string conversationId, [Body] NewMessageModel input); - - [Post("/instruct/text-completion")] - Task TextCompletion([Header("Authorization")] string authorization, [Body] IncomingMessageModel message); -} diff --git a/tests/BotSharp.TestingConsole/Program.cs b/tests/BotSharp.TestingConsole/Program.cs deleted file mode 100644 index 675198fd..00000000 --- a/tests/BotSharp.TestingConsole/Program.cs +++ /dev/null @@ -1,74 +0,0 @@ -// See https://aka.ms/new-console-template for more information -using BotSharp.Abstraction.Agents.Enums; -using BotSharp.Abstraction.Conversations.Models; -using BotSharp.OpenAPI.ViewModels.Conversations; -using BotSharp.TestingConsole; -using Refit; -using System.Drawing; -using Console = Colorful.Console; - -var token = "Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiI0NTZlMzVjNS1jYWYwLTRkNDUtOTA4NC1iNDRhOGNhNzE3ZTQiLCJlbWFpbCI6ImJvdHNoYXJwQGdtYWlsLmNvbSIsImdpdmVuX25hbWUiOiJIYWlwaW5nIiwiZmFtaWx5X25hbWUiOiJDaGVuIiwianRpIjoiMTQ3MDkwMDQtNDM1Ny00NTFkLWExM2MtY2U1NDk5NWM0ZTJlIiwibmJmIjoxNjk3MTY0MzA4LCJleHAiOjE2OTcxNjQ2MDgsImlhdCI6MTY5NzE2NDMwOCwiaXNzIjoiYm90c2hhcnAiLCJhdWQiOiJib3RzaGFycCJ9.1UgOj5esNInTPiiy-_gLmcT2x8NtFswCUyePVHXa-4EeLCkA43nx0LOXPlzb_rmvUIg9bJSRZXbH2aBqtmiDYg"; -var agentId = "01fcc3e5-9af7-49e6-ad7a-a760bd12dc4a"; - -// New conversation -var botsharp = RestService.For("http://localhost:5500"); -var conv = await botsharp.NewConversation(token, agentId); - -var instruction = @"You're a customer who is going to buy a pizza. - -Below are your requirments: -* You want to know what kind of pizza do they have. -* You want to buy three piece of pizza. -* Say Bye if the order is placed and payment is completed. - -Below are your profile: -* You like pepperoni flavor. -* You will pay the order in cash. -* Your address is 347 S Gladstone Ave, Aurora, IL 60506. -* Your phone number is +16308926431"; - -Action PrintDialog = message => -{ - Console.Write($"[{DateTime.Now:HH:mm:ss}] {message.Role}:\t"); - if (message.Role == AgentRole.User) - { - Console.WriteLine(message.Content); - } - else - { - Console.WriteLine(message.Content, Color.Yellow); - } -}; - -var dialogs = new List(); -dialogs.Add(new RoleDialogModel(AgentRole.User, "Good morning!")); -PrintDialog(dialogs.Last()); -dialogs.Add(new RoleDialogModel(AgentRole.Assistant, "Hi, How can I help you today?")); -PrintDialog(dialogs.Last()); - -var response = new MessageResponseModel(); - -while (response.Function != "conversation_end") -{ - var text = string.Join("\r\n", dialogs.Select(x => $"{x.Role}: {x.Content}")); - text = instruction + $"\r\n###\r\n{text}\r\n{AgentRole.User}: "; - var question = await botsharp.TextCompletion(token, new IncomingMessageModel - { - Text = text - }); - - dialogs.Add(new RoleDialogModel(AgentRole.User, question)); - PrintDialog(dialogs.Last()); - - response = await botsharp.SendMessage(token, agentId, conv.Id, new NewMessageModel - { - Text = question - }); - - dialogs.Add(new RoleDialogModel(AgentRole.Assistant, response.Text.Trim())); - PrintDialog(dialogs.Last()); -} - -Console.WriteLine(); -Console.WriteLine("Conversation End", Color.Green); -Console.ReadLine(); \ No newline at end of file