mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-02-12 12:21:38 +00:00
fixed bug in dropdown that prevented values from changing; finished its functionality
This commit is contained in:
parent
5a3e49d839
commit
4fd21ad45b
@ -18,7 +18,7 @@
|
||||
if (component is AssistantDropdown assistantDropdown)
|
||||
{
|
||||
<DynamicAssistantDropdown Items="@assistantDropdown.Items"
|
||||
@bind-Value="@this.selectedTargetLanguage"
|
||||
@bind-Value="@this.dropdownFields[assistantDropdown.Name]"
|
||||
Default="@assistantDropdown.Default"
|
||||
Label="@assistantDropdown.Label"
|
||||
Icon="@Icons.Material.Filled.Translate"/>
|
||||
|
||||
@ -29,6 +29,7 @@ public partial class AssistantDynamic : AssistantBaseCore<SettingsDialogDynamic>
|
||||
private string customTargetLanguage = string.Empty;
|
||||
|
||||
private Dictionary<string, string> inputFields = new();
|
||||
private Dictionary<string, string> dropdownFields = new();
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
@ -54,6 +55,12 @@ public partial class AssistantDynamic : AssistantBaseCore<SettingsDialogDynamic>
|
||||
this.inputFields.Add(textArea.Name, textArea.PrefillText);
|
||||
}
|
||||
break;
|
||||
case AssistantUiCompontentType.DROPDOWN:
|
||||
if (component is AssistantDropdown dropdown)
|
||||
{
|
||||
this.dropdownFields.Add(dropdown.Name, dropdown.Default.Value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
base.OnInitialized();
|
||||
@ -94,27 +101,30 @@ public partial class AssistantDynamic : AssistantBaseCore<SettingsDialogDynamic>
|
||||
}
|
||||
}
|
||||
break;
|
||||
case AssistantUiCompontentType.DROPDOWN:
|
||||
if (component is AssistantDropdown dropdown)
|
||||
{
|
||||
prompt += $"{Environment.NewLine}context:{Environment.NewLine}{dropdown.UserPrompt}{Environment.NewLine}{Environment.NewLine}---{Environment.NewLine}";
|
||||
if (this.dropdownFields.TryGetValue(dropdown.Name, out userInput))
|
||||
{
|
||||
prompt += $"user prompt:{Environment.NewLine}{userInput}";
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
prompt += $"{userInput}{Environment.NewLine}";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Console.WriteLine(prompt);
|
||||
return prompt;
|
||||
}
|
||||
|
||||
private async Task Submit()
|
||||
{
|
||||
this.CreateChatThread();
|
||||
var time = this.AddUserRequest(
|
||||
$"""
|
||||
|
||||
The given text is:
|
||||
|
||||
---
|
||||
{this.CollectUserPrompt()}
|
||||
""");
|
||||
|
||||
var time = this.AddUserRequest(this.CollectUserPrompt());
|
||||
await this.AddAIResponseAsync(time);
|
||||
}
|
||||
}
|
||||
@ -1,17 +1,21 @@
|
||||
<MudStack Row="true" Class="mb-3">
|
||||
<MudSelect
|
||||
@bind-Value="@this.Value"
|
||||
T="string"
|
||||
Value="@this.Value"
|
||||
ValueChanged="@(val => this.OnValueChanged(val))"
|
||||
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>
|
||||
}
|
||||
Margin="Margin.Dense"
|
||||
MultiSelection="false"
|
||||
>
|
||||
@foreach (var item in Items)
|
||||
{
|
||||
<MudSelectItem Value="@item.Value">
|
||||
@item.Display
|
||||
</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudStack>
|
||||
@ -29,5 +29,14 @@ namespace AIStudio.Components
|
||||
|
||||
[Parameter]
|
||||
public string Icon { get; set; } = Icons.Material.Filled.ArrowDropDown;
|
||||
|
||||
private async Task OnValueChanged(string newValue)
|
||||
{
|
||||
if (this.Value != newValue)
|
||||
{
|
||||
this.Value = newValue;
|
||||
await this.ValueChanged.InvokeAsync(newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -20,6 +20,15 @@ public class AssistantDropdown : AssistantComponentBase
|
||||
: string.Empty;
|
||||
set => this.Props[nameof(this.Label)] = value;
|
||||
}
|
||||
|
||||
public string UserPrompt
|
||||
{
|
||||
get => this.Props.TryGetValue(nameof(this.UserPrompt), out var v)
|
||||
? v.ToString() ?? string.Empty
|
||||
: string.Empty;
|
||||
set => this.Props[nameof(this.UserPrompt)] = value;
|
||||
}
|
||||
|
||||
public AssistantDropdownItem Default
|
||||
{
|
||||
get
|
||||
|
||||
@ -19,7 +19,7 @@ public static class ComponentPropSpecs
|
||||
),
|
||||
[AssistantUiCompontentType.DROPDOWN] = new(
|
||||
required: ["Name", "Label", "Default", "Items"],
|
||||
optional: []
|
||||
optional: ["UserPrompt"]
|
||||
),
|
||||
[AssistantUiCompontentType.PROVIDER_SELECTION] = new(
|
||||
required: ["Name", "Label"],
|
||||
|
||||
Loading…
Reference in New Issue
Block a user