Skip to content

Commit e28b8a7

Browse files
authored
Merge pull request #193 from hchen2020/master
PerInstanceCache = true
2 parents 2a52e30 + 2cd3dfc commit e28b8a7

5 files changed

Lines changed: 17 additions & 13 deletions

File tree

src/Infrastructure/BotSharp.Abstraction/Utilities/StringExtensions.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Text.Json;
12
using System.Text.RegularExpressions;
23

34
namespace BotSharp.Abstraction.Utilities;
@@ -27,4 +28,16 @@ public static bool IsEqualTo(this string str1, string str2, StringComparison opt
2728
{
2829
return str1.Equals(str2, option);
2930
}
31+
32+
public static string JsonContent(this string text)
33+
{
34+
var m = Regex.Match(text, @"\{(?:[^{}]|(?<open>\{)|(?<-open>\}))+(?(open)(?!))\}");
35+
return m.Success ? m.Value : "{}";
36+
}
37+
38+
public static T? JsonContent<T>(this string text)
39+
{
40+
text = JsonContent(text);
41+
return JsonSerializer.Deserialize<T>(text);
42+
}
3043
}

src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.GetAgents.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,14 @@ namespace BotSharp.Core.Agents.Services;
44

55
public partial class AgentService
66
{
7-
#if !DEBUG
8-
[MemoryCache(10 * 60)]
9-
#endif
7+
[MemoryCache(10 * 60, PerInstanceCache = true)]
108
public async Task<List<Agent>> GetAgents(bool? allowRouting = null)
119
{
1210
var agents = _db.GetAgents(allowRouting: allowRouting);
1311
return await Task.FromResult(agents);
1412
}
1513

16-
#if !DEBUG
17-
[MemoryCache(10 * 60)]
18-
#endif
14+
[MemoryCache(10 * 60, PerInstanceCache = true)]
1915
public async Task<Agent> GetAgent(string id)
2016
{
2117
var profile = _db.GetAgent(id);

src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,6 @@ public List<string> GetAgentResponses(string agentId, string prefix, string inte
486486
return responses;
487487
}
488488

489-
#if !DEBUG
490-
[MemoryCache(10 * 60)]
491-
#endif
492489
public Agent? GetAgent(string agentId)
493490
{
494491
var agentDir = Path.Combine(_dbSettings.FileRepository, _agentSettings.DataDir);

src/Infrastructure/BotSharp.Core/Routing/RoutingService.GetNextInstruction.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ public async Task<FunctionCallFromLlm> GetNextInstruction()
8282
new RoleDialogModel(AgentRole.User, content)
8383
});
8484

85-
var pattern = @"\{(?:[^{}]|(?<open>\{)|(?<-open>\}))+(?(open)(?!))\}";
86-
response.Content = Regex.Match(response.Content, pattern).Value;
87-
args = JsonSerializer.Deserialize<FunctionCallFromLlm>(response.Content);
85+
args = response.Content.JsonContent<FunctionCallFromLlm>();
8886
break;
8987
}
9088
catch (Exception ex)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +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.
1+
What is the next step based on the CONVERSATION? Response must be in appropriate JSON format.

0 commit comments

Comments
 (0)