use list extension

This commit is contained in:
Jicheng Lu 2023-09-03 17:58:07 -05:00
parent b5c90c02bc
commit f381208498
6 changed files with 8 additions and 8 deletions

View file

@ -2,7 +2,7 @@ namespace BotSharp.Abstraction.Utilities;
public static class ListExtenstion
{
public static bool IsEmpty(this IEnumerable<string> strList)
public static bool IsEmpty<T>(this IEnumerable<T> strList)
{
return strList == null || !strList.Any();
}

View file

@ -30,7 +30,7 @@ public partial class AgentService
hook.OnInstructionLoaded(agent.Instruction, templateDict);
}
if (agent.Functions != null && agent.Functions.Any())
if (!agent.Functions.IsEmpty())
{
var functions = agent.Functions;
hook.OnFunctionsLoaded(ref functions);

View file

@ -27,10 +27,10 @@ public partial class AgentService
if (!string.IsNullOrEmpty(agent.Instruction))
record.Instruction = agent.Instruction;
if (agent.Functions != null && agent.Functions.Any())
if (!agent.Functions.IsEmpty())
record.Functions = agent.Functions;
if (agent.Responses != null && agent.Responses.Any())
if (!agent.Responses.IsEmpty())
record.Responses = agent.Responses;
db.UpdateAgent(record);

View file

@ -311,7 +311,7 @@ public class FileRepository : IBotSharpRepository
File.WriteAllText(instructionFile, agent.Instruction);
}
if (agent.Functions != null || agent.Functions.Any())
if (!agent.Functions.IsEmpty())
{
var functionFile = Path.Combine(dir, "functions.json");
var functions = new List<string>();

View file

@ -36,7 +36,7 @@ public class Router : IAgentRouting
var records = db.RoutingItem.Select(x => x.ToRoutingItem()).ToArray();
var profiles = db.RoutingProfile.ToList();
if (profiles != null && profiles.Any())
if (!profiles.IsEmpty())
{
var state = _services.GetRequiredService<IConversationStateService>();
var name = state.GetState("channel");

View file

@ -43,10 +43,10 @@ public class AgentUpdateModel
if (Samples != null)
agent.Samples = Samples;
if (Functions != null && Functions.Any())
if (!Functions.IsEmpty())
agent.Functions = Functions;
if (Responses != null && Responses.Any())
if (!Responses.IsEmpty())
agent.Responses = Responses;
return agent;