mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-06-27 17:16:28 +00:00
fixed issues with stored paths in chat templates
This commit is contained in:
parent
e49973497c
commit
63c9be044a
@ -7309,6 +7309,9 @@ UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::FILEEXTENSIONVALIDATION::T29806295
|
|||||||
-- Images are not supported at this place
|
-- Images are not supported at this place
|
||||||
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::FILEEXTENSIONVALIDATION::T305247150"] = "Images are not supported at this place"
|
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::FILEEXTENSIONVALIDATION::T305247150"] = "Images are not supported at this place"
|
||||||
|
|
||||||
|
-- Unsupported file type
|
||||||
|
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::FILEEXTENSIONVALIDATION::T4041351522"] = "Unsupported file type"
|
||||||
|
|
||||||
-- Executables are not allowed
|
-- Executables are not allowed
|
||||||
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::FILEEXTENSIONVALIDATION::T4167762413"] = "Executables are not allowed"
|
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::FILEEXTENSIONVALIDATION::T4167762413"] = "Executables are not allowed"
|
||||||
|
|
||||||
|
|||||||
@ -229,11 +229,15 @@ public sealed class ContentText : IContent
|
|||||||
|
|
||||||
if(this.FileAttachments.Count > 0)
|
if(this.FileAttachments.Count > 0)
|
||||||
{
|
{
|
||||||
|
var normalizedAttachments = this.FileAttachments
|
||||||
|
.Select(attachment => attachment.Normalize())
|
||||||
|
.ToList();
|
||||||
|
|
||||||
// Get the list of existing documents:
|
// Get the list of existing documents:
|
||||||
var existingDocuments = this.FileAttachments.Where(x => x.Type is FileAttachmentType.DOCUMENT && x.Exists).ToList();
|
var existingDocuments = normalizedAttachments.Where(x => x.Type is FileAttachmentType.DOCUMENT && x.Exists).ToList();
|
||||||
|
|
||||||
// Log warning for missing files:
|
// Log warning for missing files:
|
||||||
var missingDocuments = this.FileAttachments.Except(existingDocuments).Where(x => x.Type is FileAttachmentType.DOCUMENT).ToList();
|
var missingDocuments = normalizedAttachments.Except(existingDocuments).Where(x => x.Type is FileAttachmentType.DOCUMENT).ToList();
|
||||||
if (missingDocuments.Count > 0)
|
if (missingDocuments.Count > 0)
|
||||||
foreach (var missingDocument in missingDocuments)
|
foreach (var missingDocument in missingDocuments)
|
||||||
LOGGER.LogWarning("File attachment no longer exists and will be skipped: '{MissingDocument}'.", missingDocument.FilePath);
|
LOGGER.LogWarning("File attachment no longer exists and will be skipped: '{MissingDocument}'.", missingDocument.FilePath);
|
||||||
@ -269,7 +273,7 @@ public sealed class ContentText : IContent
|
|||||||
sb.AppendLine("````");
|
sb.AppendLine("````");
|
||||||
}
|
}
|
||||||
|
|
||||||
var numImages = this.FileAttachments.Count(x => x is { IsImage: true, Exists: true });
|
var numImages = normalizedAttachments.Count(x => x is { IsImage: true, Exists: true });
|
||||||
if (numImages > 0)
|
if (numImages > 0)
|
||||||
{
|
{
|
||||||
sb.AppendLine();
|
sb.AppendLine();
|
||||||
|
|||||||
@ -53,6 +53,11 @@ public record FileAttachment(FileAttachmentType Type, string FileName, string Fi
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
public bool Exists => File.Exists(this.FilePath);
|
public bool Exists => File.Exists(this.FilePath);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Rebuilds the attachment from its current file path so file type detection uses the latest rules.
|
||||||
|
/// </summary>
|
||||||
|
public FileAttachment Normalize() => FromPath(this.FilePath);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a FileAttachment from a file path by automatically determining the type,
|
/// Creates a FileAttachment from a file path by automatically determining the type,
|
||||||
/// extracting the filename, and reading the file size.
|
/// extracting the filename, and reading the file size.
|
||||||
|
|||||||
@ -94,7 +94,7 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
|||||||
|
|
||||||
// Apply template's file attachments, if any:
|
// Apply template's file attachments, if any:
|
||||||
foreach (var attachment in this.currentChatTemplate.FileAttachments)
|
foreach (var attachment in this.currentChatTemplate.FileAttachments)
|
||||||
this.chatDocumentPaths.Add(attachment);
|
this.chatDocumentPaths.Add(attachment.Normalize());
|
||||||
|
|
||||||
//
|
//
|
||||||
// Check for deferred messages of the kind 'SEND_TO_CHAT',
|
// Check for deferred messages of the kind 'SEND_TO_CHAT',
|
||||||
@ -392,7 +392,7 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
|||||||
// Apply template's file attachments (replaces existing):
|
// Apply template's file attachments (replaces existing):
|
||||||
this.chatDocumentPaths.Clear();
|
this.chatDocumentPaths.Clear();
|
||||||
foreach (var attachment in this.currentChatTemplate.FileAttachments)
|
foreach (var attachment in this.currentChatTemplate.FileAttachments)
|
||||||
this.chatDocumentPaths.Add(attachment);
|
this.chatDocumentPaths.Add(attachment.Normalize());
|
||||||
|
|
||||||
if(this.ChatThread is null)
|
if(this.ChatThread is null)
|
||||||
return;
|
return;
|
||||||
@ -538,10 +538,15 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
|||||||
IContent? lastUserPrompt;
|
IContent? lastUserPrompt;
|
||||||
if (!reuseLastUserPrompt)
|
if (!reuseLastUserPrompt)
|
||||||
{
|
{
|
||||||
|
var normalizedAttachments = this.chatDocumentPaths
|
||||||
|
.Select(attachment => attachment.Normalize())
|
||||||
|
.Where(attachment => attachment.IsValid)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
lastUserPrompt = new ContentText
|
lastUserPrompt = new ContentText
|
||||||
{
|
{
|
||||||
Text = this.userInput,
|
Text = this.userInput,
|
||||||
FileAttachments = [..this.chatDocumentPaths.Where(x => x.IsValid)],
|
FileAttachments = normalizedAttachments,
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -764,7 +769,7 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
|||||||
// Apply template's file attachments:
|
// Apply template's file attachments:
|
||||||
this.chatDocumentPaths.Clear();
|
this.chatDocumentPaths.Clear();
|
||||||
foreach (var attachment in this.currentChatTemplate.FileAttachments)
|
foreach (var attachment in this.currentChatTemplate.FileAttachments)
|
||||||
this.chatDocumentPaths.Add(attachment);
|
this.chatDocumentPaths.Add(attachment.Normalize());
|
||||||
|
|
||||||
// Now, we have to reset the data source options as well:
|
// Now, we have to reset the data source options as well:
|
||||||
this.ApplyStandardDataSourceOptions();
|
this.ApplyStandardDataSourceOptions();
|
||||||
|
|||||||
@ -133,7 +133,7 @@ public partial class ChatTemplateDialog : MSGComponentBase
|
|||||||
SystemPrompt = this.DataSystemPrompt,
|
SystemPrompt = this.DataSystemPrompt,
|
||||||
PredefinedUserPrompt = this.PredefinedUserPrompt,
|
PredefinedUserPrompt = this.PredefinedUserPrompt,
|
||||||
ExampleConversation = this.dataExampleConversation,
|
ExampleConversation = this.dataExampleConversation,
|
||||||
FileAttachments = [..this.fileAttachments],
|
FileAttachments = this.fileAttachments.Select(attachment => attachment.Normalize()).ToList(),
|
||||||
AllowProfileUsage = this.AllowProfileUsage,
|
AllowProfileUsage = this.AllowProfileUsage,
|
||||||
|
|
||||||
EnterpriseConfigurationPluginId = Guid.Empty,
|
EnterpriseConfigurationPluginId = Guid.Empty,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user