mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-06-27 13:16:26 +00:00
added a reader of context relevant files from embedded resources
This commit is contained in:
parent
37271d65b1
commit
d5881225e2
@ -1,9 +1,12 @@
|
||||
using AIStudio.Dialogs.Settings;
|
||||
using System.Text;
|
||||
using AIStudio.Dialogs.Settings;
|
||||
|
||||
namespace AIStudio.Assistants.Meta;
|
||||
|
||||
public partial class AssistantMetaAssistant : AssistantBaseCore<NoSettingsPanel>
|
||||
{
|
||||
private static readonly ILogger LOGGER = Program.LOGGER_FACTORY.CreateLogger(nameof(AssistantMetaAssistant));
|
||||
|
||||
protected override Tools.Components Component => Tools.Components.META_ASSISTANT;
|
||||
protected override string Title => T("Assistant Builder");
|
||||
protected override string Description => string.Empty;
|
||||
@ -18,6 +21,8 @@ public partial class AssistantMetaAssistant : AssistantBaseCore<NoSettingsPanel>
|
||||
protected override bool HasSettingsPanel { get; }
|
||||
|
||||
private bool isAgentRunning;
|
||||
private AssistantCategory selectedCategory;
|
||||
private string customCategory = string.Empty;
|
||||
private static readonly AssistantContextFile[] ASSISTANT_CONTEXT_FILES =
|
||||
[
|
||||
new("Assistant plugin schema", "Plugins/assistants/README.md", IsRequired: true),
|
||||
@ -28,39 +33,66 @@ public partial class AssistantMetaAssistant : AssistantBaseCore<NoSettingsPanel>
|
||||
string Title,
|
||||
string RelativePath,
|
||||
bool IsRequired);
|
||||
|
||||
|
||||
#region Overrides of ComponentBase
|
||||
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
protected override void ResetForm()
|
||||
{
|
||||
return;
|
||||
this.selectedCategory = AssistantCategory.AS_IS;
|
||||
this.customCategory = string.Empty;
|
||||
}
|
||||
|
||||
protected override bool MightPreselectValues()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private string AssembleSystemPrompt() => string.Empty;
|
||||
|
||||
private string? ValidatingCategory(AssistantCategory category)
|
||||
{
|
||||
if(category is AssistantCategory.AS_IS)
|
||||
return T("Please select an assistant category.");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateCustomCategory(string category)
|
||||
{
|
||||
if(this.selectedCategory is AssistantCategory.OTHER && string.IsNullOrWhiteSpace(category))
|
||||
return T("Please provide a custom category.");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private async Task GenerateLuaAssistant()
|
||||
{
|
||||
await this.Form!.Validate();
|
||||
if (!this.InputIsValid)
|
||||
return;
|
||||
|
||||
this.CreateChatThread();
|
||||
var time = this.AddUserRequest(
|
||||
$"""
|
||||
Assistant category: {this.GetSelectedCategoryName()}
|
||||
|
||||
Remind me to replace this placeholder with the real lua plugin context
|
||||
""");
|
||||
|
||||
|
||||
await this.AddAIResponseAsync(time);
|
||||
}
|
||||
|
||||
private string GetSelectedCategoryName() => this.selectedCategory is AssistantCategory.OTHER
|
||||
? this.customCategory
|
||||
: this.selectedCategory.Name();
|
||||
|
||||
private static async Task<string> ReadAppResourceTextAsync(string relativePath)
|
||||
{
|
||||
relativePath = relativePath.Replace('\\', '/');
|
||||
@ -80,4 +112,34 @@ public partial class AssistantMetaAssistant : AssistantBaseCore<NoSettingsPanel>
|
||||
return await reader.ReadToEndAsync();
|
||||
#endif
|
||||
}
|
||||
|
||||
private async Task<string> LoadAssistantBuilderContextAsync()
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
|
||||
foreach (var contextFile in ASSISTANT_CONTEXT_FILES)
|
||||
{
|
||||
var content = await ReadAppResourceTextAsync(contextFile.RelativePath);
|
||||
if (string.IsNullOrWhiteSpace(content))
|
||||
{
|
||||
LOGGER.LogError($"The context for \"{contextFile.Title}\" could not be read from the assembly. Path: {contextFile.RelativePath}");
|
||||
if (contextFile.IsRequired)
|
||||
{
|
||||
await MessageBus.INSTANCE.SendError(new (Icons.Material.Filled.SettingsSuggest, string.Format(T("The Assistant-Builder was not able to read the plugin manifest and therefore cannot safely generate your assistant right now."))));
|
||||
this.isAgentRunning = true;
|
||||
return string.Empty;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
builder.AppendLine($"# {contextFile.Title}");
|
||||
builder.AppendLine($"Source: {contextFile.RelativePath}");
|
||||
builder.AppendLine("<context>");
|
||||
builder.AppendLine(content.Trim());
|
||||
builder.AppendLine("</context>");
|
||||
builder.AppendLine();
|
||||
}
|
||||
|
||||
return builder.ToString().Trim();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user