Merge branch 'SciSharp:master' into master

This commit is contained in:
hchen2020 2025-02-12 09:08:47 -06:00 committed by GitHub
commit 6894349b63
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 744 additions and 741 deletions

View file

@ -71,5 +71,5 @@ public interface IConversationService
/// <param name="convLimit">conversation limit</param>
/// <param name="preLoad">if pre-loading, then keys are not filter by the search query</param>
/// <returns></returns>
Task<List<string>> GetConversationSearhKeys(string query, int convlimit = 100, int keyLimit = 10, bool preLoad = false);
Task<List<string>> GetConversationStateSearhKeys(string query, int convlimit = 100, int keyLimit = 10, bool preLoad = false);
}

View file

@ -148,7 +148,7 @@ public interface IBotSharpRepository : IHaveServiceProvider
=> throw new NotImplementedException();
List<string> TruncateConversation(string conversationId, string messageId, bool cleanLog = false)
=> throw new NotImplementedException();
List<string> GetConversationSearchKeys(int messageLimit = 2, int convlimit = 100)
List<string> GetConversationStateSearchKeys(int messageLowerLimit = 2, int convUpperlimit = 100)
=> throw new NotImplementedException();
#endregion

View file

@ -222,7 +222,7 @@ public partial class ConversationService : IConversationService
_state.Save();
}
public async Task<List<string>> GetConversationSearhKeys(string query, int convlimit = 100, int keyLimit = 10, bool preLoad = false)
public async Task<List<string>> GetConversationStateSearhKeys(string query, int convlimit = 100, int keyLimit = 10, bool preLoad = false)
{
var keys = new List<string>();
if (!preLoad && string.IsNullOrWhiteSpace(query))
@ -231,7 +231,7 @@ public partial class ConversationService : IConversationService
}
var db = _services.GetRequiredService<IBotSharpRepository>();
keys = db.GetConversationSearchKeys(convlimit: convlimit);
keys = db.GetConversationStateSearchKeys(convUpperlimit: convlimit);
keys = preLoad ? keys : keys.Where(x => x.Contains(query, StringComparison.OrdinalIgnoreCase)).ToList();
return keys.OrderBy(x => x).Take(keyLimit).ToList();
}

View file

@ -558,7 +558,7 @@ public class ConversationController : ControllerBase
public async Task<List<string>> GetConversationStateKeys([FromQuery] string query, [FromQuery] int keyLimit = 10, [FromQuery] bool preLoad = false)
{
var convService = _services.GetRequiredService<IConversationService>();
var keys = await convService.GetConversationSearhKeys(query, keyLimit: keyLimit, preLoad: preLoad);
var keys = await convService.GetConversationStateSearhKeys(query, keyLimit: keyLimit, preLoad: preLoad);
return keys;
}
#endregion

View file

@ -611,13 +611,15 @@ public partial class MongoRepository
return deletedMessageIds;
}
public List<string> GetConversationSearchKeys(int messageLimit = 2, int convlimit = 100)
#if !DEBUG
[SharpCache(10)]
#endif
public List<string> GetConversationStateSearchKeys(int messageLowerLimit = 2, int convUpperlimit = 100)
{
var convFilter = Builders<ConversationDocument>.Filter.Gte(x => x.DialogCount, messageLimit);
var convFilter = Builders<ConversationDocument>.Filter.Gte(x => x.DialogCount, messageLowerLimit);
var conversations = _dc.Conversations.Find(convFilter)
.SortByDescending(x => x.UpdatedTime)
.Limit(convlimit)
.Limit(convUpperlimit)
.ToList();
if (conversations.IsNullOrEmpty()) return [];