smartcomponents
smartcomponents copied to clipboard
[SmartPaste] Advanced field descriptions concept
Overview
Question
Could it be possible to have alternative ways of using of describing fields to SmartPaste
?
Two possible ideas I have are:
- Binding data models, using annotations for descriptions
- Using custom field handlers for more advance result mapping
Context
I'm using the MudBlazor component library for my controls, and while SmartPaste
works well with MudTextField, but I'm struggling to get good results with other form controls (like MudSelect).
Examples
Without knowing much about how the controls currently work.. this is the kind of thing I was thinking of.
Binding Example
Model using custom DataAnnotations
public class DataModel
{
[SmartPasteDescription("The user's vehicle registration number which must be in the form XYZ-123")]
public string Registration { get; set; }
[SmartPasteDescription("The job description which must start with JOB TITLE in all caps, and then contain one paragraph")]
public string JobDescription { get; set; }
[SmartPasteIgnore]
public bool IsAvailable { get; set; }
}
Component
...
<MudTextField @bind-Value="@dataModel.Registration" Label="Car Rego" />
<MudTextField @bind-Value="@dataModel.JobDescription" Label="Job Description" />
<MudSwitch @bind-Value="@dataModel.IsAvailable" Label="Available?" />
<SmartPaste DefaultIcon @bind-Model="dataModel" />
...
@code {
public DataModel dataModel { get; set; } = new();
...
}
Custom Handlers Example
For more advanced custom handlers of results returned post AI processing. This could also be used in conjunction with the default behaviour of processing the form fields.
...
<SmartPaste DefaultIcon CustomFieldHandlers="@CustomFields" />
...
@code {
// A dictionary of string/actions to "describe" and "handle" fields for the SmartPaste component
public Dictionary<string, Action<string>> CustomFields { get; set; }
protected override void OnInitialized()
{
CustomFields = new Dictionary<string, Action<string>>
{
{ "The user's vehicle registration number which must be in the form XYZ-123", RegistrationHandler },
{ "The job description which must start with JOB TITLE in all caps, and then contain one paragraph", result => dataModel.JobDescription = result }
};
}
private void RegistrationHandler(string result)
{
// More advanced handling for car rego checks, after the AI has extracted the result
}
}