Skip to content
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
10 changes: 7 additions & 3 deletions src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -860,8 +860,10 @@ public List<string> GetExecutionLogs(string conversationId)
#region LLM Completion Log
public void SaveLlmCompletionLog(LlmCompletionLog log)
{
if (log == null || string.IsNullOrEmpty(log.ConversationId)) return;

var convDir = FindConversationDirectory(log.ConversationId);
if (!Directory.Exists(convDir)) return;
if (string.IsNullOrEmpty(convDir)) return;

var logDir = Path.Combine(convDir, "llm_prompt_log");
if (!Directory.Exists(logDir))
Expand All @@ -870,7 +872,7 @@ public void SaveLlmCompletionLog(LlmCompletionLog log)
}

log.Id = Guid.NewGuid().ToString();
var index = GetLlmCompletionLogIndex(logDir, log.MessageId);
var index = GetNextLlmCompletionLogIndex(logDir, log.MessageId);
var file = Path.Combine(logDir, $"{log.MessageId}.{index}.log");
File.WriteAllText(file, JsonSerializer.Serialize(log, _options));
}
Expand Down Expand Up @@ -969,6 +971,8 @@ private List<AgentResponse> FetchResponses(string fileDir)

private string? FindConversationDirectory(string conversationId)
{
if (string.IsNullOrEmpty(conversationId)) return null;

var dir = Path.Combine(_dbSettings.FileRepository, _conversationSettings.DataDir, conversationId);
if (!Directory.Exists(dir)) return null;

Expand Down Expand Up @@ -1024,7 +1028,7 @@ private List<StateKeyValue> CollectConversationStates(string stateDir)
return states;
}

private int GetLlmCompletionLogIndex(string logDir, string id)
private int GetNextLlmCompletionLogIndex(string logDir, string id)
{
var files = Directory.GetFiles(logDir);
if (files.IsNullOrEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,8 @@ public List<string> GetExecutionLogs(string conversationId)
#region LLM Completion Log
public void SaveLlmCompletionLog(LlmCompletionLog log)
{
if (log == null || string.IsNullOrEmpty(log.ConversationId)) return;

var completiongLog = new LlmCompletionLogDocument
{
Id = string.IsNullOrEmpty(log.Id) ? Guid.NewGuid().ToString() : log.Id,
Expand Down