Added a function to load a text file

This commit is contained in:
Thorsten Sommer 2025-03-29 18:55:30 +01:00
parent b632854cd4
commit 01eb99096e
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
2 changed files with 22 additions and 0 deletions

View File

@ -8,6 +8,9 @@
<PreviewExperimental ApplyInnerScrollingFix="true"/> <PreviewExperimental ApplyInnerScrollingFix="true"/>
<ProviderSelection @bind-ProviderSettings="@this.providerSettings"/> <ProviderSelection @bind-ProviderSettings="@this.providerSettings"/>
<MudButton Variant="Variant.Filled" StartIcon="@Icons.Material.Filled.Download" OnClick="@(() => this.LoadTextFile())" Color="Color.Primary" Class="mb-2">
Load a text file
</MudButton>
<InnerScrolling> <InnerScrolling>
<ChildContent> <ChildContent>
<MudTextField <MudTextField

View File

@ -1,6 +1,9 @@
using System.Text;
using AIStudio.Chat; using AIStudio.Chat;
using AIStudio.Components; using AIStudio.Components;
using AIStudio.Provider; using AIStudio.Provider;
using AIStudio.Tools.Services;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.Web;
@ -14,6 +17,9 @@ public partial class Writer : MSGComponentBase, IAsyncDisposable
[Inject] [Inject]
private ILogger<Chat> Logger { get; init; } = null!; private ILogger<Chat> Logger { get; init; } = null!;
[Inject]
private RustService RustService { get; init; } = null!;
private static readonly Dictionary<string, object?> USER_INPUT_ATTRIBUTES = new(); private static readonly Dictionary<string, object?> USER_INPUT_ATTRIBUTES = new();
private readonly Timer typeTimer = new(TimeSpan.FromMilliseconds(1_500)); private readonly Timer typeTimer = new(TimeSpan.FromMilliseconds(1_500));
@ -56,6 +62,19 @@ public partial class Writer : MSGComponentBase, IAsyncDisposable
#endregion #endregion
private bool IsProviderSelected => this.providerSettings.UsedLLMProvider != LLMProviders.NONE; private bool IsProviderSelected => this.providerSettings.UsedLLMProvider != LLMProviders.NONE;
private async Task LoadTextFile()
{
var result = await this.RustService.SelectFile("Load a text file");
if(result.UserCancelled)
return;
if(!File.Exists(result.SelectedFilePath))
return;
var text = await File.ReadAllTextAsync(result.SelectedFilePath, Encoding.UTF8);
this.userInput = text;
}
private async Task InputKeyEvent(KeyboardEventArgs keyEvent) private async Task InputKeyEvent(KeyboardEventArgs keyEvent)
{ {