mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-03-29 21:51:37 +00:00
added a web content reader as a component for the assistant builder
This commit is contained in:
parent
58c034843b
commit
6841a357cc
@ -15,6 +15,16 @@
|
|||||||
<MudTextField T="string" @bind-Text="@this.inputFields[textArea.Name]" Label="@textArea.Label" ReadOnly="@textArea.ReadOnly" AdornmentIcon="@Icons.Material.Filled.DocumentScanner" Adornment="Adornment.Start" Variant="Variant.Outlined" Lines="@lines" AutoGrow="@true" MaxLines="12" Class="mb-3"/>
|
<MudTextField T="string" @bind-Text="@this.inputFields[textArea.Name]" Label="@textArea.Label" ReadOnly="@textArea.ReadOnly" AdornmentIcon="@Icons.Material.Filled.DocumentScanner" Adornment="Adornment.Start" Variant="Variant.Outlined" Lines="@lines" AutoGrow="@true" MaxLines="12" Class="mb-3"/>
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case AssistantUiCompontentType.WEB_CONTENT_READER:
|
||||||
|
if (component is AssistantWebContentReader webContent && this.webContentFields.TryGetValue(webContent.Name, out var webState))
|
||||||
|
{
|
||||||
|
<ReadWebContent @bind-Content="@webState.Content"
|
||||||
|
ProviderSettings="@this.providerSettings"
|
||||||
|
@bind-AgentIsRunning="@webState.AgentIsRunning"
|
||||||
|
@bind-Preselect="@webState.Preselect"
|
||||||
|
@bind-PreselectContentCleanerAgent="@webState.PreselectContentCleanerAgent" />
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case AssistantUiCompontentType.DROPDOWN:
|
case AssistantUiCompontentType.DROPDOWN:
|
||||||
if (component is AssistantDropdown assistantDropdown)
|
if (component is AssistantDropdown assistantDropdown)
|
||||||
|
|||||||
@ -34,6 +34,7 @@ public partial class AssistantDynamic : AssistantBaseCore<SettingsDialogDynamic>
|
|||||||
private Dictionary<string, string> inputFields = new();
|
private Dictionary<string, string> inputFields = new();
|
||||||
private Dictionary<string, string> dropdownFields = new();
|
private Dictionary<string, string> dropdownFields = new();
|
||||||
private Dictionary<string, bool> switchFields = new();
|
private Dictionary<string, bool> switchFields = new();
|
||||||
|
private Dictionary<string, WebContentState> webContentFields = new();
|
||||||
|
|
||||||
protected override void OnInitialized()
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
@ -72,6 +73,16 @@ public partial class AssistantDynamic : AssistantBaseCore<SettingsDialogDynamic>
|
|||||||
this.switchFields.Add(switchComponent.Name, switchComponent.Value);
|
this.switchFields.Add(switchComponent.Name, switchComponent.Value);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case AssistantUiCompontentType.WEB_CONTENT_READER:
|
||||||
|
if (component is AssistantWebContentReader webContent)
|
||||||
|
{
|
||||||
|
this.webContentFields.Add(webContent.Name, new WebContentState
|
||||||
|
{
|
||||||
|
Preselect = webContent.Preselect,
|
||||||
|
PreselectContentCleanerAgent = webContent.PreselectContentCleanerAgent,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
base.OnInitialized();
|
base.OnInitialized();
|
||||||
@ -83,6 +94,11 @@ public partial class AssistantDynamic : AssistantBaseCore<SettingsDialogDynamic>
|
|||||||
{
|
{
|
||||||
this.inputFields[entry.Key] = string.Empty;
|
this.inputFields[entry.Key] = string.Empty;
|
||||||
}
|
}
|
||||||
|
foreach (var entry in this.webContentFields)
|
||||||
|
{
|
||||||
|
entry.Value.Content = string.Empty;
|
||||||
|
entry.Value.AgentIsRunning = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool MightPreselectValues()
|
protected override bool MightPreselectValues()
|
||||||
@ -133,6 +149,21 @@ public partial class AssistantDynamic : AssistantBaseCore<SettingsDialogDynamic>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case AssistantUiCompontentType.WEB_CONTENT_READER:
|
||||||
|
if (component is AssistantWebContentReader webContent &&
|
||||||
|
this.webContentFields.TryGetValue(webContent.Name, out var webState))
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(webContent.UserPrompt))
|
||||||
|
{
|
||||||
|
prompt += $"{Environment.NewLine}context:{Environment.NewLine}{webContent.UserPrompt}{Environment.NewLine}---{Environment.NewLine}";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(webState.Content))
|
||||||
|
{
|
||||||
|
prompt += $"user prompt:{Environment.NewLine}{webState.Content}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
prompt += $"{userInput}{Environment.NewLine}";
|
prompt += $"{userInput}{Environment.NewLine}";
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -0,0 +1,9 @@
|
|||||||
|
namespace AIStudio.Assistants.Dynamic;
|
||||||
|
|
||||||
|
public sealed class WebContentState
|
||||||
|
{
|
||||||
|
public string Content { get; set; } = string.Empty;
|
||||||
|
public bool Preselect { get; set; }
|
||||||
|
public bool PreselectContentCleanerAgent { get; set; }
|
||||||
|
public bool AgentIsRunning { get; set; }
|
||||||
|
}
|
||||||
@ -142,6 +142,15 @@ ASSISTANT = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
["Type"] = "WEB_CONTENT_READER", -- allows the user to fetch a URL and clean it
|
||||||
|
["Props"] = {
|
||||||
|
["Name"] = "<unique identifier of this component>", -- required
|
||||||
|
["UserPrompt"] = "<help text that explains the purpose of this reader>",
|
||||||
|
["Preselect"] = false, -- automatically show the reader when the assistant opens
|
||||||
|
["PreselectContentCleanerAgent"] = true -- run the content cleaner by default
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,6 +33,8 @@ public class AssistantComponentFactory
|
|||||||
return new AssistantText { Props = props, Children = children };
|
return new AssistantText { Props = props, Children = children };
|
||||||
case AssistantUiCompontentType.LIST:
|
case AssistantUiCompontentType.LIST:
|
||||||
return new AssistantList { Props = props, Children = children };
|
return new AssistantList { Props = props, Children = children };
|
||||||
|
case AssistantUiCompontentType.WEB_CONTENT_READER:
|
||||||
|
return new AssistantWebContentReader { Props = props, Children = children };
|
||||||
default:
|
default:
|
||||||
LOGGER.LogError($"Unknown assistant component type!\n{type} is not a supported assistant component type");
|
LOGGER.LogError($"Unknown assistant component type!\n{type} is not a supported assistant component type");
|
||||||
throw new Exception($"Unknown assistant component type: {type}");
|
throw new Exception($"Unknown assistant component type: {type}");
|
||||||
|
|||||||
@ -12,4 +12,5 @@ public enum AssistantUiCompontentType
|
|||||||
HEADING,
|
HEADING,
|
||||||
TEXT,
|
TEXT,
|
||||||
LIST,
|
LIST,
|
||||||
|
WEB_CONTENT_READER,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,36 @@
|
|||||||
|
namespace AIStudio.Tools.PluginSystem.Assistants.DataModel;
|
||||||
|
|
||||||
|
public class AssistantWebContentReader : AssistantComponentBase
|
||||||
|
{
|
||||||
|
public override AssistantUiCompontentType Type => AssistantUiCompontentType.WEB_CONTENT_READER;
|
||||||
|
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 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 bool Preselect
|
||||||
|
{
|
||||||
|
get => this.Props.TryGetValue(nameof(this.Preselect), out var v) && v is true;
|
||||||
|
set => this.Props[nameof(this.Preselect)] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool PreselectContentCleanerAgent
|
||||||
|
{
|
||||||
|
get => this.Props.TryGetValue(nameof(this.PreselectContentCleanerAgent), out var v) && v is true;
|
||||||
|
set => this.Props[nameof(this.PreselectContentCleanerAgent)] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -45,5 +45,9 @@ public static class ComponentPropSpecs
|
|||||||
required: ["Items"],
|
required: ["Items"],
|
||||||
optional: []
|
optional: []
|
||||||
),
|
),
|
||||||
|
[AssistantUiCompontentType.WEB_CONTENT_READER] = new(
|
||||||
|
required: ["Name"],
|
||||||
|
optional: ["UserPrompt", "Preselect", "PreselectContentCleanerAgent"]
|
||||||
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user