Merge pull request #235 from iceljc/bugfix/refine-mongo-and-exe-log

rename mongo collection and use exe log flag
This commit is contained in:
Haiping 2023-12-13 12:20:25 -06:00 committed by GitHub
commit e51c47365a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 111 additions and 94 deletions

View file

@ -5,39 +5,56 @@ namespace BotSharp.Core.Evaluations;
public class EvaluationConversationHook : ConversationHookBase
{
private readonly IExecutionLogger _logger;
private readonly ConversationSetting _convSettings;
public EvaluationConversationHook(IExecutionLogger logger)
public EvaluationConversationHook(IExecutionLogger logger, ConversationSetting convSettings)
{
_logger = logger;
_convSettings = convSettings;
}
public override Task OnMessageReceived(RoleDialogModel message)
{
_logger.Append(_conversation.Id, $"[{DateTime.Now}] {message.Role}: {message.Content}");
if (_convSettings.EnableExecutionLog)
{
_logger.Append(_conversation.Id, $"[{DateTime.Now}] {message.Role}: {message.Content}");
}
return base.OnMessageReceived(message);
}
public override Task OnFunctionExecuted(RoleDialogModel message)
{
_logger.Append(_conversation.Id, $"[{DateTime.Now}] {message.Role}: {message.FunctionName}({message.FunctionArgs}) => {message.Content}");
if (_convSettings.EnableExecutionLog)
{
_logger.Append(_conversation.Id, $"[{DateTime.Now}] {message.Role}: {message.FunctionName}({message.FunctionArgs}) => {message.Content}");
}
return base.OnFunctionExecuted(message);
}
public override Task OnResponseGenerated(RoleDialogModel message)
{
_logger.Append(_conversation.Id, $"[{DateTime.Now}] {message.Role}: {message.Content}");
if (_convSettings.EnableExecutionLog)
{
_logger.Append(_conversation.Id, $"[{DateTime.Now}] {message.Role}: {message.Content}");
}
return base.OnResponseGenerated(message);
}
public override Task OnHumanInterventionNeeded(RoleDialogModel message)
{
_logger.Append(_conversation.Id, $"[{DateTime.Now}] {AgentRole.Function}: trigger_event({{\"event\": \"{message.FunctionName}\"}})");
if (_convSettings.EnableExecutionLog)
{
_logger.Append(_conversation.Id, $"[{DateTime.Now}] {AgentRole.Function}: trigger_event({{\"event\": \"{message.FunctionName}\"}})");
}
return base.OnHumanInterventionNeeded(message);
}
public override Task OnConversationEnding(RoleDialogModel message)
{
_logger.Append(_conversation.Id, $"[{DateTime.Now}] {AgentRole.Function}: trigger_event({{\"event\": \"{message.FunctionName}\"}})");
if (_convSettings.EnableExecutionLog)
{
_logger.Append(_conversation.Id, $"[{DateTime.Now}] {AgentRole.Function}: trigger_event({{\"event\": \"{message.FunctionName}\"}})");
}
return base.OnConversationEnding(message);
}
}

View file

@ -2,7 +2,7 @@ using BotSharp.Plugin.MongoStorage.Models;
namespace BotSharp.Plugin.MongoStorage.Collections;
public class AgentCollection : MongoBase
public class AgentDocument : MongoBase
{
public string Name { get; set; }
public string Description { get; set; }

View file

@ -2,7 +2,7 @@ using BotSharp.Plugin.MongoStorage.Models;
namespace BotSharp.Plugin.MongoStorage.Collections;
public class ConversationDialogCollection : MongoBase
public class ConversationDialogDocument : MongoBase
{
public string ConversationId { get; set; }
public List<DialogMongoElement> Dialogs { get; set; }

View file

@ -2,7 +2,7 @@ using BotSharp.Abstraction.Conversations.Models;
namespace BotSharp.Plugin.MongoStorage.Collections;
public class ConversationCollection : MongoBase
public class ConversationDocument : MongoBase
{
public string AgentId { get; set; }
public string UserId { get; set; }

View file

@ -1,6 +1,6 @@
namespace BotSharp.Plugin.MongoStorage.Collections;
public class ExecutionLogCollection : MongoBase
public class ExecutionLogDocument : MongoBase
{
public string ConversationId { get; set; }
public List<string> Logs { get; set; }

View file

@ -1,6 +1,6 @@
namespace BotSharp.Plugin.MongoStorage.Collections;
public class LlmCompletionLogCollection : MongoBase
public class LlmCompletionLogDocument : MongoBase
{
public string ConversationId { get; set; }
public string MessageId { get; set; }

View file

@ -1,6 +1,6 @@
namespace BotSharp.Plugin.MongoStorage.Collections;
public class UserAgentCollection : MongoBase
public class UserAgentDocument : MongoBase
{
public string UserId { get; set; }
public string AgentId { get; set; }

View file

@ -1,6 +1,6 @@
namespace BotSharp.Plugin.MongoStorage.Collections;
public class UserCollection : MongoBase
public class UserDocument : MongoBase
{
public string FirstName { get; set; }
public string LastName { get; set; }

View file

@ -28,24 +28,24 @@ public class MongoDbContext
private IMongoDatabase Database { get { return _mongoClient.GetDatabase(_mongoDbDatabaseName); } }
public IMongoCollection<AgentCollection> Agents
=> Database.GetCollection<AgentCollection>($"{_collectionPrefix}_Agents");
public IMongoCollection<AgentDocument> Agents
=> Database.GetCollection<AgentDocument>($"{_collectionPrefix}_Agents");
public IMongoCollection<ConversationCollection> Conversations
=> Database.GetCollection<ConversationCollection>($"{_collectionPrefix}_Conversations");
public IMongoCollection<ConversationDocument> Conversations
=> Database.GetCollection<ConversationDocument>($"{_collectionPrefix}_Conversations");
public IMongoCollection<ConversationDialogCollection> ConversationDialogs
=> Database.GetCollection<ConversationDialogCollection>($"{_collectionPrefix}_ConversationDialogs");
public IMongoCollection<ConversationDialogDocument> ConversationDialogs
=> Database.GetCollection<ConversationDialogDocument>($"{_collectionPrefix}_ConversationDialogs");
public IMongoCollection<ExecutionLogCollection> ExectionLogs
=> Database.GetCollection<ExecutionLogCollection>($"{_collectionPrefix}_ExecutionLogs");
public IMongoCollection<ExecutionLogDocument> ExectionLogs
=> Database.GetCollection<ExecutionLogDocument>($"{_collectionPrefix}_ExecutionLogs");
public IMongoCollection<UserCollection> Users
=> Database.GetCollection<UserCollection>($"{_collectionPrefix}_Users");
public IMongoCollection<UserDocument> Users
=> Database.GetCollection<UserDocument>($"{_collectionPrefix}_Users");
public IMongoCollection<UserAgentCollection> UserAgents
=> Database.GetCollection<UserAgentCollection>($"{_collectionPrefix}_UserAgents");
public IMongoCollection<UserAgentDocument> UserAgents
=> Database.GetCollection<UserAgentDocument>($"{_collectionPrefix}_UserAgents");
public IMongoCollection<LlmCompletionLogCollection> LlmCompletionLogs
=> Database.GetCollection<LlmCompletionLogCollection>($"{_collectionPrefix}_Llm_Completion_Logs");
public IMongoCollection<LlmCompletionLogDocument> LlmCompletionLogs
=> Database.GetCollection<LlmCompletionLogDocument>($"{_collectionPrefix}_Llm_Completion_Logs");
}

View file

@ -59,7 +59,7 @@ public class MongoRepository : IBotSharpRepository
{
if (table == nameof(Agent))
{
var agents = _agents.Select(x => new AgentCollection
var agents = _agents.Select(x => new AgentDocument
{
Id = !string.IsNullOrEmpty(x.Id) ? x.Id : Guid.NewGuid().ToString(),
Name = x.Name,
@ -88,8 +88,8 @@ public class MongoRepository : IBotSharpRepository
foreach (var agent in agents)
{
var filter = Builders<AgentCollection>.Filter.Eq(x => x.Id, agent.Id);
var update = Builders<AgentCollection>.Update
var filter = Builders<AgentDocument>.Filter.Eq(x => x.Id, agent.Id);
var update = Builders<AgentDocument>.Update
.Set(x => x.Name, agent.Name)
.Set(x => x.Description, agent.Description)
.Set(x => x.Instruction, agent.Instruction)
@ -109,7 +109,7 @@ public class MongoRepository : IBotSharpRepository
}
else if (table == nameof(User))
{
var users = _users.Select(x => new UserCollection
var users = _users.Select(x => new UserDocument
{
Id = !string.IsNullOrEmpty(x.Id) ? x.Id : Guid.NewGuid().ToString(),
FirstName = x.FirstName,
@ -125,8 +125,8 @@ public class MongoRepository : IBotSharpRepository
foreach (var user in users)
{
var filter = Builders<UserCollection>.Filter.Eq(x => x.Id, user.Id);
var update = Builders<UserCollection>.Update
var filter = Builders<UserDocument>.Filter.Eq(x => x.Id, user.Id);
var update = Builders<UserDocument>.Update
.Set(x => x.FirstName, user.FirstName)
.Set(x => x.LastName, user.LastName)
.Set(x => x.Email, user.Email)
@ -141,7 +141,7 @@ public class MongoRepository : IBotSharpRepository
}
else if (table == nameof(UserAgent))
{
var userAgents = _userAgents.Select(x => new UserAgentCollection
var userAgents = _userAgents.Select(x => new UserAgentDocument
{
Id = !string.IsNullOrEmpty(x.Id) ? x.Id : Guid.NewGuid().ToString(),
AgentId = x.AgentId,
@ -153,8 +153,8 @@ public class MongoRepository : IBotSharpRepository
foreach (var userAgent in userAgents)
{
var filter = Builders<UserAgentCollection>.Filter.Eq(x => x.Id, userAgent.Id);
var update = Builders<UserAgentCollection>.Update
var filter = Builders<UserAgentDocument>.Filter.Eq(x => x.Id, userAgent.Id);
var update = Builders<UserAgentDocument>.Update
.Set(x => x.AgentId, userAgent.AgentId)
.Set(x => x.UserId, userAgent.UserId)
.Set(x => x.Editable, userAgent.Editable)
@ -224,8 +224,8 @@ public class MongoRepository : IBotSharpRepository
{
if (string.IsNullOrEmpty(name)) return;
var filter = Builders<AgentCollection>.Filter.Eq(x => x.Id, agentId);
var update = Builders<AgentCollection>.Update
var filter = Builders<AgentDocument>.Filter.Eq(x => x.Id, agentId);
var update = Builders<AgentDocument>.Update
.Set(x => x.Name, name)
.Set(x => x.UpdatedTime, DateTime.UtcNow);
@ -236,8 +236,8 @@ public class MongoRepository : IBotSharpRepository
{
if (string.IsNullOrEmpty(description)) return;
var filter = Builders<AgentCollection>.Filter.Eq(x => x.Id, agentId);
var update = Builders<AgentCollection>.Update
var filter = Builders<AgentDocument>.Filter.Eq(x => x.Id, agentId);
var update = Builders<AgentDocument>.Update
.Set(x => x.Description, description)
.Set(x => x.UpdatedTime, DateTime.UtcNow);
@ -246,8 +246,8 @@ public class MongoRepository : IBotSharpRepository
private void UpdateAgentIsPublic(string agentId, bool isPublic)
{
var filter = Builders<AgentCollection>.Filter.Eq(x => x.Id, agentId);
var update = Builders<AgentCollection>.Update
var filter = Builders<AgentDocument>.Filter.Eq(x => x.Id, agentId);
var update = Builders<AgentDocument>.Update
.Set(x => x.IsPublic, isPublic)
.Set(x => x.UpdatedTime, DateTime.UtcNow);
@ -256,8 +256,8 @@ public class MongoRepository : IBotSharpRepository
private void UpdateAgentDisabled(string agentId, bool disabled)
{
var filter = Builders<AgentCollection>.Filter.Eq(x => x.Id, agentId);
var update = Builders<AgentCollection>.Update
var filter = Builders<AgentDocument>.Filter.Eq(x => x.Id, agentId);
var update = Builders<AgentDocument>.Update
.Set(x => x.Disabled, disabled)
.Set(x => x.UpdatedTime, DateTime.UtcNow);
@ -266,8 +266,8 @@ public class MongoRepository : IBotSharpRepository
private void UpdateAgentAllowRouting(string agentId, bool allowRouting)
{
var filter = Builders<AgentCollection>.Filter.Eq(x => x.Id, agentId);
var update = Builders<AgentCollection>.Update
var filter = Builders<AgentDocument>.Filter.Eq(x => x.Id, agentId);
var update = Builders<AgentDocument>.Update
.Set(x => x.AllowRouting, allowRouting)
.Set(x => x.UpdatedTime, DateTime.UtcNow);
@ -278,8 +278,8 @@ public class MongoRepository : IBotSharpRepository
{
if (profiles.IsNullOrEmpty()) return;
var filter = Builders<AgentCollection>.Filter.Eq(x => x.Id, agentId);
var update = Builders<AgentCollection>.Update
var filter = Builders<AgentDocument>.Filter.Eq(x => x.Id, agentId);
var update = Builders<AgentDocument>.Update
.Set(x => x.Profiles, profiles)
.Set(x => x.UpdatedTime, DateTime.UtcNow);
@ -291,8 +291,8 @@ public class MongoRepository : IBotSharpRepository
if (rules.IsNullOrEmpty()) return;
var ruleElements = rules.Select(x => RoutingRuleMongoElement.ToMongoElement(x)).ToList();
var filter = Builders<AgentCollection>.Filter.Eq(x => x.Id, agentId);
var update = Builders<AgentCollection>.Update
var filter = Builders<AgentDocument>.Filter.Eq(x => x.Id, agentId);
var update = Builders<AgentDocument>.Update
.Set(x => x.RoutingRules, ruleElements)
.Set(x => x.UpdatedTime, DateTime.UtcNow);
@ -303,8 +303,8 @@ public class MongoRepository : IBotSharpRepository
{
if (string.IsNullOrEmpty(instruction)) return;
var filter = Builders<AgentCollection>.Filter.Eq(x => x.Id, agentId);
var update = Builders<AgentCollection>.Update
var filter = Builders<AgentDocument>.Filter.Eq(x => x.Id, agentId);
var update = Builders<AgentDocument>.Update
.Set(x => x.Instruction, instruction)
.Set(x => x.UpdatedTime, DateTime.UtcNow);
@ -316,8 +316,8 @@ public class MongoRepository : IBotSharpRepository
if (functions.IsNullOrEmpty()) return;
var functionsToUpdate = functions.Select(f => FunctionDefMongoElement.ToMongoElement(f)).ToList();
var filter = Builders<AgentCollection>.Filter.Eq(x => x.Id, agentId);
var update = Builders<AgentCollection>.Update
var filter = Builders<AgentDocument>.Filter.Eq(x => x.Id, agentId);
var update = Builders<AgentDocument>.Update
.Set(x => x.Functions, functionsToUpdate)
.Set(x => x.UpdatedTime, DateTime.UtcNow);
@ -329,8 +329,8 @@ public class MongoRepository : IBotSharpRepository
if (templates.IsNullOrEmpty()) return;
var templatesToUpdate = templates.Select(t => AgentTemplateMongoElement.ToMongoElement(t)).ToList();
var filter = Builders<AgentCollection>.Filter.Eq(x => x.Id, agentId);
var update = Builders<AgentCollection>.Update
var filter = Builders<AgentDocument>.Filter.Eq(x => x.Id, agentId);
var update = Builders<AgentDocument>.Update
.Set(x => x.Templates, templatesToUpdate)
.Set(x => x.UpdatedTime, DateTime.UtcNow);
@ -342,8 +342,8 @@ public class MongoRepository : IBotSharpRepository
if (responses.IsNullOrEmpty()) return;
var responsesToUpdate = responses.Select(r => AgentResponseMongoElement.ToMongoElement(r)).ToList();
var filter = Builders<AgentCollection>.Filter.Eq(x => x.Id, agentId);
var update = Builders<AgentCollection>.Update
var filter = Builders<AgentDocument>.Filter.Eq(x => x.Id, agentId);
var update = Builders<AgentDocument>.Update
.Set(x => x.Responses, responsesToUpdate)
.Set(x => x.UpdatedTime, DateTime.UtcNow);
@ -354,8 +354,8 @@ public class MongoRepository : IBotSharpRepository
{
if (samples.IsNullOrEmpty()) return;
var filter = Builders<AgentCollection>.Filter.Eq(x => x.Id, agentId);
var update = Builders<AgentCollection>.Update
var filter = Builders<AgentDocument>.Filter.Eq(x => x.Id, agentId);
var update = Builders<AgentDocument>.Update
.Set(x => x.Samples, samples)
.Set(x => x.UpdatedTime, DateTime.UtcNow);
@ -364,8 +364,8 @@ public class MongoRepository : IBotSharpRepository
private void UpdateAgentAllFields(Agent agent)
{
var filter = Builders<AgentCollection>.Filter.Eq(x => x.Id, agent.Id);
var update = Builders<AgentCollection>.Update
var filter = Builders<AgentDocument>.Filter.Eq(x => x.Id, agent.Id);
var update = Builders<AgentDocument>.Update
.Set(x => x.Name, agent.Name)
.Set(x => x.Description, agent.Description)
.Set(x => x.Disabled, agent.Disabled)
@ -420,7 +420,7 @@ public class MongoRepository : IBotSharpRepository
public List<Agent> GetAgents(AgentFilter filter)
{
var agents = new List<Agent>();
IQueryable<AgentCollection> query = _dc.Agents.AsQueryable();
IQueryable<AgentDocument> query = _dc.Agents.AsQueryable();
if (!string.IsNullOrEmpty(filter.AgentName))
{
@ -510,7 +510,7 @@ public class MongoRepository : IBotSharpRepository
{
if (agents.IsNullOrEmpty()) return;
var agentDocs = agents.Select(x => new AgentCollection
var agentDocs = agents.Select(x => new AgentDocument
{
Id = !string.IsNullOrEmpty(x.Id) ? x.Id : Guid.NewGuid().ToString(),
Name = x.Name,
@ -544,7 +544,7 @@ public class MongoRepository : IBotSharpRepository
{
if (userAgents.IsNullOrEmpty()) return;
var userAgentDocs = userAgents.Select(x => new UserAgentCollection
var userAgentDocs = userAgents.Select(x => new UserAgentDocument
{
Id = !string.IsNullOrEmpty(x.Id) ? x.Id : Guid.NewGuid().ToString(),
AgentId = x.AgentId,
@ -561,8 +561,8 @@ public class MongoRepository : IBotSharpRepository
{
try
{
_dc.UserAgents.DeleteMany(Builders<UserAgentCollection>.Filter.Empty);
_dc.Agents.DeleteMany(Builders<AgentCollection>.Filter.Empty);
_dc.UserAgents.DeleteMany(Builders<UserAgentDocument>.Filter.Empty);
_dc.Agents.DeleteMany(Builders<AgentDocument>.Filter.Empty);
return true;
}
catch
@ -578,7 +578,7 @@ public class MongoRepository : IBotSharpRepository
{
if (conversation == null) return;
var conv = new ConversationCollection
var conv = new ConversationDocument
{
Id = !string.IsNullOrEmpty(conversation.Id) ? conversation.Id : Guid.NewGuid().ToString(),
AgentId = conversation.AgentId,
@ -591,7 +591,7 @@ public class MongoRepository : IBotSharpRepository
UpdatedTime = DateTime.UtcNow,
};
var dialog = new ConversationDialogCollection
var dialog = new ConversationDialogDocument
{
Id = Guid.NewGuid().ToString(),
ConversationId = conv.Id,
@ -606,10 +606,10 @@ public class MongoRepository : IBotSharpRepository
{
if (string.IsNullOrEmpty(conversationId)) return false;
var filterConv = Builders<ConversationCollection>.Filter.Eq(x => x.Id, conversationId);
var filterDialog = Builders<ConversationDialogCollection>.Filter.Eq(x => x.ConversationId, conversationId);
var filterExeLog = Builders<ExecutionLogCollection>.Filter.Eq(x => x.ConversationId, conversationId);
var filterPromptLog = Builders<LlmCompletionLogCollection>.Filter.Eq(x => x.ConversationId, conversationId);
var filterConv = Builders<ConversationDocument>.Filter.Eq(x => x.Id, conversationId);
var filterDialog = Builders<ConversationDialogDocument>.Filter.Eq(x => x.ConversationId, conversationId);
var filterExeLog = Builders<ExecutionLogDocument>.Filter.Eq(x => x.ConversationId, conversationId);
var filterPromptLog = Builders<LlmCompletionLogDocument>.Filter.Eq(x => x.ConversationId, conversationId);
var exeLogDeleted = _dc.ExectionLogs.DeleteMany(filterExeLog);
var promptLogDeleted = _dc.LlmCompletionLogs.DeleteMany(filterPromptLog);
@ -623,7 +623,7 @@ public class MongoRepository : IBotSharpRepository
var dialogs = new List<DialogElement>();
if (string.IsNullOrEmpty(conversationId)) return dialogs;
var filter = Builders<ConversationDialogCollection>.Filter.Eq(x => x.ConversationId, conversationId);
var filter = Builders<ConversationDialogDocument>.Filter.Eq(x => x.ConversationId, conversationId);
var foundDialog = _dc.ConversationDialogs.Find(filter).FirstOrDefault();
if (foundDialog == null) return dialogs;
@ -635,17 +635,17 @@ public class MongoRepository : IBotSharpRepository
{
if (string.IsNullOrEmpty(conversationId)) return;
var filterConv = Builders<ConversationCollection>.Filter.Eq(x => x.Id, conversationId);
var filterConv = Builders<ConversationDocument>.Filter.Eq(x => x.Id, conversationId);
var foundConv = _dc.Conversations.Find(filterConv).FirstOrDefault();
if (foundConv == null) return;
var filterDialog = Builders<ConversationDialogCollection>.Filter.Eq(x => x.ConversationId, conversationId);
var filterDialog = Builders<ConversationDialogDocument>.Filter.Eq(x => x.ConversationId, conversationId);
var foundDialog = _dc.ConversationDialogs.Find(filterDialog).FirstOrDefault();
if (foundDialog == null) return;
var dialogElements = dialogs.Select(x => DialogMongoElement.ToMongoElement(x)).ToList();
var updateDialog = Builders<ConversationDialogCollection>.Update.PushEach(x => x.Dialogs, dialogElements);
var updateConv = Builders<ConversationCollection>.Update.Set(x => x.UpdatedTime, DateTime.UtcNow);
var updateDialog = Builders<ConversationDialogDocument>.Update.PushEach(x => x.Dialogs, dialogElements);
var updateConv = Builders<ConversationDocument>.Update.Set(x => x.UpdatedTime, DateTime.UtcNow);
_dc.ConversationDialogs.UpdateOne(filterDialog, updateDialog);
_dc.Conversations.UpdateOne(filterConv, updateConv);
@ -655,11 +655,11 @@ public class MongoRepository : IBotSharpRepository
{
if (string.IsNullOrEmpty(conversationId)) return;
var filterConv = Builders<ConversationCollection>.Filter.Eq(x => x.Id, conversationId);
var filterConv = Builders<ConversationDocument>.Filter.Eq(x => x.Id, conversationId);
var foundConv = _dc.Conversations.Find(filterConv).FirstOrDefault();
if (foundConv == null) return;
var updateConv = Builders<ConversationCollection>.Update
var updateConv = Builders<ConversationDocument>.Update
.Set(x => x.UpdatedTime, DateTime.UtcNow)
.Set(x => x.Title, title);
@ -671,7 +671,7 @@ public class MongoRepository : IBotSharpRepository
var states = new List<StateKeyValue>();
if (string.IsNullOrEmpty(conversationId)) return states;
var filter = Builders<ConversationCollection>.Filter.Eq(x => x.Id, conversationId);
var filter = Builders<ConversationDocument>.Filter.Eq(x => x.Id, conversationId);
var foundConversation = _dc.Conversations.Find(filter).FirstOrDefault();
var savedStates = foundConversation?.States ?? new List<StateKeyValue>();
return savedStates;
@ -681,11 +681,11 @@ public class MongoRepository : IBotSharpRepository
{
if (string.IsNullOrEmpty(conversationId)) return;
var filter = Builders<ConversationCollection>.Filter.Eq(x => x.Id, conversationId);
var filter = Builders<ConversationDocument>.Filter.Eq(x => x.Id, conversationId);
var foundConv = _dc.Conversations.Find(filter).FirstOrDefault();
if (foundConv == null) return;
var update = Builders<ConversationCollection>.Update
var update = Builders<ConversationDocument>.Update
.Set(x => x.States, states)
.Set(x => x.UpdatedTime, DateTime.UtcNow);
@ -696,11 +696,11 @@ public class MongoRepository : IBotSharpRepository
{
if (string.IsNullOrEmpty(conversationId) || string.IsNullOrEmpty(status)) return;
var filter = Builders<ConversationCollection>.Filter.Eq(x => x.Id, conversationId);
var filter = Builders<ConversationDocument>.Filter.Eq(x => x.Id, conversationId);
var foundConv = _dc.Conversations.Find(filter).FirstOrDefault();
if (foundConv == null) return;
var update = Builders<ConversationCollection>.Update
var update = Builders<ConversationDocument>.Update
.Set(x => x.Status, status)
.Set(x => x.UpdatedTime, DateTime.UtcNow);
@ -711,8 +711,8 @@ public class MongoRepository : IBotSharpRepository
{
if (string.IsNullOrEmpty(conversationId)) return null;
var filterConv = Builders<ConversationCollection>.Filter.Eq(x => x.Id, conversationId);
var filterDialog = Builders<ConversationDialogCollection>.Filter.Eq(x => x.ConversationId, conversationId);
var filterConv = Builders<ConversationDocument>.Filter.Eq(x => x.Id, conversationId);
var filterDialog = Builders<ConversationDialogDocument>.Filter.Eq(x => x.ConversationId, conversationId);
var conv = _dc.Conversations.Find(filterConv).FirstOrDefault();
var dialog = _dc.ConversationDialogs.Find(filterDialog).FirstOrDefault();
@ -739,8 +739,8 @@ public class MongoRepository : IBotSharpRepository
public List<Conversation> GetConversations(ConversationFilter filter)
{
var records = new List<Conversation>();
var builder = Builders<ConversationCollection>.Filter;
var filters = new List<FilterDefinition<ConversationCollection>>();
var builder = Builders<ConversationDocument>.Filter;
var filters = new List<FilterDefinition<ConversationDocument>>();
if (!string.IsNullOrEmpty(filter.AgentId)) filters.Add(builder.Eq(x => x.AgentId, filter.AgentId));
if (!string.IsNullOrEmpty(filter.Status)) filters.Add(builder.Eq(x => x.Status, filter.Status));
@ -825,7 +825,7 @@ public class MongoRepository : IBotSharpRepository
{
if (user == null) return;
var userCollection = new UserCollection
var userCollection = new UserDocument
{
Id = Guid.NewGuid().ToString(),
FirstName = user.FirstName,
@ -848,8 +848,8 @@ public class MongoRepository : IBotSharpRepository
{
if (string.IsNullOrEmpty(conversationId) || logs.IsNullOrEmpty()) return;
var filter = Builders<ExecutionLogCollection>.Filter.Eq(x => x.ConversationId, conversationId);
var update = Builders<ExecutionLogCollection>.Update
var filter = Builders<ExecutionLogDocument>.Filter.Eq(x => x.ConversationId, conversationId);
var update = Builders<ExecutionLogDocument>.Update
.SetOnInsert(x => x.Id, Guid.NewGuid().ToString())
.PushEach(x => x.Logs, logs);
@ -861,7 +861,7 @@ public class MongoRepository : IBotSharpRepository
var logs = new List<string>();
if (string.IsNullOrEmpty(conversationId)) return logs;
var filter = Builders<ExecutionLogCollection>.Filter.Eq(x => x.ConversationId, conversationId);
var filter = Builders<ExecutionLogDocument>.Filter.Eq(x => x.ConversationId, conversationId);
var logCollection = _dc.ExectionLogs.Find(filter).FirstOrDefault();
logs = logCollection?.Logs ?? new List<string>();
@ -872,7 +872,7 @@ public class MongoRepository : IBotSharpRepository
#region LLM Completion Log
public void SaveLlmCompletionLog(LlmCompletionLog log)
{
var completiongLog = new LlmCompletionLogCollection
var completiongLog = new LlmCompletionLogDocument
{
Id = string.IsNullOrEmpty(log.Id) ? Guid.NewGuid().ToString() : log.Id,
ConversationId = log.ConversationId,