diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs index 4d3a77795..715bfde57 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs @@ -41,7 +41,7 @@ public virtual bool OnFunctionsLoaded(List functions) return true; } - public virtual bool OnSamplesLoaded(ref string samples) + public virtual bool OnSamplesLoaded(List samples) { _agent.Samples = samples; return true; diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentHook.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentHook.cs index 047a0b03d..f7b7379b7 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentHook.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentHook.cs @@ -19,7 +19,7 @@ public interface IAgentHook bool OnFunctionsLoaded(List functions); - bool OnSamplesLoaded(ref string samples); + bool OnSamplesLoaded(List samples); /// /// Triggered when agent is loaded completely. diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs index ef2646592..427105208 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs @@ -27,7 +27,7 @@ public class Agent /// Samples /// [JsonIgnore] - public string Samples { get; set; } + public List Samples { get; set; } /// /// Functions @@ -109,6 +109,12 @@ public Agent SetFunctions(List functions) return this; } + public Agent SetSamples(List samples) + { + Samples = samples ?? new List(); + return this; + } + public Agent SetResponses(List responses) { Responses = responses ?? new List(); ; diff --git a/src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingService.cs b/src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingService.cs index 0881b1d3a..8b4ebaf95 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Routing/IRoutingService.cs @@ -5,6 +5,7 @@ namespace BotSharp.Abstraction.Routing; public interface IRoutingService { List Dialogs { get; } + void RefreshDialogs(); Task GetNextInstruction(); Task InvokeAgent(string agentId); Task InstructLoop(); diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs index 47cfcd2b8..f5f54a7eb 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs @@ -42,10 +42,9 @@ public async Task LoadAgent(string id) hook.OnFunctionsLoaded(agent.Functions); } - if (!string.IsNullOrEmpty(agent.Samples)) + if (agent.Samples != null) { - var samples = agent.Samples; - hook.OnSamplesLoaded(ref samples); + hook.OnSamplesLoaded(agent.Samples); } hook.OnAgentLoaded(agent); diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs index da44f034e..58f71bd0a 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs @@ -56,6 +56,8 @@ await routing.InstructLoop() : var statistics = _services.GetRequiredService(); statistics.PrintStatistics(); + routing.RefreshDialogs(); + return true; } diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs index 623283436..b585b7646 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs @@ -519,10 +519,12 @@ public List GetAgentResponses(string agentId, string prefix, string inte var instruction = FetchInstruction(dir); var functions = FetchFunctions(dir); + var samples = FetchSamples(dir); var templates = FetchTemplates(dir); var responses = FetchResponses(dir); return record.SetInstruction(instruction) .SetFunctions(functions) + .SetSamples(samples) .SetTemplates(templates) .SetResponses(responses); } @@ -771,6 +773,14 @@ private List FetchFunctions(string fileDir) return functions; } + private List FetchSamples(string fileDir) + { + var file = Path.Combine(fileDir, "samples.txt"); + if (!File.Exists(file)) return new List(); + + return File.ReadAllLines(file).ToList(); + } + private List FetchTemplates(string fileDir) { var templates = new List(); diff --git a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs index 5c1b3f1d8..e10239a87 100644 --- a/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs +++ b/src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs @@ -25,6 +25,11 @@ public List Dialogs { } } + public void RefreshDialogs() + { + _dialogs = null; + } + public RoutingService(IServiceProvider services, RoutingSettings settings, ILogger logger, diff --git a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ProviderHelper.cs b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ProviderHelper.cs index b829330f4..dffc196d2 100644 --- a/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ProviderHelper.cs +++ b/src/Plugins/BotSharp.Plugin.AzureOpenAI/Providers/ProviderHelper.cs @@ -23,16 +23,11 @@ public static (OpenAIClient, string) GetClient(string model, AzureOpenAiSettings } } - public static List GetChatSamples(string sampleText) + public static List GetChatSamples(List lines) { var samples = new List(); - if (string.IsNullOrEmpty(sampleText)) - { - return samples; - } - var lines = sampleText.Split('\n'); - for (int i = 0; i < lines.Length; i++) + for (int i = 0; i < lines.Count; i++) { var line = lines[i]; if (string.IsNullOrEmpty(line.Trim()))