Merge branch 'master' of https://github.com/SciSharp/BotSharp into features/add-knowledge-docs
This commit is contained in:
commit
c3e048d1a7
|
|
@ -13,7 +13,7 @@ public interface IConversationService
|
|||
Task<PagedItems<Conversation>> GetConversations(ConversationFilter filter);
|
||||
Task<Conversation> UpdateConversationTitle(string id, string title);
|
||||
Task<List<Conversation>> GetLastConversations();
|
||||
Task<List<string>> GetIdleConversations(int batchSize, int messageLimit, int bufferHours);
|
||||
Task<List<string>> GetIdleConversations(int batchSize, int messageLimit, int bufferHours, IEnumerable<string> excludeAgentIds);
|
||||
Task<bool> DeleteConversations(IEnumerable<string> ids);
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ public class ConversationSetting
|
|||
public bool EnableContentLog { get; set; }
|
||||
public bool EnableStateLog { get; set; }
|
||||
public bool EnableTranslationMemory { get; set; }
|
||||
public CleanConversationSetting CleanSetting { get; set; } = new CleanConversationSetting();
|
||||
public RateLimitSetting RateLimit { get; set; } = new RateLimitSetting();
|
||||
public CleanConversationSetting CleanSetting { get; set; } = new();
|
||||
public RateLimitSetting RateLimit { get; set; } = new();
|
||||
}
|
||||
|
||||
public class CleanConversationSetting
|
||||
|
|
@ -22,5 +22,5 @@ public class CleanConversationSetting
|
|||
public int BatchSize { get; set; }
|
||||
public int MessageLimit { get; set; }
|
||||
public int BufferHours { get; set; }
|
||||
|
||||
public IEnumerable<string> ExcludeAgentIds { get; set; } = new List<string>();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ public interface IBotSharpRepository
|
|||
void UpdateConversationBreakpoint(string conversationId, ConversationBreakpoint breakpoint);
|
||||
ConversationBreakpoint? GetConversationBreakpoint(string conversationId);
|
||||
List<Conversation> GetLastConversations();
|
||||
List<string> GetIdleConversations(int batchSize, int messageLimit, int bufferHours);
|
||||
List<string> GetIdleConversations(int batchSize, int messageLimit, int bufferHours, IEnumerable<string> excludeAgentIds);
|
||||
IEnumerable<string> TruncateConversation(string conversationId, string messageId, bool cleanLog = false);
|
||||
#endregion
|
||||
|
||||
|
|
|
|||
|
|
@ -70,10 +70,10 @@ public partial class ConversationService : IConversationService
|
|||
return db.GetLastConversations();
|
||||
}
|
||||
|
||||
public async Task<List<string>> GetIdleConversations(int batchSize, int messageLimit, int bufferHours)
|
||||
public async Task<List<string>> GetIdleConversations(int batchSize, int messageLimit, int bufferHours, IEnumerable<string> excludeAgentIds)
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
return db.GetIdleConversations(batchSize, messageLimit, bufferHours);
|
||||
return db.GetIdleConversations(batchSize, messageLimit, bufferHours, excludeAgentIds ?? new List<string>());
|
||||
}
|
||||
|
||||
public async Task<Conversation> NewConversation(Conversation sess)
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ public class BotSharpDbContext : Database, IBotSharpRepository
|
|||
public List<Conversation> GetLastConversations()
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public List<string> GetIdleConversations(int batchSize, int messageLimit, int bufferHours)
|
||||
public List<string> GetIdleConversations(int batchSize, int messageLimit, int bufferHours, IEnumerable<string> excludeAgentIds)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public List<DialogElement> GetConversationDialogs(string conversationId)
|
||||
|
|
|
|||
|
|
@ -378,7 +378,7 @@ namespace BotSharp.Core.Repository
|
|||
.ToList();
|
||||
}
|
||||
|
||||
public List<string> GetIdleConversations(int batchSize, int messageLimit, int bufferHours)
|
||||
public List<string> GetIdleConversations(int batchSize, int messageLimit, int bufferHours, IEnumerable<string> excludeAgentIds)
|
||||
{
|
||||
var ids = new List<string>();
|
||||
var batchLimit = 100;
|
||||
|
|
@ -423,7 +423,7 @@ namespace BotSharp.Core.Repository
|
|||
continue;
|
||||
}
|
||||
|
||||
if (conv.UpdatedTime > utcNow.AddHours(-bufferHours))
|
||||
if (excludeAgentIds.Contains(conv.AgentId) || conv.UpdatedTime > utcNow.AddHours(-bufferHours))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ namespace BotSharp.OpenAPI.BackgroundServices
|
|||
if (cleanSetting == null || !cleanSetting.Enable) return;
|
||||
|
||||
var conversationService = scope.ServiceProvider.GetRequiredService<IConversationService>();
|
||||
var conversationIds = await conversationService.GetIdleConversations(cleanSetting.BatchSize, cleanSetting.MessageLimit, cleanSetting.BufferHours);
|
||||
var conversationIds = await conversationService.GetIdleConversations(cleanSetting.BatchSize, cleanSetting.MessageLimit, cleanSetting.BufferHours, cleanSetting.ExcludeAgentIds);
|
||||
|
||||
if (!conversationIds.IsNullOrEmpty())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -344,7 +344,7 @@ public partial class MongoRepository
|
|||
}).ToList();
|
||||
}
|
||||
|
||||
public List<string> GetIdleConversations(int batchSize, int messageLimit, int bufferHours)
|
||||
public List<string> GetIdleConversations(int batchSize, int messageLimit, int bufferHours, IEnumerable<string> excludeAgentIds)
|
||||
{
|
||||
var page = 1;
|
||||
var batchLimit = 100;
|
||||
|
|
@ -370,7 +370,7 @@ public partial class MongoRepository
|
|||
{
|
||||
var skip = (page - 1) * batchSize;
|
||||
var candidates = _dc.Conversations.AsQueryable()
|
||||
.Where(x => x.DialogCount <= messageLimit && x.UpdatedTime <= utcNow.AddHours(-bufferHours))
|
||||
.Where(x => !excludeAgentIds.Contains(x.AgentId) && x.DialogCount <= messageLimit && x.UpdatedTime <= utcNow.AddHours(-bufferHours))
|
||||
.Skip(skip)
|
||||
.Take(batchSize)
|
||||
.Select(x => x.Id)
|
||||
|
|
|
|||
Loading…
Reference in a new issue