Skip to content

rename mongo collection and use exe log flag #235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace BotSharp.Plugin.MongoStorage.Collections;

public class AgentCollection : MongoBase
public class AgentDocument : MongoBase
{
public string Name { get; set; }
public string Description { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace BotSharp.Plugin.MongoStorage.Collections;

public class ConversationDialogCollection : MongoBase
public class ConversationDialogDocument : MongoBase
{
public string ConversationId { get; set; }
public List<DialogMongoElement> Dialogs { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace BotSharp.Plugin.MongoStorage.Collections;

public class ConversationCollection : MongoBase
public class ConversationDocument : MongoBase
{
public string AgentId { get; set; }
public string UserId { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -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; }
Expand Down
Original file line number Diff line number Diff line change
@@ -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; }
Expand Down
Original file line number Diff line number Diff line change
@@ -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; }
Expand Down
Original file line number Diff line number Diff line change
@@ -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; }
Expand Down
28 changes: 14 additions & 14 deletions src/Plugins/BotSharp.Plugin.MongoStorage/MongoDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@ private string GetDatabaseName(string mongoDbConnectionString)

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");
}
Loading