reset message wrapper and fix path error
This commit is contained in:
parent
9fb6d9fd38
commit
2e524d5f28
|
|
@ -31,11 +31,17 @@ public partial class LocalFileStorageService
|
||||||
|
|
||||||
public BinaryData GetSpeechFile(string conversationId, string fileName)
|
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);
|
var path = Path.Combine(_baseDir, CONVERSATION_FOLDER, conversationId, TEXT_TO_SPEECH_FOLDER, fileName);
|
||||||
if (!File.Exists(path))
|
if (!File.Exists(path))
|
||||||
{
|
{
|
||||||
return BinaryData.Empty;
|
return BinaryData.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
using var fs = new FileStream(path, FileMode.Open, FileAccess.Read);
|
using var fs = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||||
return BinaryData.FromStream(fs);
|
return BinaryData.FromStream(fs);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,16 +19,30 @@ public partial class LocalFileStorageService
|
||||||
|
|
||||||
foreach (var messageId in messageIds)
|
foreach (var messageId in messageIds)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(messageId))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var dir = Path.Combine(pathPrefix, messageId, FileSourceType.User);
|
var dir = Path.Combine(pathPrefix, messageId, FileSourceType.User);
|
||||||
if (!ExistDirectory(dir)) continue;
|
if (!ExistDirectory(dir))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var subDir in Directory.GetDirectories(dir))
|
foreach (var subDir in Directory.GetDirectories(dir))
|
||||||
{
|
{
|
||||||
var file = Directory.GetFiles(subDir).FirstOrDefault();
|
var file = Directory.GetFiles(subDir).FirstOrDefault();
|
||||||
if (file == null) continue;
|
if (file == null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var screenshots = await GetScreenshots(file, subDir, messageId, source);
|
var screenshots = await GetScreenshots(file, subDir, messageId, source);
|
||||||
if (screenshots.IsNullOrEmpty()) continue;
|
if (screenshots.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
files.AddRange(screenshots);
|
files.AddRange(screenshots);
|
||||||
}
|
}
|
||||||
|
|
@ -41,10 +55,18 @@ public partial class LocalFileStorageService
|
||||||
string source, IEnumerable<string>? contentTypes = null)
|
string source, IEnumerable<string>? contentTypes = null)
|
||||||
{
|
{
|
||||||
var files = new List<MessageFileModel>();
|
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)
|
foreach (var messageId in messageIds)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(messageId))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var dir = Path.Combine(_baseDir, CONVERSATION_FOLDER, conversationId, FILE_FOLDER, messageId, source);
|
var dir = Path.Combine(_baseDir, CONVERSATION_FOLDER, conversationId, FILE_FOLDER, messageId, source);
|
||||||
if (!ExistDirectory(dir))
|
if (!ExistDirectory(dir))
|
||||||
{
|
{
|
||||||
|
|
@ -85,6 +107,14 @@ public partial class LocalFileStorageService
|
||||||
|
|
||||||
public string GetMessageFile(string conversationId, string messageId, string source, string index, string fileName)
|
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);
|
var dir = Path.Combine(_baseDir, CONVERSATION_FOLDER, conversationId, FILE_FOLDER, messageId, source, index);
|
||||||
if (!ExistDirectory(dir))
|
if (!ExistDirectory(dir))
|
||||||
{
|
{
|
||||||
|
|
@ -98,10 +128,18 @@ public partial class LocalFileStorageService
|
||||||
public IEnumerable<MessageFileModel> GetMessagesWithFile(string conversationId, IEnumerable<string> messageIds)
|
public IEnumerable<MessageFileModel> GetMessagesWithFile(string conversationId, IEnumerable<string> messageIds)
|
||||||
{
|
{
|
||||||
var foundMsgs = new List<MessageFileModel>();
|
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)
|
foreach (var messageId in messageIds)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(messageId))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var prefix = Path.Combine(_baseDir, CONVERSATION_FOLDER, conversationId, FILE_FOLDER, messageId);
|
var prefix = Path.Combine(_baseDir, CONVERSATION_FOLDER, conversationId, FILE_FOLDER, messageId);
|
||||||
var userDir = Path.Combine(prefix, FileSourceType.User);
|
var userDir = Path.Combine(prefix, FileSourceType.User);
|
||||||
if (ExistDirectory(userDir))
|
if (ExistDirectory(userDir))
|
||||||
|
|
@ -121,7 +159,17 @@ public partial class LocalFileStorageService
|
||||||
|
|
||||||
public bool SaveMessageFiles(string conversationId, string messageId, string source, List<FileDataModel> files)
|
public bool SaveMessageFiles(string conversationId, string messageId, string source, List<FileDataModel> files)
|
||||||
{
|
{
|
||||||
if (files.IsNullOrEmpty()) return false;
|
if (files.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(conversationId)
|
||||||
|
|| string.IsNullOrWhiteSpace(messageId)
|
||||||
|
|| string.IsNullOrWhiteSpace(source))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
var dir = GetConversationFileDirectory(conversationId, messageId, createNewDir: true);
|
var dir = GetConversationFileDirectory(conversationId, messageId, createNewDir: true);
|
||||||
if (!ExistDirectory(dir)) return false;
|
if (!ExistDirectory(dir)) return false;
|
||||||
|
|
@ -164,7 +212,10 @@ public partial class LocalFileStorageService
|
||||||
|
|
||||||
public bool DeleteMessageFiles(string conversationId, IEnumerable<string> messageIds, string targetMessageId, string? newMessageId = null)
|
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))
|
if (!string.IsNullOrEmpty(targetMessageId) && !string.IsNullOrEmpty(newMessageId))
|
||||||
{
|
{
|
||||||
|
|
@ -192,7 +243,10 @@ public partial class LocalFileStorageService
|
||||||
foreach (var messageId in messageIds)
|
foreach (var messageId in messageIds)
|
||||||
{
|
{
|
||||||
var dir = GetConversationFileDirectory(conversationId, messageId);
|
var dir = GetConversationFileDirectory(conversationId, messageId);
|
||||||
if (!ExistDirectory(dir)) continue;
|
if (!ExistDirectory(dir))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
DeleteDirectory(dir);
|
DeleteDirectory(dir);
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
|
|
@ -203,12 +257,18 @@ public partial class LocalFileStorageService
|
||||||
|
|
||||||
public bool DeleteConversationFiles(IEnumerable<string> conversationIds)
|
public bool DeleteConversationFiles(IEnumerable<string> conversationIds)
|
||||||
{
|
{
|
||||||
if (conversationIds.IsNullOrEmpty()) return false;
|
if (conversationIds.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var conversationId in conversationIds)
|
foreach (var conversationId in conversationIds)
|
||||||
{
|
{
|
||||||
var convDir = GetConversationDirectory(conversationId);
|
var convDir = GetConversationDirectory(conversationId);
|
||||||
if (!ExistDirectory(convDir)) continue;
|
if (!ExistDirectory(convDir))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
DeleteDirectory(convDir);
|
DeleteDirectory(convDir);
|
||||||
}
|
}
|
||||||
|
|
@ -241,7 +301,10 @@ public partial class LocalFileStorageService
|
||||||
|
|
||||||
private IEnumerable<string> GetMessageIds(IEnumerable<RoleDialogModel> dialogs, int? offset = null)
|
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)
|
if (offset.HasValue && offset < 1)
|
||||||
{
|
{
|
||||||
|
|
@ -264,13 +327,17 @@ public partial class LocalFileStorageService
|
||||||
private async Task<IEnumerable<string>> ConvertPdfToImages(string pdfLoc, string imageLoc)
|
private async Task<IEnumerable<string>> ConvertPdfToImages(string pdfLoc, string imageLoc)
|
||||||
{
|
{
|
||||||
var converters = _services.GetServices<IPdf2ImageConverter>();
|
var converters = _services.GetServices<IPdf2ImageConverter>();
|
||||||
if (converters.IsNullOrEmpty()) return Enumerable.Empty<string>();
|
if (converters.IsNullOrEmpty())
|
||||||
|
{
|
||||||
|
return Enumerable.Empty<string>();
|
||||||
|
}
|
||||||
|
|
||||||
var converter = GetPdf2ImageConverter();
|
var converter = GetPdf2ImageConverter();
|
||||||
if (converter == null)
|
if (converter == null)
|
||||||
{
|
{
|
||||||
return Enumerable.Empty<string>();
|
return Enumerable.Empty<string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
return await converter.ConvertPdfToImages(pdfLoc, imageLoc);
|
return await converter.ConvertPdfToImages(pdfLoc, imageLoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@ public partial class RoutingService
|
||||||
message.Indication = response.Indication;
|
message.Indication = response.Indication;
|
||||||
message.CurrentAgentId = agent.Id;
|
message.CurrentAgentId = agent.Id;
|
||||||
message.IsStreaming = response.IsStreaming;
|
message.IsStreaming = response.IsStreaming;
|
||||||
|
message.AdditionalMessageWrapper = null;
|
||||||
|
|
||||||
await InvokeFunction(message, dialogs, options);
|
await InvokeFunction(message, dialogs, options);
|
||||||
}
|
}
|
||||||
|
|
@ -74,6 +75,7 @@ public partial class RoutingService
|
||||||
message = RoleDialogModel.From(message, role: AgentRole.Assistant, content: response.Content);
|
message = RoleDialogModel.From(message, role: AgentRole.Assistant, content: response.Content);
|
||||||
message.CurrentAgentId = agent.Id;
|
message.CurrentAgentId = agent.Id;
|
||||||
message.IsStreaming = response.IsStreaming;
|
message.IsStreaming = response.IsStreaming;
|
||||||
|
message.AdditionalMessageWrapper = null;
|
||||||
dialogs.Add(message);
|
dialogs.Add(message);
|
||||||
Context.SetDialogs(dialogs);
|
Context.SetDialogs(dialogs);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,12 +76,10 @@ public class PlotChartFn : IFunctionCallback
|
||||||
SaveToDb = true,
|
SaveToDb = true,
|
||||||
Messages = new List<RoleDialogModel>
|
Messages = new List<RoleDialogModel>
|
||||||
{
|
{
|
||||||
new()
|
new(AgentRole.Assistant, obj.ReportSummary)
|
||||||
{
|
{
|
||||||
Role = AgentRole.Assistant,
|
|
||||||
MessageId = message.MessageId,
|
MessageId = message.MessageId,
|
||||||
CurrentAgentId = message.CurrentAgentId,
|
CurrentAgentId = message.CurrentAgentId,
|
||||||
Content = obj.ReportSummary,
|
|
||||||
Indication = "Summarizing",
|
Indication = "Summarizing",
|
||||||
FunctionName = message.FunctionName,
|
FunctionName = message.FunctionName,
|
||||||
FunctionArgs = message.FunctionArgs,
|
FunctionArgs = message.FunctionArgs,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue