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
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@ public bool SaveSpeechFile(string conversationId, string fileName, BinaryData da

public BinaryData GetSpeechFile(string conversationId, string fileName)
{
if (string.IsNullOrWhiteSpace(conversationId) || string.IsNullOrWhiteSpace(fileName))
{
return BinaryData.Empty;
}

var path = Path.Combine(_baseDir, CONVERSATION_FOLDER, conversationId, TEXT_TO_SPEECH_FOLDER, fileName);
if (!File.Exists(path))
{
return BinaryData.Empty;
}

using var fs = new FileStream(path, FileMode.Open, FileAccess.Read);
return BinaryData.FromStream(fs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,30 @@ public async Task<IEnumerable<MessageFileModel>> GetMessageFileScreenshotsAsync(

foreach (var messageId in messageIds)
{
if (string.IsNullOrWhiteSpace(messageId))
{
continue;
}

var dir = Path.Combine(pathPrefix, messageId, FileSourceType.User);
if (!ExistDirectory(dir)) continue;
if (!ExistDirectory(dir))
{
continue;
}

foreach (var subDir in Directory.GetDirectories(dir))
{
var file = Directory.GetFiles(subDir).FirstOrDefault();
if (file == null) continue;
if (file == null)
{
continue;
}

var screenshots = await GetScreenshots(file, subDir, messageId, source);
if (screenshots.IsNullOrEmpty()) continue;
if (screenshots.IsNullOrEmpty())
{
continue;
}

files.AddRange(screenshots);
}
Expand All @@ -41,10 +55,18 @@ public IEnumerable<MessageFileModel> GetMessageFiles(string conversationId, IEnu
string source, IEnumerable<string>? contentTypes = null)
{
var files = new List<MessageFileModel>();
if (string.IsNullOrWhiteSpace(conversationId) || messageIds.IsNullOrEmpty()) return files;
if (string.IsNullOrWhiteSpace(conversationId) || messageIds.IsNullOrEmpty())
{
return files;
}

foreach (var messageId in messageIds)
{
if (string.IsNullOrWhiteSpace(messageId))
{
continue;
}

var dir = Path.Combine(_baseDir, CONVERSATION_FOLDER, conversationId, FILE_FOLDER, messageId, source);
if (!ExistDirectory(dir))
{
Expand Down Expand Up @@ -85,6 +107,14 @@ public IEnumerable<MessageFileModel> GetMessageFiles(string conversationId, IEnu

public string GetMessageFile(string conversationId, string messageId, string source, string index, string fileName)
{
if (string.IsNullOrWhiteSpace(conversationId)
|| string.IsNullOrWhiteSpace(messageId)
|| string.IsNullOrWhiteSpace(source)
|| string.IsNullOrWhiteSpace(index))
{
return string.Empty;
}

var dir = Path.Combine(_baseDir, CONVERSATION_FOLDER, conversationId, FILE_FOLDER, messageId, source, index);
if (!ExistDirectory(dir))
{
Expand All @@ -98,10 +128,18 @@ public string GetMessageFile(string conversationId, string messageId, string sou
public IEnumerable<MessageFileModel> GetMessagesWithFile(string conversationId, IEnumerable<string> messageIds)
{
var foundMsgs = new List<MessageFileModel>();
if (string.IsNullOrWhiteSpace(conversationId) || messageIds.IsNullOrEmpty()) return foundMsgs;
if (string.IsNullOrWhiteSpace(conversationId) || messageIds.IsNullOrEmpty())
{
return foundMsgs;
}

foreach (var messageId in messageIds)
{
if (string.IsNullOrWhiteSpace(messageId))
{
continue;
}

var prefix = Path.Combine(_baseDir, CONVERSATION_FOLDER, conversationId, FILE_FOLDER, messageId);
var userDir = Path.Combine(prefix, FileSourceType.User);
if (ExistDirectory(userDir))
Expand All @@ -121,10 +159,19 @@ public IEnumerable<MessageFileModel> GetMessagesWithFile(string conversationId,

public bool SaveMessageFiles(string conversationId, string messageId, string source, List<FileDataModel> files)
{
if (files.IsNullOrEmpty()) return false;
if (string.IsNullOrWhiteSpace(conversationId)
|| string.IsNullOrWhiteSpace(messageId)
|| string.IsNullOrWhiteSpace(source)
|| files.IsNullOrEmpty())
{
return false;
}

var dir = GetConversationFileDirectory(conversationId, messageId, createNewDir: true);
if (!ExistDirectory(dir)) return false;
if (!ExistDirectory(dir))
{
return false;
}

for (int i = 0; i < files.Count; i++)
{
Expand Down Expand Up @@ -164,7 +211,10 @@ public bool SaveMessageFiles(string conversationId, string messageId, string sou

public bool DeleteMessageFiles(string conversationId, IEnumerable<string> messageIds, string targetMessageId, string? newMessageId = null)
{
if (string.IsNullOrEmpty(conversationId) || messageIds == null) return false;
if (string.IsNullOrEmpty(conversationId) || messageIds == null)
{
return false;
}

if (!string.IsNullOrEmpty(targetMessageId) && !string.IsNullOrEmpty(newMessageId))
{
Expand Down Expand Up @@ -192,7 +242,10 @@ public bool DeleteMessageFiles(string conversationId, IEnumerable<string> messag
foreach (var messageId in messageIds)
{
var dir = GetConversationFileDirectory(conversationId, messageId);
if (!ExistDirectory(dir)) continue;
if (!ExistDirectory(dir))
{
continue;
}

DeleteDirectory(dir);
Thread.Sleep(100);
Expand All @@ -203,12 +256,18 @@ public bool DeleteMessageFiles(string conversationId, IEnumerable<string> messag

public bool DeleteConversationFiles(IEnumerable<string> conversationIds)
{
if (conversationIds.IsNullOrEmpty()) return false;
if (conversationIds.IsNullOrEmpty())
{
return false;
}

foreach (var conversationId in conversationIds)
{
var convDir = GetConversationDirectory(conversationId);
if (!ExistDirectory(convDir)) continue;
if (!ExistDirectory(convDir))
{
continue;
}

DeleteDirectory(convDir);
}
Expand Down Expand Up @@ -241,7 +300,10 @@ private string GetConversationFileDirectory(string? conversationId, string? mess

private IEnumerable<string> GetMessageIds(IEnumerable<RoleDialogModel> dialogs, int? offset = null)
{
if (dialogs.IsNullOrEmpty()) return Enumerable.Empty<string>();
if (dialogs.IsNullOrEmpty())
{
return Enumerable.Empty<string>();
}

if (offset.HasValue && offset < 1)
{
Expand All @@ -264,13 +326,17 @@ private IEnumerable<string> GetMessageIds(IEnumerable<RoleDialogModel> dialogs,
private async Task<IEnumerable<string>> ConvertPdfToImages(string pdfLoc, string imageLoc)
{
var converters = _services.GetServices<IPdf2ImageConverter>();
if (converters.IsNullOrEmpty()) return Enumerable.Empty<string>();
if (converters.IsNullOrEmpty())
{
return Enumerable.Empty<string>();
}

var converter = GetPdf2ImageConverter();
if (converter == null)
{
return Enumerable.Empty<string>();
}

return await converter.ConvertPdfToImages(pdfLoc, imageLoc);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public async Task<bool> InvokeAgent(
message.Indication = response.Indication;
message.CurrentAgentId = agent.Id;
message.IsStreaming = response.IsStreaming;
message.AdditionalMessageWrapper = null;

await InvokeFunction(message, dialogs, options);
}
Expand All @@ -74,6 +75,7 @@ public async Task<bool> InvokeAgent(
message = RoleDialogModel.From(message, role: AgentRole.Assistant, content: response.Content);
message.CurrentAgentId = agent.Id;
message.IsStreaming = response.IsStreaming;
message.AdditionalMessageWrapper = null;
dialogs.Add(message);
Context.SetDialogs(dialogs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,10 @@ public async Task<bool> Execute(RoleDialogModel message)
SaveToDb = true,
Messages = new List<RoleDialogModel>
{
new()
new(AgentRole.Assistant, obj.ReportSummary)
{
Role = AgentRole.Assistant,
MessageId = message.MessageId,
CurrentAgentId = message.CurrentAgentId,
Content = obj.ReportSummary,
Indication = "Summarizing",
FunctionName = message.FunctionName,
FunctionArgs = message.FunctionArgs,
Expand Down
Loading