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