mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-02-14 20:41:37 +00:00
Refactor AttachDocuments and ChatComponent to use FileAttachment type for improved handling and consistency
This commit is contained in:
parent
69c3e490d7
commit
26d963de23
@ -68,9 +68,9 @@ else
|
|||||||
</MudStack>
|
</MudStack>
|
||||||
<div @onmouseenter="@this.OnMouseEnter" @onmouseleave="@this.OnMouseLeave">
|
<div @onmouseenter="@this.OnMouseEnter" @onmouseleave="@this.OnMouseLeave">
|
||||||
<MudPaper Height="20em" Outlined="true" Class="@this.dragClass" Style="overflow-y: auto;">
|
<MudPaper Height="20em" Outlined="true" Class="@this.dragClass" Style="overflow-y: auto;">
|
||||||
@foreach (var filePath in this.DocumentPaths)
|
@foreach (var fileAttachment in this.DocumentPaths)
|
||||||
{
|
{
|
||||||
<MudChip T="string" Color="Color.Dark" Text="@Path.GetFileName(filePath)" tabindex="-1" Icon="@Icons.Material.Filled.Search" OnClick="@(() => this.InvestigateFile(filePath))" OnClose="@(() => this.RemoveDocument(filePath))"/>
|
<MudChip T="string" Color="Color.Dark" Text="@fileAttachment.FileName" tabindex="-1" Icon="@Icons.Material.Filled.Search" OnClick="@(() => this.InvestigateFile(fileAttachment))" OnClose="@(() => this.RemoveDocument(fileAttachment))"/>
|
||||||
}
|
}
|
||||||
</MudPaper>
|
</MudPaper>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
using AIStudio.Chat;
|
||||||
using AIStudio.Dialogs;
|
using AIStudio.Dialogs;
|
||||||
using AIStudio.Tools.PluginSystem;
|
using AIStudio.Tools.PluginSystem;
|
||||||
using AIStudio.Tools.Rust;
|
using AIStudio.Tools.Rust;
|
||||||
@ -16,15 +17,15 @@ public partial class AttachDocuments : MSGComponentBase
|
|||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public string Name { get; set; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public HashSet<string> DocumentPaths { get; set; } = [];
|
public HashSet<FileAttachment> DocumentPaths { get; set; } = [];
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public EventCallback<HashSet<string>> DocumentPathsChanged { get; set; }
|
public EventCallback<HashSet<FileAttachment>> DocumentPathsChanged { get; set; }
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public Func<HashSet<string>, Task> OnChange { get; set; } = _ => Task.CompletedTask;
|
public Func<HashSet<FileAttachment>, Task> OnChange { get; set; } = _ => Task.CompletedTask;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Catch all documents that are hovered over the AI Studio window and not only over the drop zone.
|
/// Catch all documents that are hovered over the AI Studio window and not only over the drop zone.
|
||||||
@ -116,7 +117,7 @@ public partial class AttachDocuments : MSGComponentBase
|
|||||||
if(!await FileExtensionValidation.IsExtensionValidWithNotifyAsync(path))
|
if(!await FileExtensionValidation.IsExtensionValidWithNotifyAsync(path))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
this.DocumentPaths.Add(path);
|
this.DocumentPaths.Add(FileAttachment.FromPath(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.DocumentPathsChanged.InvokeAsync(this.DocumentPaths);
|
await this.DocumentPathsChanged.InvokeAsync(this.DocumentPaths);
|
||||||
@ -160,7 +161,7 @@ public partial class AttachDocuments : MSGComponentBase
|
|||||||
if (!await FileExtensionValidation.IsExtensionValidWithNotifyAsync(selectedFilePath))
|
if (!await FileExtensionValidation.IsExtensionValidWithNotifyAsync(selectedFilePath))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
this.DocumentPaths.Add(selectedFilePath);
|
this.DocumentPaths.Add(FileAttachment.FromPath(selectedFilePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.DocumentPathsChanged.InvokeAsync(this.DocumentPaths);
|
await this.DocumentPathsChanged.InvokeAsync(this.DocumentPaths);
|
||||||
@ -199,23 +200,23 @@ public partial class AttachDocuments : MSGComponentBase
|
|||||||
this.StateHasChanged();
|
this.StateHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task RemoveDocument(string filePath)
|
private async Task RemoveDocument(FileAttachment fileAttachment)
|
||||||
{
|
{
|
||||||
this.DocumentPaths.Remove(filePath);
|
this.DocumentPaths.Remove(fileAttachment);
|
||||||
|
|
||||||
await this.DocumentPathsChanged.InvokeAsync(this.DocumentPaths);
|
await this.DocumentPathsChanged.InvokeAsync(this.DocumentPaths);
|
||||||
await this.OnChange(this.DocumentPaths);
|
await this.OnChange(this.DocumentPaths);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The user might want to check what we actually extract from his file and therefore give the LLM as an input.
|
/// The user might want to check what we actually extract from his file and therefore give the LLM as an input.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filePath">The file to check.</param>
|
/// <param name="fileAttachment">The file to check.</param>
|
||||||
private async Task InvestigateFile(string filePath)
|
private async Task InvestigateFile(FileAttachment fileAttachment)
|
||||||
{
|
{
|
||||||
var dialogParameters = new DialogParameters<DocumentCheckDialog>
|
var dialogParameters = new DialogParameters<DocumentCheckDialog>
|
||||||
{
|
{
|
||||||
{ x => x.FilePath, filePath },
|
{ x => x.FilePath, fileAttachment.FilePath },
|
||||||
};
|
};
|
||||||
|
|
||||||
await this.DialogService.ShowAsync<DocumentCheckDialog>(T("Document Preview"), dialogParameters, DialogOptions.FULLSCREEN);
|
await this.DialogService.ShowAsync<DocumentCheckDialog>(T("Document Preview"), dialogParameters, DialogOptions.FULLSCREEN);
|
||||||
|
|||||||
@ -57,7 +57,7 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
|||||||
private string currentWorkspaceName = string.Empty;
|
private string currentWorkspaceName = string.Empty;
|
||||||
private Guid currentWorkspaceId = Guid.Empty;
|
private Guid currentWorkspaceId = Guid.Empty;
|
||||||
private CancellationTokenSource? cancellationTokenSource;
|
private CancellationTokenSource? cancellationTokenSource;
|
||||||
private HashSet<string> chatDocumentPaths = [];
|
private HashSet<FileAttachment> chatDocumentPaths = [];
|
||||||
|
|
||||||
// Unfortunately, we need the input field reference to blur the focus away. Without
|
// Unfortunately, we need the input field reference to blur the focus away. Without
|
||||||
// this, we cannot clear the input field.
|
// this, we cannot clear the input field.
|
||||||
@ -464,7 +464,7 @@ public partial class ChatComponent : MSGComponentBase, IAsyncDisposable
|
|||||||
lastUserPrompt = new ContentText
|
lastUserPrompt = new ContentText
|
||||||
{
|
{
|
||||||
Text = this.userInput,
|
Text = this.userInput,
|
||||||
FileAttachments = this.chatDocumentPaths.ToList(),
|
FileAttachments = [..this.chatDocumentPaths],
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user