mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-10 15:47:21 +00:00
Fixed dropping a custom prompt guide into the Prompt Optimizer (#1163)
This commit is contained in:
1 parent
9c98bdae86
commit
a3d38c5db4
7 files changed
+49
-49
No files matched your search
@@ -2311,6 +2311,9 @@ UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::PROMPTOPTIMIZER::ASSISTANTPROMPTOPTIMIZER
|
||||
-- Custom language
|
||||
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::PROMPTOPTIMIZER::ASSISTANTPROMPTOPTIMIZER::T3032662264"] = "Custom language"
|
||||
|
||||
-- Load the prompt guide from file
|
||||
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::PROMPTOPTIMIZER::ASSISTANTPROMPTOPTIMIZER::T3415232006"] = "Load the prompt guide from file"
|
||||
|
||||
-- Give the model a role
|
||||
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::PROMPTOPTIMIZER::ASSISTANTPROMPTOPTIMIZER::T3420218291"] = "Give the model a role"
|
||||
|
||||
|
||||
@@ -95,17 +95,6 @@
|
||||
@T("Use custom prompt guide")
|
||||
</MudSwitch>
|
||||
|
||||
@if (this.useCustomPromptGuide)
|
||||
{
|
||||
<AttachDocuments Name="Custom Prompt Guide"
|
||||
@bind-DocumentPaths="@this.customPromptGuideFiles"
|
||||
OnChange="@this.OnCustomPromptGuideFilesChanged"
|
||||
CatchAllDocuments="false"
|
||||
UseSmallForm="true"
|
||||
ValidateMediaFileTypes="false"
|
||||
Provider="@this.ProviderSettings"/>
|
||||
}
|
||||
|
||||
<MudTextField T="string"
|
||||
Text="@this.CustomPromptGuideFileName"
|
||||
Label="@T("Custom prompt guide file")"
|
||||
@@ -123,4 +112,13 @@
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
|
||||
@if (this.useCustomPromptGuide)
|
||||
{
|
||||
<ReadFileContent Text="@T("Load the prompt guide from file")"
|
||||
@bind-FileContent="@this.customPromptingGuidelineContent"
|
||||
FilePathLoaded="@this.SetCustomPromptGuideFile"
|
||||
Filter="@CUSTOM_PROMPT_GUIDE_FILE_TYPES"
|
||||
EnableDragDrop="true"/>
|
||||
}
|
||||
|
||||
<ProviderSelection @bind-ProviderSettings="@this.ProviderSettings" ValidateProvider="@this.ValidatingProvider"/>
|
||||
+24
-18
@@ -5,6 +5,7 @@ using AIStudio.Dialogs;
|
||||
using AIStudio.Dialogs.Settings;
|
||||
using AIStudio.Tools.AssistantLaunch;
|
||||
using AIStudio.Tools.AssistantSessions;
|
||||
using AIStudio.Tools.Rust;
|
||||
using AIStudio.Tools.Services;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
@@ -187,6 +188,16 @@ public partial class AssistantPromptOptimizer : AssistantBaseCore<SettingsDialog
|
||||
private string recStructureMarkers = string.Empty;
|
||||
private string recRoleDefinition = string.Empty;
|
||||
private string recLanguageChoice = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The files a custom prompt guide can come from.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Documents only: an audio or a video file would be transcribed, and a transcript reports
|
||||
/// the name of its file rather than the path, which the preview of the guide needs.
|
||||
/// </remarks>
|
||||
private static readonly FileTypeFilter[] CUSTOM_PROMPT_GUIDE_FILE_TYPES = [ FileTypes.DOCUMENT ];
|
||||
|
||||
private static readonly AssistantSessionStateKey<string> INPUT_PROMPT_STATE_KEY = new(nameof(inputPrompt));
|
||||
private static readonly AssistantSessionStateKey<CommonLanguages> SELECTED_TARGET_LANGUAGE_STATE_KEY = new(nameof(selectedTargetLanguage));
|
||||
private static readonly AssistantSessionStateKey<string> CUSTOM_TARGET_LANGUAGE_STATE_KEY = new(nameof(customTargetLanguage));
|
||||
@@ -549,29 +560,24 @@ public partial class AssistantPromptOptimizer : AssistantBaseCore<SettingsDialog
|
||||
await this.LoadCustomPromptGuidelineContentAsync(fileAttachment);
|
||||
}
|
||||
|
||||
private async Task OnCustomPromptGuideFilesChanged(HashSet<FileAttachment> files)
|
||||
/// <summary>
|
||||
/// Takes the file whose content was just loaded as the custom prompt guide.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The content has arrived already, through the binding of ReadFileContent, which reports it
|
||||
/// before the path. A file without readable content never gets here.
|
||||
/// </remarks>
|
||||
/// <param name="filePath">The path of the file which was loaded.</param>
|
||||
private async Task SetCustomPromptGuideFile(string filePath)
|
||||
{
|
||||
if (files.Count == 0)
|
||||
{
|
||||
this.customPromptGuideFiles.Clear();
|
||||
this.currentCustomPromptGuidePath = string.Empty;
|
||||
this.customPromptingGuidelineContent = string.Empty;
|
||||
return;
|
||||
}
|
||||
|
||||
var selected = files.FirstOrDefault(file => !string.Equals(file.FilePath, this.currentCustomPromptGuidePath, StringComparison.OrdinalIgnoreCase))
|
||||
?? files.First();
|
||||
|
||||
var replacedPrevious = !string.IsNullOrWhiteSpace(this.currentCustomPromptGuidePath) &&
|
||||
!string.Equals(this.currentCustomPromptGuidePath, selected.FilePath, StringComparison.OrdinalIgnoreCase);
|
||||
!string.Equals(this.currentCustomPromptGuidePath, filePath, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
this.customPromptGuideFiles = [ selected ];
|
||||
this.currentCustomPromptGuidePath = selected.FilePath;
|
||||
this.customPromptGuideFiles = [ FileAttachment.FromPath(filePath) ];
|
||||
this.currentCustomPromptGuidePath = filePath;
|
||||
|
||||
if (files.Count > 1 || replacedPrevious)
|
||||
if (replacedPrevious)
|
||||
await this.MessageBus.SendInfo(new(Icons.Material.Filled.SwapHoriz, T("Replaced the previously selected custom prompt guide file.")));
|
||||
|
||||
await this.LoadCustomPromptGuidelineContentAsync(selected);
|
||||
}
|
||||
|
||||
private async Task LoadCustomPromptGuidelineContentAsync(FileAttachment fileAttachment)
|
||||
|
||||
@@ -211,23 +211,6 @@ public partial class ReadFileContent : MSGComponentBase
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<bool> EnsurePandocAvailability()
|
||||
{
|
||||
// Ensure that Pandoc is installed and ready:
|
||||
var pandocState = await this.PandocAvailabilityService.EnsureAvailabilityAsync(
|
||||
showSuccessMessage: false,
|
||||
showDialog: true);
|
||||
|
||||
// Check if Pandoc is available after the check / installation:
|
||||
if (!pandocState.IsAvailable)
|
||||
{
|
||||
this.Logger.LogWarning("The user cancelled the Pandoc installation or Pandoc is not available. Aborting file selection.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task LoadFirstValidFile(List<string> paths)
|
||||
{
|
||||
var inaccessiblePaths = paths.Where(path => !File.Exists(path)).ToList();
|
||||
@@ -264,9 +247,11 @@ public partial class ReadFileContent : MSGComponentBase
|
||||
if (FileTypes.IsAllowedPath(filePath, FileTypes.AUDIO) || FileTypes.IsAllowedPath(filePath, FileTypes.VIDEO))
|
||||
return await this.LoadMediaTranscriptAsync(filePath);
|
||||
|
||||
if (!await this.EnsurePandocAvailability())
|
||||
return false;
|
||||
|
||||
//
|
||||
// No Pandoc check here: UserFile.LoadFileData asks for Pandoc itself, and only for the
|
||||
// formats we convert with it. PDFs and the other document types are read by the Rust
|
||||
// runtime, so they must stay loadable without Pandoc.
|
||||
//
|
||||
if (!await FileExtensionValidation.IsExtensionValidWithNotifyAsync(FileExtensionValidation.UseCase.DIRECTLY_LOADING_CONTENT, filePath))
|
||||
{
|
||||
this.Logger.LogWarning("User attempted to load unsupported file: {FilePath}", filePath);
|
||||
|
||||
+3
@@ -2313,6 +2313,9 @@ UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::PROMPTOPTIMIZER::ASSISTANTPROMPTOPTIMIZER
|
||||
-- Custom language
|
||||
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::PROMPTOPTIMIZER::ASSISTANTPROMPTOPTIMIZER::T3032662264"] = "Benutzerdefinierte Sprache"
|
||||
|
||||
-- Load the prompt guide from file
|
||||
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::PROMPTOPTIMIZER::ASSISTANTPROMPTOPTIMIZER::T3415232006"] = "Prompting-Leitfaden aus Datei laden"
|
||||
|
||||
-- Give the model a role
|
||||
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::PROMPTOPTIMIZER::ASSISTANTPROMPTOPTIMIZER::T3420218291"] = "Geben Sie dem Modell eine Rolle"
|
||||
|
||||
|
||||
+3
@@ -2313,6 +2313,9 @@ UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::PROMPTOPTIMIZER::ASSISTANTPROMPTOPTIMIZER
|
||||
-- Custom language
|
||||
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::PROMPTOPTIMIZER::ASSISTANTPROMPTOPTIMIZER::T3032662264"] = "Custom language"
|
||||
|
||||
-- Load the prompt guide from file
|
||||
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::PROMPTOPTIMIZER::ASSISTANTPROMPTOPTIMIZER::T3415232006"] = "Load the prompt guide from file"
|
||||
|
||||
-- Give the model a role
|
||||
UI_TEXT_CONTENT["AISTUDIO::ASSISTANTS::PROMPTOPTIMIZER::ASSISTANTPROMPTOPTIMIZER::T3420218291"] = "Give the model a role"
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
- Fixed the Assistant Builder telling you in English why it could not use the answer of the AI model, even when you chose another language for AI Studio.
|
||||
- Fixed requests to a provider failing when a configuration plugin gave it additional API parameters that contain the same parameter twice. AI Studio now sends the request without these parameters and names the repeated parameter in its log, as it does for other invalid parameters.
|
||||
- Fixed the information page leaving out three libraries that AI Studio uses: MailKit and MimeKit, which read your mailboxes, and the Open XML SDK, with which the Slide Assistant reads and writes PowerPoint files.
|
||||
- Fixed AI Studio asking you to install Pandoc when you load a file as the input of an assistant, although PDF, Word, Markdown, and most other files need no Pandoc.
|
||||
- Fixed dropping a file onto your custom prompt guide in the Prompt Optimizer. Once you switch on "Use custom prompt guide", a marked area appears where you can drop your guide or select it with a button.
|
||||
- Upgraded several libraries to improve security.
|
||||
- Upgraded Tauri to v2.12.5.
|
||||
- Upgraded MudBlazor to v9.12.0.
|
||||
|
||||
Reference in new issue
Block a user