JsonContent<T>
This commit is contained in:
parent
012158470f
commit
2cd3dfcd29
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System.Text.Json;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace BotSharp.Abstraction.Utilities;
|
namespace BotSharp.Abstraction.Utilities;
|
||||||
|
|
@ -27,4 +28,16 @@ public static class StringExtensions
|
||||||
{
|
{
|
||||||
return str1.Equals(str2, option);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,9 +82,7 @@ public partial class RoutingService
|
||||||
new RoleDialogModel(AgentRole.User, content)
|
new RoleDialogModel(AgentRole.User, content)
|
||||||
});
|
});
|
||||||
|
|
||||||
var pattern = @"\{(?:[^{}]|(?<open>\{)|(?<-open>\}))+(?(open)(?!))\}";
|
args = response.Content.JsonContent<FunctionCallFromLlm>();
|
||||||
response.Content = Regex.Match(response.Content, pattern).Value;
|
|
||||||
args = JsonSerializer.Deserialize<FunctionCallFromLlm>(response.Content);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
Loading…
Reference in a new issue