Merge pull request #193 from hchen2020/master

PerInstanceCache = true
This commit is contained in:
Haiping 2023-10-26 13:54:55 -05:00 committed by GitHub
commit e28b8a70a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 13 deletions

View file

@ -1,3 +1,4 @@
using System.Text.Json;
using System.Text.RegularExpressions;
namespace BotSharp.Abstraction.Utilities;
@ -27,4 +28,16 @@ public static class StringExtensions
{
return str1.Equals(str2, option);
}
public static string JsonContent(this string text)
{
var m = Regex.Match(text, @"\{(?:[^{}]|(?<open>\{)|(?<-open>\}))+(?(open)(?!))\}");
return m.Success ? m.Value : "{}";
}
public static T? JsonContent<T>(this string text)
{
text = JsonContent(text);
return JsonSerializer.Deserialize<T>(text);
}
}

View file

@ -4,18 +4,14 @@ namespace BotSharp.Core.Agents.Services;
public partial class AgentService
{
#if !DEBUG
[MemoryCache(10 * 60)]
#endif
[MemoryCache(10 * 60, PerInstanceCache = true)]
public async Task<List<Agent>> GetAgents(bool? allowRouting = null)
{
var agents = _db.GetAgents(allowRouting: allowRouting);
return await Task.FromResult(agents);
}
#if !DEBUG
[MemoryCache(10 * 60)]
#endif
[MemoryCache(10 * 60, PerInstanceCache = true)]
public async Task<Agent> GetAgent(string id)
{
var profile = _db.GetAgent(id);

View file

@ -486,9 +486,6 @@ public class FileRepository : IBotSharpRepository
return responses;
}
#if !DEBUG
[MemoryCache(10 * 60)]
#endif
public Agent? GetAgent(string agentId)
{
var agentDir = Path.Combine(_dbSettings.FileRepository, _agentSettings.DataDir);

View file

@ -82,9 +82,7 @@ public partial class RoutingService
new RoleDialogModel(AgentRole.User, content)
});
var pattern = @"\{(?:[^{}]|(?<open>\{)|(?<-open>\}))+(?(open)(?!))\}";
response.Content = Regex.Match(response.Content, pattern).Value;
args = JsonSerializer.Deserialize<FunctionCallFromLlm>(response.Content);
args = response.Content.JsonContent<FunctionCallFromLlm>();
break;
}
catch (Exception ex)

View file

@ -1 +1 @@
What is the next step based on the CONVERSATION? Response must be in appropriate JSON format. Route to the latest agent as much as possible.
What is the next step based on the CONVERSATION? Response must be in appropriate JSON format.