refine llm completion log

This commit is contained in:
Jicheng Lu 2025-02-20 12:17:21 -06:00
parent 816abe9310
commit 6e9237ca4b
5 changed files with 12 additions and 23 deletions

View file

@ -7,5 +7,5 @@ public class LlmCompletionLog
public string AgentId { get; set; } = string.Empty;
public string Prompt { get; set; } = string.Empty;
public string? Response { get; set; }
public DateTime CreateDateTime { get; set; } = DateTime.UtcNow;
public DateTime CreatedTime { get; set; } = DateTime.UtcNow;
}

View file

@ -30,7 +30,7 @@ public class CommonContentGeneratingHook : IContentGeneratingHook
AgentId = message.CurrentAgentId,
Prompt = tokenStats.Prompt,
Response = message.Content,
CreateDateTime = DateTime.UtcNow
CreatedTime = DateTime.UtcNow
};
db.SaveLlmCompletionLog(completionLog);

View file

@ -3,5 +3,9 @@ namespace BotSharp.Plugin.MongoStorage.Collections;
public class LlmCompletionLogDocument : MongoBase
{
public string ConversationId { get; set; } = default!;
public List<PromptLogMongoElement> Logs { get; set; } = [];
public string MessageId { get; set; } = default!;
public string AgentId { get; set; } = default!;
public string Prompt { get; set; } = default!;
public string? Response { get; set; }
public DateTime CreatedTime { get; set; }
}

View file

@ -1,11 +0,0 @@
namespace BotSharp.Plugin.MongoStorage.Models;
[BsonIgnoreExtraElements(Inherited = true)]
public class PromptLogMongoElement
{
public string MessageId { get; set; } = default!;
public string AgentId { get; set; } = default!;
public string Prompt { get; set; } = default!;
public string? Response { get; set; }
public DateTime CreateDateTime { get; set; }
}

View file

@ -12,21 +12,17 @@ public partial class MongoRepository
var conversationId = log.ConversationId.IfNullOrEmptyAs(Guid.NewGuid().ToString());
var messageId = log.MessageId.IfNullOrEmptyAs(Guid.NewGuid().ToString());
var logElement = new PromptLogMongoElement
var data = new LlmCompletionLogDocument
{
Id = Guid.NewGuid().ToString(),
ConversationId = conversationId,
MessageId = messageId,
AgentId = log.AgentId,
Prompt = log.Prompt,
Response = log.Response,
CreateDateTime = log.CreateDateTime
CreatedTime = log.CreatedTime
};
var filter = Builders<LlmCompletionLogDocument>.Filter.Eq(x => x.ConversationId, conversationId);
var update = Builders<LlmCompletionLogDocument>.Update
.SetOnInsert(x => x.Id, Guid.NewGuid().ToString())
.Push(x => x.Logs, logElement);
_dc.LlmCompletionLogs.UpdateOne(filter, update, _options);
_dc.LlmCompletionLogs.InsertOne(data);
}
#endregion