mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-02-12 08:21:37 +00:00
added DynamicAssistantDropdown to accomodate lua structure; included overrides from base Assistant for chat functionality
This commit is contained in:
parent
d37c3f26fb
commit
2afc8c6391
@ -9,19 +9,26 @@
|
||||
case AssistantUiCompontentType.TEXT_AREA:
|
||||
if (component is AssistantTextArea textArea)
|
||||
{
|
||||
<MudTextField T="string" @bind-Text="@this.inputText" Label="@textArea.Label" AdornmentIcon="@Icons.Material.Filled.DocumentScanner" Adornment="Adornment.Start" Variant="Variant.Outlined" Lines="6" AutoGrow="@true" MaxLines="12" Class="mb-3"/>
|
||||
<MudTextField T="string" @bind-Text="@this.inputFields[textArea.Name]" Label="@textArea.Label" AdornmentIcon="@Icons.Material.Filled.DocumentScanner" Adornment="Adornment.Start" Variant="Variant.Outlined" Lines="6" AutoGrow="@true" MaxLines="12" Class="mb-3"/>
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case AssistantUiCompontentType.DROPDOWN:
|
||||
if (component is AssistantDropdown assistantDropdown)
|
||||
{
|
||||
<DynamicAssistantDropdown Items="@assistantDropdown.Items"
|
||||
@bind-Value="@this.selectedTargetLanguage"
|
||||
Default="@assistantDropdown.Default"
|
||||
Label="@assistantDropdown.Label"
|
||||
Icon="@Icons.Material.Filled.Translate"/>
|
||||
}
|
||||
break;
|
||||
|
||||
case AssistantUiCompontentType.PROVIDER_SELECTION:
|
||||
if (component is AssistantProviderSelection providerSelection)
|
||||
{
|
||||
<ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider"/>
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -10,18 +10,26 @@ public partial class AssistantDynamic : AssistantBaseCore<SettingsDialogDynamic>
|
||||
{
|
||||
[Parameter]
|
||||
public AssistantForm? RootComponent { get; set; } = null!;
|
||||
|
||||
protected override string Title => this.title;
|
||||
protected override string Description => this.description;
|
||||
protected override string SystemPrompt => this.systemPrompt;
|
||||
protected override bool AllowProfiles => this.allowProfiles;
|
||||
protected override string SubmitText => this.submitText;
|
||||
protected override Func<Task> SubmitAction => this.Submit;
|
||||
public override Tools.Components Component { get; }
|
||||
|
||||
private string? inputText;
|
||||
private string title = string.Empty;
|
||||
private string description = string.Empty;
|
||||
private string systemPrompt = string.Empty;
|
||||
private bool allowProfiles = true;
|
||||
|
||||
protected override string Title => this.title;
|
||||
protected override string Description => this.description;
|
||||
protected override string SystemPrompt => this.systemPrompt;
|
||||
protected override bool AllowProfiles => this.allowProfiles;
|
||||
public override Tools.Components Component { get; }
|
||||
private string submitText = string.Empty;
|
||||
private string selectedTargetLanguage = string.Empty;
|
||||
private string customTargetLanguage = string.Empty;
|
||||
|
||||
private Dictionary<string, string> inputFields = new();
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
var guid = Guid.Parse("958312de-a9e7-4666-901f-4d5b61647efb");
|
||||
@ -32,21 +40,63 @@ public partial class AssistantDynamic : AssistantBaseCore<SettingsDialogDynamic>
|
||||
this.title = assistantPlugin.AssistantTitle;
|
||||
this.description = assistantPlugin.AssistantDescription;
|
||||
this.systemPrompt = assistantPlugin.SystemPrompt;
|
||||
this.submitText = assistantPlugin.SubmitText;
|
||||
this.allowProfiles = assistantPlugin.AllowProfiles;
|
||||
}
|
||||
|
||||
foreach (var component in this.RootComponent!.Children)
|
||||
{
|
||||
switch (component.Type)
|
||||
{
|
||||
case AssistantUiCompontentType.TEXT_AREA:
|
||||
if (component is AssistantTextArea textArea)
|
||||
{
|
||||
this.inputFields.Add(textArea.Name, string.Empty);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
base.OnInitialized();
|
||||
}
|
||||
|
||||
protected override void ResetForm()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
foreach (var entry in this.inputFields)
|
||||
{
|
||||
this.inputFields[entry.Key] = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool MightPreselectValues()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
Console.WriteLine("throw new NotImplementedException();");
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override string SubmitText { get; }
|
||||
protected override Func<Task> SubmitAction { get; }
|
||||
private string? ValidateCustomLanguage(string value) => string.Empty;
|
||||
|
||||
private string CollectUserPrompt()
|
||||
{
|
||||
var prompt = string.Empty;
|
||||
foreach (var entry in this.inputFields)
|
||||
{
|
||||
prompt += $"{entry.Value}{Environment.NewLine}";
|
||||
}
|
||||
return prompt;
|
||||
}
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
this.CreateChatThread();
|
||||
var time = this.AddUserRequest(
|
||||
$"""
|
||||
|
||||
The given text is:
|
||||
|
||||
---
|
||||
{this.CollectUserPrompt()}
|
||||
""");
|
||||
|
||||
await this.AddAIResponseAsync(time);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
<MudStack Row="true" Class="mb-3">
|
||||
<MudSelect
|
||||
@bind-Value="@this.Value"
|
||||
Label="@this.Label"
|
||||
Placeholder="@this.Default.Value"
|
||||
AdornmentIcon="@this.Icon"
|
||||
Adornment="Adornment.Start"
|
||||
Variant="Variant.Outlined"
|
||||
Margin="Margin.Dense">
|
||||
@foreach (var item in Items)
|
||||
{
|
||||
<MudSelectItem Value="@item.Value">
|
||||
@item.Display
|
||||
</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudStack>
|
||||
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using AIStudio.Tools.PluginSystem.Assistants.DataModel;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MudBlazor;
|
||||
|
||||
namespace AIStudio.Components
|
||||
{
|
||||
public partial class DynamicAssistantDropdown : ComponentBase
|
||||
{
|
||||
[Parameter]
|
||||
public List<AssistantDropdownItem> Items { get; set; } = new();
|
||||
|
||||
[Parameter]
|
||||
public AssistantDropdownItem Default { get; set; } = new();
|
||||
|
||||
[Parameter]
|
||||
public string Value { get; set; } = string.Empty;
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<string> ValueChanged { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public string Label { get; set; } = string.Empty;
|
||||
|
||||
[Parameter]
|
||||
public Func<string, string?> ValidateSelection { get; set; } = _ => null;
|
||||
|
||||
[Parameter]
|
||||
public string Icon { get; set; } = Icons.Material.Filled.ArrowDropDown;
|
||||
}
|
||||
}
|
||||
@ -14,6 +14,7 @@ public sealed class PluginAssistants(bool isInternal, LuaState state, PluginType
|
||||
public string AssistantTitle { get; set; } = string.Empty;
|
||||
public string AssistantDescription { get; set; } = string.Empty;
|
||||
public string SystemPrompt { get; set; } = string.Empty;
|
||||
public string SubmitText { get; set; } = string.Empty;
|
||||
public bool AllowProfiles { get; set; } = true;
|
||||
|
||||
public void TryLoad()
|
||||
@ -64,6 +65,13 @@ public sealed class PluginAssistants(bool isInternal, LuaState state, PluginType
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!assistantTable.TryGetValue("SubmitText", out var assistantSubmitTextValue) ||
|
||||
!assistantSubmitTextValue.TryRead<string>(out var assistantSubmitText))
|
||||
{
|
||||
message = TB("The ASSISTANT table does not contain a valid system prompt.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!assistantTable.TryGetValue("AllowProfiles", out var assistantAllowProfilesValue) ||
|
||||
!assistantAllowProfilesValue.TryRead<bool>(out var assistantAllowProfiles))
|
||||
{
|
||||
@ -74,6 +82,7 @@ public sealed class PluginAssistants(bool isInternal, LuaState state, PluginType
|
||||
this.AssistantTitle = assistantTitle;
|
||||
this.AssistantDescription = assistantDescription;
|
||||
this.SystemPrompt = assistantSystemPrompt;
|
||||
this.SubmitText = assistantSubmitText;
|
||||
this.AllowProfiles = assistantAllowProfiles;
|
||||
|
||||
// Ensure that the UI table exists nested in the ASSISTANT table and is a valid Lua table:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user