dotnet-smartcomponents / smartcomponents

Experimental, end-to-end AI features for .NET apps
693 stars 61 forks source link

[SmartPaste] Advanced field descriptions concept #46

Open MitchellNZ opened 7 months ago

MitchellNZ commented 7 months ago

Overview

Question

Could it be possible to have alternative ways of using of describing fields to SmartPaste?

Two possible ideas I have are:

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
  }
}
MitchellNZ commented 7 months ago

Was just reading over some of the other issues in more detail and noticed #39 is almost exactly the same as my first example! Sorry for the duplication, but my second example for custom handlers would still help my situation a lot also.

For some additional context, I would love to roll this out into a production app (feature flagged for more advanced users and testing at this stage), but am stuck doing so until I can provide reliable results for all MudBlaozr form components, and my other issue (#44) has been addressed.