mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-02-12 10:21:36 +00:00
added a switch component for boolean user inputs
This commit is contained in:
parent
4fd21ad45b
commit
0775b03529
@ -24,12 +24,17 @@
|
||||
Icon="@Icons.Material.Filled.Translate"/>
|
||||
}
|
||||
break;
|
||||
|
||||
case AssistantUiCompontentType.PROVIDER_SELECTION:
|
||||
if (component is AssistantProviderSelection providerSelection)
|
||||
{
|
||||
<ProviderSelection @bind-ProviderSettings="@this.providerSettings" ValidateProvider="@this.ValidatingProvider"/>
|
||||
}
|
||||
break;
|
||||
case AssistantUiCompontentType.SWITCH:
|
||||
if (component is AssistantSwitch assistantSwitch)
|
||||
{
|
||||
<MudTextSwitch Label="@assistantSwitch.Label" @bind-Value="@this.switchFields[assistantSwitch.Name]" LabelOn="@assistantSwitch.LabelOn" LabelOff="@assistantSwitch.LabelOff" />
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -30,6 +30,7 @@ public partial class AssistantDynamic : AssistantBaseCore<SettingsDialogDynamic>
|
||||
|
||||
private Dictionary<string, string> inputFields = new();
|
||||
private Dictionary<string, string> dropdownFields = new();
|
||||
private Dictionary<string, bool> switchFields = new();
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
@ -61,6 +62,12 @@ public partial class AssistantDynamic : AssistantBaseCore<SettingsDialogDynamic>
|
||||
this.dropdownFields.Add(dropdown.Name, dropdown.Default.Value);
|
||||
}
|
||||
break;
|
||||
case AssistantUiCompontentType.SWITCH:
|
||||
if (component is AssistantSwitch switchComponent)
|
||||
{
|
||||
this.switchFields.Add(switchComponent.Name, switchComponent.Value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
base.OnInitialized();
|
||||
@ -89,12 +96,13 @@ public partial class AssistantDynamic : AssistantBaseCore<SettingsDialogDynamic>
|
||||
foreach (var component in this.RootComponent!.Children)
|
||||
{
|
||||
var userInput = string.Empty;
|
||||
var userDecision = false;
|
||||
switch (component.Type)
|
||||
{
|
||||
case AssistantUiCompontentType.TEXT_AREA:
|
||||
if (component is AssistantTextArea textArea)
|
||||
{
|
||||
prompt += $"context:{Environment.NewLine}{textArea.UserPrompt}{Environment.NewLine}{Environment.NewLine}---{Environment.NewLine}";
|
||||
prompt += $"context:{Environment.NewLine}{textArea.UserPrompt}{Environment.NewLine}---{Environment.NewLine}";
|
||||
if (this.inputFields.TryGetValue(textArea.Name, out userInput))
|
||||
{
|
||||
prompt += $"user prompt:{Environment.NewLine}{userInput}";
|
||||
@ -104,20 +112,29 @@ public partial class AssistantDynamic : AssistantBaseCore<SettingsDialogDynamic>
|
||||
case AssistantUiCompontentType.DROPDOWN:
|
||||
if (component is AssistantDropdown dropdown)
|
||||
{
|
||||
prompt += $"{Environment.NewLine}context:{Environment.NewLine}{dropdown.UserPrompt}{Environment.NewLine}{Environment.NewLine}---{Environment.NewLine}";
|
||||
prompt += $"{Environment.NewLine}context:{Environment.NewLine}{dropdown.UserPrompt}{Environment.NewLine}---{Environment.NewLine}";
|
||||
if (this.dropdownFields.TryGetValue(dropdown.Name, out userInput))
|
||||
{
|
||||
prompt += $"user prompt:{Environment.NewLine}{userInput}";
|
||||
}
|
||||
}
|
||||
break;
|
||||
case AssistantUiCompontentType.SWITCH:
|
||||
if (component is AssistantSwitch switchComponent)
|
||||
{
|
||||
prompt += $"{Environment.NewLine}context:{Environment.NewLine}{switchComponent.UserPrompt}{Environment.NewLine}---{Environment.NewLine}";
|
||||
if (this.switchFields.TryGetValue(switchComponent.Name, out userDecision))
|
||||
{
|
||||
prompt += $"user decision:{Environment.NewLine}{userDecision}";
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
prompt += $"{userInput}{Environment.NewLine}";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine(prompt);
|
||||
return prompt;
|
||||
}
|
||||
|
||||
|
||||
@ -23,6 +23,8 @@ public class AssistantComponentFactory
|
||||
return new AssistantDropdown { Props = props, Children = children };
|
||||
case AssistantUiCompontentType.PROVIDER_SELECTION:
|
||||
return new AssistantProviderSelection { Props = props, Children = children };
|
||||
case AssistantUiCompontentType.SWITCH:
|
||||
return new AssistantSwitch { Props = props, Children = children };
|
||||
default:
|
||||
LOGGER.LogError($"Unknown assistant component type!\n{type} is not a supported assistant component type");
|
||||
throw new Exception($"Unknown assistant component type: {type}");
|
||||
|
||||
@ -0,0 +1,54 @@
|
||||
namespace AIStudio.Tools.PluginSystem.Assistants.DataModel;
|
||||
|
||||
public class AssistantSwitch : AssistantComponentBase
|
||||
{
|
||||
public override AssistantUiCompontentType Type => AssistantUiCompontentType.SWITCH;
|
||||
public Dictionary<string, object> Props { get; set; } = new();
|
||||
public List<IAssistantComponent> Children { get; set; } = new();
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => this.Props.TryGetValue(nameof(this.Name), out var v)
|
||||
? v.ToString() ?? string.Empty
|
||||
: string.Empty;
|
||||
set => this.Props[nameof(this.Name)] = value;
|
||||
}
|
||||
|
||||
public string Label
|
||||
{
|
||||
get => this.Props.TryGetValue(nameof(this.Label), out var v)
|
||||
? v.ToString() ?? string.Empty
|
||||
: string.Empty;
|
||||
set => this.Props[nameof(this.Label)] = value;
|
||||
}
|
||||
|
||||
public bool Value
|
||||
{
|
||||
get => this.Props.TryGetValue(nameof(this.Value), out var val) && val is true;
|
||||
set => this.Props[nameof(this.Value)] = value;
|
||||
}
|
||||
|
||||
public string UserPrompt
|
||||
{
|
||||
get => this.Props.TryGetValue(nameof(this.UserPrompt), out var val)
|
||||
? val.ToString() ?? string.Empty
|
||||
: string.Empty;
|
||||
set => this.Props[nameof(this.UserPrompt)] = value;
|
||||
}
|
||||
|
||||
public string LabelOn
|
||||
{
|
||||
get => this.Props.TryGetValue(nameof(this.LabelOn), out var v)
|
||||
? v.ToString() ?? string.Empty
|
||||
: string.Empty;
|
||||
set => this.Props[nameof(this.LabelOn)] = value;
|
||||
}
|
||||
|
||||
public string LabelOff
|
||||
{
|
||||
get => this.Props.TryGetValue(nameof(this.LabelOff), out var v)
|
||||
? v.ToString() ?? string.Empty
|
||||
: string.Empty;
|
||||
set => this.Props[nameof(this.LabelOff)] = value;
|
||||
}
|
||||
}
|
||||
@ -7,4 +7,5 @@ public enum AssistantUiCompontentType
|
||||
BUTTON,
|
||||
DROPDOWN,
|
||||
PROVIDER_SELECTION,
|
||||
SWITCH,
|
||||
}
|
||||
@ -25,5 +25,9 @@ public static class ComponentPropSpecs
|
||||
required: ["Name", "Label"],
|
||||
optional: []
|
||||
),
|
||||
[AssistantUiCompontentType.SWITCH] = new(
|
||||
required: ["Name", "Label", "LabelOn", "LabelOff", "Value"],
|
||||
optional: ["UserPrompt"]
|
||||
),
|
||||
};
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user