mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-02-12 20:01:37 +00:00
Refactor file attachment handling to skip forbidden file types in DocumentAnalysisAssistant, ContentText, and ChatComponent
This commit is contained in:
parent
cca5c4d3a4
commit
ca76da65f2
@ -332,6 +332,12 @@ public partial class DocumentAnalysisAssistant : AssistantBaseCore<SettingsDialo
|
||||
|
||||
foreach (var fileAttachment in this.loadedDocumentPaths)
|
||||
{
|
||||
if (fileAttachment.IsForbidden)
|
||||
{
|
||||
this.Logger.LogWarning($"Skipping forbidden file: '{fileAttachment.FilePath}'.");
|
||||
continue;
|
||||
}
|
||||
|
||||
var fileContent = await this.RustService.ReadArbitraryFileData(fileAttachment.FilePath, int.MaxValue);
|
||||
|
||||
documentSections.Add($"""
|
||||
|
||||
@ -165,8 +165,11 @@ public sealed class ContentText : IContent
|
||||
foreach (var missingFile in missingFiles)
|
||||
LOGGER.LogWarning("File attachment no longer exists and will be skipped: '{MissingFile}'.", missingFile.FilePath);
|
||||
|
||||
// Only proceed if there are existing files
|
||||
if (existingFiles.Count > 0)
|
||||
// Determine allowed attachments:
|
||||
var numberAllowedExistingFiles = existingFiles.Count(x => x.IsValid);
|
||||
|
||||
// Only proceed if there are existing, allowed files:
|
||||
if (numberAllowedExistingFiles > 0)
|
||||
{
|
||||
// Check Pandoc availability once before processing file attachments
|
||||
var pandocState = await Pandoc.CheckAvailabilityAsync(Program.RUST_SERVICE, showMessages: true, showSuccessMessage: false);
|
||||
@ -181,6 +184,12 @@ public sealed class ContentText : IContent
|
||||
sb.AppendLine("The following files are attached to this message:");
|
||||
foreach(var file in existingFiles)
|
||||
{
|
||||
if (file.IsForbidden)
|
||||
{
|
||||
LOGGER.LogWarning("File attachment '{FilePath}' has a forbidden file type and will be skipped.", file.FilePath);
|
||||
continue;
|
||||
}
|
||||
|
||||
sb.AppendLine();
|
||||
sb.AppendLine("---------------------------------------");
|
||||
sb.AppendLine($"File path: {file.FilePath}");
|
||||
|
||||
@ -464,7 +464,7 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
||||
lastUserPrompt = new ContentText
|
||||
{
|
||||
Text = this.userInput,
|
||||
FileAttachments = [..this.chatDocumentPaths],
|
||||
FileAttachments = [..this.chatDocumentPaths.Where(x => x.IsValid)],
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
Loading…
Reference in New Issue
Block a user