diff --git a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs index c29d39ab4..bfd2ae8a3 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs @@ -72,6 +72,8 @@ void UpdateAgent(Agent agent, AgentField field) => throw new NotImplementedException(); Agent? GetAgent(string agentId, bool basicsOnly = false) => throw new NotImplementedException(); + Task GetAgentAsync(string agentId, bool basicsOnly = false) + => throw new NotImplementedException(); List GetAgents(AgentFilter filter) => throw new NotImplementedException(); List GetUserAgents(string userId) @@ -114,7 +116,7 @@ bool DeleteAgentTasks(string agentId, List? taskIds = null) #region Agent Code List GetAgentCodeScripts(string agentId, AgentCodeScriptFilter? filter = null) => throw new NotImplementedException(); - AgentCodeScript? GetAgentCodeScript(string agentId, string scriptName, string scriptType = AgentCodeScriptType.Src) + Task GetAgentCodeScript(string agentId, string scriptName, string scriptType = AgentCodeScriptType.Src) => throw new NotImplementedException(); bool UpdateAgentCodeScripts(string agentId, List scripts, AgentCodeScriptDbUpdateOptions? options = null) => throw new NotImplementedException(); @@ -139,7 +141,7 @@ void UpdateConversationStates(string conversationId, List states) => throw new NotImplementedException(); void UpdateConversationStatus(string conversationId, string status) => throw new NotImplementedException(); - Conversation GetConversation(string conversationId, bool isLoadStates = false) + Task GetConversation(string conversationId, bool isLoadStates = false) => throw new NotImplementedException(); ValueTask> GetConversations(ConversationFilter filter) => throw new NotImplementedException(); @@ -231,9 +233,9 @@ bool AddKnowledgeCollectionConfigs(List configs, bool re => throw new NotImplementedException(); bool DeleteKnowledgeCollectionConfig(string collectionName) => throw new NotImplementedException(); - IEnumerable GetKnowledgeCollectionConfigs(VectorCollectionConfigFilter filter) + Task> GetKnowledgeCollectionConfigs(VectorCollectionConfigFilter filter) => throw new NotImplementedException(); - VectorCollectionConfig GetKnowledgeCollectionConfig(string collectionName, string vectorStroageProvider) + Task GetKnowledgeCollectionConfig(string collectionName, string vectorStroageProvider) => throw new NotImplementedException(); bool SaveKnolwedgeBaseFileMeta(KnowledgeDocMetaData metaData) => throw new NotImplementedException(); diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.Coding.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.Coding.cs index ea9d336f0..61749828a 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.Coding.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.Coding.cs @@ -17,8 +17,8 @@ public async Task> GetAgentCodeScripts(string agentId, Age public async Task GetAgentCodeScript(string agentId, string scriptName, string scriptType = AgentCodeScriptType.Src) { var db = _services.GetRequiredService(); - var script = db.GetAgentCodeScript(agentId, scriptName, scriptType); - return await Task.FromResult(script); + var script = await db.GetAgentCodeScript(agentId, scriptName, scriptType); + return script; } public async Task UpdateAgentCodeScripts(string agentId, List codeScripts, AgentCodeScriptUpdateOptions? options = null) diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.GetAgents.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.GetAgents.cs index e3defd95d..6d9ef934c 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.GetAgents.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.GetAgents.cs @@ -50,7 +50,7 @@ public async Task GetAgent(string id) return null; } - var profile = _db.GetAgent(id); + var profile = await _db.GetAgentAsync(id); if (profile == null) { _logger.LogError($"Can't find agent {id}"); diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs index 4a2e1ec51..924077fed 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs @@ -18,7 +18,7 @@ public async Task UpdateAgent(Agent agent, AgentField updateField) return; } - var record = _db.GetAgent(agent.Id); + var record = await _db.GetAgentAsync(agent.Id); if (record == null) return; record.Name = agent.Name ?? string.Empty; @@ -65,7 +65,7 @@ public async Task PatchAgentTemplate(Agent agent) return patchResult; } - var record = _db.GetAgent(agent.Id); + var record = await _db.GetAgentAsync(agent.Id); if (record == null) { patchResult = $"Cannot find agent {agent.Id}"; diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs index 314736db6..cea0ad7f6 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs @@ -45,7 +45,7 @@ public async Task UpdateConversationTitle(string id, string title) { var db = _services.GetRequiredService(); db.UpdateConversationTitle(id, title); - var conversation = db.GetConversation(id); + var conversation = await db.GetConversation(id); return conversation; } @@ -53,7 +53,7 @@ public async Task UpdateConversationTitleAlias(string id, string t { var db = _services.GetRequiredService(); db.UpdateConversationTitleAlias(id, titleAlias); - var conversation = db.GetConversation(id); + var conversation = await db.GetConversation(id); return conversation; } @@ -72,7 +72,7 @@ public async Task UpdateConversationMessage(string conversationId, UpdateM public async Task GetConversation(string id, bool isLoadStates = false) { var db = _services.GetRequiredService(); - var conversation = db.GetConversation(id); + var conversation = await db.GetConversation(id); return conversation; } diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.AgentCodeScript.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.AgentCodeScript.cs index fa4d11a9f..82f40e761 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.AgentCodeScript.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.AgentCodeScript.cs @@ -50,7 +50,7 @@ public List GetAgentCodeScripts(string agentId, AgentCodeScript return results; } - public AgentCodeScript? GetAgentCodeScript(string agentId, string scriptName, string scriptType = AgentCodeScriptType.Src) + public async Task GetAgentCodeScript(string agentId, string scriptName, string scriptType = AgentCodeScriptType.Src) { if (string.IsNullOrWhiteSpace(agentId) || string.IsNullOrWhiteSpace(scriptName) @@ -76,7 +76,7 @@ public List GetAgentCodeScripts(string agentId, AgentCodeScript AgentId = agentId, Name = scriptName, ScriptType = scriptType, - Content = File.ReadAllText(foundFile), + Content = await File.ReadAllTextAsync(foundFile), CreatedTime = File.GetCreationTimeUtc(foundFile), UpdatedTime = File.GetLastWriteTimeUtc(foundFile) }; diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs index 5939cf644..86d80e263 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs @@ -401,7 +401,7 @@ public void UpdateConversationStatus(string conversationId, string status) } } - public Conversation GetConversation(string conversationId, bool isLoadStates = false) + public async Task GetConversation(string conversationId, bool isLoadStates = false) { var convDir = FindConversationDirectory(conversationId); if (string.IsNullOrEmpty(convDir)) @@ -410,7 +410,7 @@ public Conversation GetConversation(string conversationId, bool isLoadStates = f } var convFile = Path.Combine(convDir, CONVERSATION_FILE); - var content = File.ReadAllText(convFile); + var content = await File.ReadAllTextAsync(convFile); var record = JsonSerializer.Deserialize(content, _options); var dialogFile = Path.Combine(convDir, DIALOG_FILE); @@ -424,7 +424,7 @@ public Conversation GetConversation(string conversationId, bool isLoadStates = f var latestStateFile = Path.Combine(convDir, CONV_LATEST_STATE_FILE); if (record != null && File.Exists(latestStateFile)) { - var stateJson = File.ReadAllText(latestStateFile); + var stateJson = await File.ReadAllTextAsync(latestStateFile); var states = JsonSerializer.Deserialize>(stateJson, _options) ?? []; record.States = states.ToDictionary(x => x.Key, x => { diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.KnowledgeBase.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.KnowledgeBase.cs index 73421a0be..55c97438a 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.KnowledgeBase.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.KnowledgeBase.cs @@ -74,7 +74,7 @@ public bool DeleteKnowledgeCollectionConfig(string collectionName) return true; } - public IEnumerable GetKnowledgeCollectionConfigs(VectorCollectionConfigFilter filter) + public async Task> GetKnowledgeCollectionConfigs(VectorCollectionConfigFilter filter) { if (filter == null) { @@ -89,7 +89,7 @@ public IEnumerable GetKnowledgeCollectionConfigs(VectorC } // Get data - var content = File.ReadAllText(configFile); + var content = await File.ReadAllTextAsync(configFile); var configs = JsonSerializer.Deserialize>(content, _options) ?? new(); // Apply filters @@ -112,9 +112,9 @@ public IEnumerable GetKnowledgeCollectionConfigs(VectorC } [SharpCache(10)] - public VectorCollectionConfig GetKnowledgeCollectionConfig(string collectionName, string vectorStroageProvider) + public async Task GetKnowledgeCollectionConfig(string collectionName, string vectorStroageProvider) { - var configs = GetKnowledgeCollectionConfigs(new VectorCollectionConfigFilter + var configs = await GetKnowledgeCollectionConfigs(new VectorCollectionConfigFilter { CollectionNames = [collectionName], VectorStroageProviders = [vectorStroageProvider] diff --git a/src/Infrastructure/BotSharp.OpenAPI/BotSharpOpenApiExtensions.cs b/src/Infrastructure/BotSharp.OpenAPI/BotSharpOpenApiExtensions.cs index 2a63ae3f7..ec9cf121b 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/BotSharpOpenApiExtensions.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/BotSharpOpenApiExtensions.cs @@ -12,6 +12,7 @@ using BotSharp.OpenAPI.BackgroundServices; using System.Text.Json.Serialization; using Microsoft.AspNetCore.Authentication; +using Microsoft.OpenApi.Models; namespace BotSharp.OpenAPI; @@ -160,6 +161,28 @@ public static IServiceCollection AddBotSharpOpenAPI(this IServiceCollection serv services.AddSwaggerGen( c => { +#if NET8_0 + c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme + { + In = ParameterLocation.Header, + Description = "Please insert JWT with Bearer into field", + Name = "Authorization", + Type = SecuritySchemeType.ApiKey + }); + c.AddSecurityRequirement(new OpenApiSecurityRequirement { + { + new OpenApiSecurityScheme + { + Reference = new OpenApiReference + { + Type = ReferenceType.SecurityScheme, + Id = "Bearer" + } + }, + Array.Empty() + } + }); +#endif } ); diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/Conversation/TranslationController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/Conversation/TranslationController.cs index a4fa2b50c..6d047dd8f 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/Conversation/TranslationController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/Conversation/TranslationController.cs @@ -23,7 +23,7 @@ public TranslationController(IServiceProvider services, public async Task Translate([FromBody] TranslationRequestModel model) { var db = _services.GetRequiredService(); - var agent = db.GetAgent(BuiltInAgentId.AIAssistant); + var agent = await db.GetAgentAsync(BuiltInAgentId.AIAssistant); var translator = _services.GetRequiredService(); var states = _services.GetRequiredService(); states.SetState("max_tokens", "8192"); @@ -38,7 +38,7 @@ public async Task Translate([FromBody] TranslationRequ public async Task SendMessageSse([FromBody] TranslationLongTextRequestModel model) { var db = _services.GetRequiredService(); - var agent = db.GetAgent(BuiltInAgentId.AIAssistant); + var agent = await db.GetAgentAsync(BuiltInAgentId.AIAssistant); var translator = _services.GetRequiredService(); Response.StatusCode = 200; diff --git a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/WelcomeHook.cs b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/WelcomeHook.cs index 3fbd852e1..23bc4a1a3 100644 --- a/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/WelcomeHook.cs +++ b/src/Plugins/BotSharp.Plugin.ChatHub/Hooks/WelcomeHook.cs @@ -36,7 +36,7 @@ public WelcomeHook( public override async Task OnUserAgentConnectedInitially(Conversation conversation) { var db = _services.GetRequiredService(); - var agent = db.GetAgent(conversation.AgentId); + var agent = await db.GetAgentAsync(conversation.AgentId); // Check if the Welcome template exists. var welcomeTemplate = agent?.Templates?.FirstOrDefault(x => x.Name == ".welcome"); diff --git a/src/Plugins/BotSharp.Plugin.KnowledgeBase/Helpers/KnowledgeSettingHelper.cs b/src/Plugins/BotSharp.Plugin.KnowledgeBase/Helpers/KnowledgeSettingHelper.cs index 112e3e19b..4ab227917 100644 --- a/src/Plugins/BotSharp.Plugin.KnowledgeBase/Helpers/KnowledgeSettingHelper.cs +++ b/src/Plugins/BotSharp.Plugin.KnowledgeBase/Helpers/KnowledgeSettingHelper.cs @@ -4,13 +4,13 @@ namespace BotSharp.Plugin.KnowledgeBase.Helpers; public static class KnowledgeSettingHelper { - public static ITextEmbedding GetTextEmbeddingSetting(IServiceProvider services, string collectionName) + public static async Task GetTextEmbeddingSetting(IServiceProvider services, string collectionName) { var settings = services.GetRequiredService(); var db = services.GetRequiredService(); // Get collection config from db - var config = db.GetKnowledgeCollectionConfig(collectionName, settings.VectorDb.Provider); + var config = await db.GetKnowledgeCollectionConfig(collectionName, settings.VectorDb.Provider); var textEmbeddingConfig = config?.TextEmbedding; var provider = textEmbeddingConfig?.Provider ?? settings.Default.TextEmbedding.Provider; diff --git a/src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/KnowledgeService.Document.cs b/src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/KnowledgeService.Document.cs index e73add1f9..613a2df8b 100644 --- a/src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/KnowledgeService.Document.cs +++ b/src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/KnowledgeService.Document.cs @@ -388,7 +388,7 @@ private async Task> SaveToVectorDb(string collectionName, IE var dataIds = new List(); var vectorDb = GetVectorDb(); - var textEmbedding = GetTextEmbedding(collectionName); + var textEmbedding = await GetTextEmbedding(collectionName); for (int i = 0; i < contents.Count(); i++) { diff --git a/src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/KnowledgeService.Vector.cs b/src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/KnowledgeService.Vector.cs index 61f5e686c..aab50869b 100644 --- a/src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/KnowledgeService.Vector.cs +++ b/src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/KnowledgeService.Vector.cs @@ -14,7 +14,7 @@ public async Task ExistVectorCollection(string collectionName) var exist = await vectorDb.DoesCollectionExist(collectionName); if (exist) return true; - var configs = db.GetKnowledgeCollectionConfigs(new VectorCollectionConfigFilter + var configs = await db.GetKnowledgeCollectionConfigs(new VectorCollectionConfigFilter { CollectionNames = [collectionName], VectorStroageProviders = [_settings.VectorDb.Provider] @@ -72,11 +72,11 @@ public async Task> GetVectorCollections(stri try { var db = _services.GetRequiredService(); - var configs = db.GetKnowledgeCollectionConfigs(new VectorCollectionConfigFilter + var configs = await db.GetKnowledgeCollectionConfigs(new VectorCollectionConfigFilter { CollectionTypes = !string.IsNullOrEmpty(type) ? [type] : null, VectorStroageProviders = [_settings.VectorDb.Provider] - }).ToList(); + }); var vectorDb = GetVectorDb(); if (vectorDb == null) @@ -100,10 +100,10 @@ public async Task> GetVectorCollections(stri if (string.IsNullOrWhiteSpace(collectionName)) return null; var db = _services.GetRequiredService(); - var configs = db.GetKnowledgeCollectionConfigs(new VectorCollectionConfigFilter + var configs = await db.GetKnowledgeCollectionConfigs(new VectorCollectionConfigFilter { CollectionNames = [collectionName] - }).ToList(); + }); var vectorDb = GetVectorDb(); var details = await vectorDb.GetCollectionDetails(collectionName); @@ -163,7 +163,7 @@ public async Task CreateVectorCollectionData(string collectionName, Vector return false; } - var textEmbedding = GetTextEmbedding(collectionName); + var textEmbedding = await GetTextEmbedding(collectionName); var vector = await textEmbedding.GetVectorAsync(create.Text); var db = GetVectorDb(); @@ -202,7 +202,7 @@ public async Task UpdateVectorCollectionData(string collectionName, Vector return false; } - var textEmbedding = GetTextEmbedding(collectionName); + var textEmbedding = await GetTextEmbedding(collectionName); var vector = await textEmbedding.GetVectorAsync(update.Text); var payload = update.Payload ?? new(); @@ -243,7 +243,7 @@ public async Task UpsertVectorCollectionData(string collectionName, Vector } } - var textEmbedding = GetTextEmbedding(collectionName); + var textEmbedding = await GetTextEmbedding(collectionName); var vector = await textEmbedding.GetVectorAsync(update.Text); var payload = update.Payload ?? new(); @@ -344,7 +344,7 @@ public async Task> SearchVectorKnowledge(string { try { - var textEmbedding = GetTextEmbedding(collectionName); + var textEmbedding = await GetTextEmbedding(collectionName); var vector = await textEmbedding.GetVectorAsync(query); // Vector search diff --git a/src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/KnowledgeService.cs b/src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/KnowledgeService.cs index 57003c5f7..9555960aa 100644 --- a/src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/KnowledgeService.cs +++ b/src/Plugins/BotSharp.Plugin.KnowledgeBase/Services/KnowledgeService.cs @@ -31,9 +31,9 @@ private IGraphDb GetGraphDb() return db; } - private ITextEmbedding GetTextEmbedding(string collectionName) + private async Task GetTextEmbedding(string collectionName) { - return KnowledgeSettingHelper.GetTextEmbeddingSetting(_services, collectionName); + return await KnowledgeSettingHelper.GetTextEmbeddingSetting(_services, collectionName); } private async Task GetUserId() diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs index 5e3a0bb35..75737ddde 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs @@ -3,6 +3,7 @@ using BotSharp.Abstraction.Functions.Models; using BotSharp.Abstraction.Repositories.Filters; using BotSharp.Abstraction.Routing.Models; +using MongoDB.Driver.Linq; namespace BotSharp.Plugin.MongoStorage.Repository; @@ -440,6 +441,17 @@ private void UpdateAgentAllFields(Agent agent) return TransformAgentDocument(agent); } + public async Task GetAgentAsync(string agentId, bool basicsOnly = false) + { + var agent = await _dc.Agents.AsQueryable().FirstOrDefaultAsync(x => x.Id == agentId); + if (agent == null) + { + return null; + } + + return TransformAgentDocument(agent); + } + public List GetAgents(AgentFilter filter) { if (filter == null) diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.AgentCodeScript.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.AgentCodeScript.cs index cc876e465..ae02f91fe 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.AgentCodeScript.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.AgentCodeScript.cs @@ -35,7 +35,7 @@ public List GetAgentCodeScripts(string agentId, AgentCodeScript return found.Select(x => AgentCodeScriptDocument.ToDomainModel(x)).ToList(); } - public AgentCodeScript? GetAgentCodeScript(string agentId, string scriptName, string scriptType = AgentCodeScriptType.Src) + public async Task GetAgentCodeScript(string agentId, string scriptName, string scriptType = AgentCodeScriptType.Src) { if (string.IsNullOrWhiteSpace(agentId) || string.IsNullOrWhiteSpace(scriptName) @@ -52,7 +52,7 @@ public List GetAgentCodeScripts(string agentId, AgentCodeScript builder.Eq(x => x.ScriptType, scriptType) }; - var found = _dc.AgentCodeScripts.Find(builder.And(filters)).FirstOrDefault(); + var found = await _dc.AgentCodeScripts.Find(builder.And(filters)).FirstOrDefaultAsync(); return found != null ? AgentCodeScriptDocument.ToDomainModel(found) : null; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs index affd182a2..42408562a 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs @@ -307,15 +307,15 @@ public void UpdateConversationStatus(string conversationId, string status) _dc.Conversations.UpdateOne(filter, update); } - public Conversation GetConversation(string conversationId, bool isLoadStates = false) + public async Task GetConversation(string conversationId, bool isLoadStates = false) { if (string.IsNullOrEmpty(conversationId)) return null; var filterConv = Builders.Filter.Eq(x => x.Id, conversationId); var filterDialog = Builders.Filter.Eq(x => x.ConversationId, conversationId); - var conv = _dc.Conversations.Find(filterConv).FirstOrDefault(); - var dialog = _dc.ConversationDialogs.Find(filterDialog).FirstOrDefault(); + var conv = await _dc.Conversations.Find(filterConv).FirstOrDefaultAsync(); + var dialog = await _dc.ConversationDialogs.Find(filterDialog).FirstOrDefaultAsync(); if (conv == null) return null; diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.KnowledgeBase.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.KnowledgeBase.cs index 18631cbba..b5afcfd62 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.KnowledgeBase.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.KnowledgeBase.cs @@ -78,7 +78,7 @@ public bool DeleteKnowledgeCollectionConfig(string collectionName) return deleted.DeletedCount > 0; } - public IEnumerable GetKnowledgeCollectionConfigs(VectorCollectionConfigFilter filter) + public async Task> GetKnowledgeCollectionConfigs(VectorCollectionConfigFilter filter) { if (filter == null) { @@ -117,9 +117,9 @@ public IEnumerable GetKnowledgeCollectionConfigs(VectorC } [SharpCache(10)] - public VectorCollectionConfig GetKnowledgeCollectionConfig(string collectionName, string vectorStroageProvider) + public async Task GetKnowledgeCollectionConfig(string collectionName, string vectorStroageProvider) { - var configs = GetKnowledgeCollectionConfigs(new VectorCollectionConfigFilter + var configs = await GetKnowledgeCollectionConfigs(new VectorCollectionConfigFilter { CollectionNames = [collectionName], VectorStroageProviders = [vectorStroageProvider]