Skip to content

refine content log input #327

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 3 commits into from
Mar 1, 2024
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 @@ -15,7 +15,7 @@ public interface IConversationService
Task<List<Conversation>> GetLastConversations();
Task<bool> DeleteConversation(string id);
Task<bool> TruncateConversation(string conversationId, string messageId);
Task<List<ConversationContentLogModel>> GetConversationContentLogs(string conversationId);
Task<List<ContentLogOutputModel>> GetConversationContentLogs(string conversationId);
Task<List<ConversationStateLogModel>> GetConversationStateLogs(string conversationId);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace BotSharp.Abstraction.Loggers.Models;

public class ContentLogInputModel
{
public string ConversationId { get; set; }
public string? Name { get; set; }
public string? AgentId { get; set; }
public string Log { get; set; }
public string Source { get; set; }
public RoleDialogModel Message { get; set; }

public ContentLogInputModel()
{

}

public ContentLogInputModel(string conversationId, RoleDialogModel message)
{
ConversationId = conversationId;
Message = message;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace BotSharp.Abstraction.Loggers.Models;

public class ConversationContentLogModel
public class ContentLogOutputModel
{
[JsonPropertyName("conversation_id")]
public string ConversationId { get; set; }
Expand All @@ -11,6 +11,9 @@ public class ConversationContentLogModel
[JsonPropertyName("name")]
public string? Name { get; set; }

[JsonPropertyName("agent_id")]
public string? AgentId { get; set; }

[JsonPropertyName("role")]
public string Role { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public interface IBotSharpRepository
#endregion

#region Conversation Content Log
void SaveConversationContentLog(ConversationContentLogModel log);
List<ConversationContentLogModel> GetConversationContentLogs(string conversationId);
void SaveConversationContentLog(ContentLogOutputModel log);
List<ContentLogOutputModel> GetConversationContentLogs(string conversationId);
#endregion

#region Conversation State Log
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace BotSharp.Core.Conversations.Services;

public partial class ConversationService
{
public async Task<List<ConversationContentLogModel>> GetConversationContentLogs(string conversationId)
public async Task<List<ContentLogOutputModel>> GetConversationContentLogs(string conversationId)
{
var db = _services.GetRequiredService<IBotSharpRepository>();
var logs = db.GetConversationContentLogs(conversationId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,12 @@ public void SaveLlmCompletionLog(LlmCompletionLog log)
#endregion

#region Conversation Content Log
public void SaveConversationContentLog(ConversationContentLogModel log)
public void SaveConversationContentLog(ContentLogOutputModel log)
{
throw new NotImplementedException();
}

public List<ConversationContentLogModel> GetConversationContentLogs(string conversationId)
public List<ContentLogOutputModel> GetConversationContentLogs(string conversationId)
{
throw new NotImplementedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ private bool HandleTruncatedLogs(string convDir, DateTime refTime)
foreach (var file in Directory.GetFiles(contentLogDir))
{
var text = File.ReadAllText(file);
var log = JsonSerializer.Deserialize<ConversationContentLogModel>(text);
var log = JsonSerializer.Deserialize<ContentLogOutputModel>(text);
if (log == null) continue;

if (log.CreateTime >= refTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void SaveLlmCompletionLog(LlmCompletionLog log)
#endregion

#region Conversation Content Log
public void SaveConversationContentLog(ConversationContentLogModel log)
public void SaveConversationContentLog(ContentLogOutputModel log)
{
if (log == null) return;

Expand All @@ -88,9 +88,9 @@ public void SaveConversationContentLog(ConversationContentLogModel log)
File.WriteAllText(file, JsonSerializer.Serialize(log, _options));
}

public List<ConversationContentLogModel> GetConversationContentLogs(string conversationId)
public List<ContentLogOutputModel> GetConversationContentLogs(string conversationId)
{
var logs = new List<ConversationContentLogModel>();
var logs = new List<ContentLogOutputModel>();
if (string.IsNullOrEmpty(conversationId)) return logs;

var convDir = FindConversationDirectory(conversationId);
Expand All @@ -102,7 +102,7 @@ public List<ConversationContentLogModel> GetConversationContentLogs(string conve
foreach (var file in Directory.GetFiles(logDir))
{
var text = File.ReadAllText(file);
var log = JsonSerializer.Deserialize<ConversationContentLogModel>(text);
var log = JsonSerializer.Deserialize<ContentLogOutputModel>(text);
if (log == null) continue;

logs.Add(log);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task<IActionResult> GetFullLog()
}

[HttpGet("/logger/conversation/{conversationId}/content-log")]
public async Task<List<ConversationContentLogModel>> GetConversationContentLogs([FromRoute] string conversationId)
public async Task<List<ContentLogOutputModel>> GetConversationContentLogs([FromRoute] string conversationId)
{
var conversationService = _services.GetRequiredService<IConversationService>();
return await conversationService.GetConversationContentLogs(conversationId);
Expand Down
Loading