mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-15 03:33:47 +00:00
Added embedding information
This commit is contained in:
6 files changed
+373
No files matched your search
@@ -0,0 +1,103 @@
|
||||
<MudDialog>
|
||||
<DialogContent>
|
||||
<MudForm @ref="@this.form" @bind-IsValid="@this.dataIsValid" @bind-Errors="@this.dataIssues">
|
||||
@* ReSharper disable once CSharpWarnings::CS8974 *@
|
||||
<MudTextField
|
||||
T="string"
|
||||
@bind-Text="@this.DataEmbeddingName"
|
||||
Label="Embedding Name"
|
||||
HelperText="The name of the embedding method."
|
||||
Class="mb-3"
|
||||
Adornment="Adornment.Start"
|
||||
AdornmentIcon="@Icons.Material.Filled.Label"
|
||||
AdornmentColor="Color.Info"
|
||||
Validation="@this.ValidateName"
|
||||
UserAttributes="@SPELLCHECK_ATTRIBUTES"
|
||||
/>
|
||||
|
||||
@* ReSharper disable once CSharpWarnings::CS8974 *@
|
||||
<MudTextField
|
||||
T="string"
|
||||
@bind-Text="@this.DataEmbeddingType"
|
||||
Label="Embedding Type"
|
||||
HelperText="What kind of embedding is used. For example, Transformer Embedding, Contextual Word Embedding, Graph Embedding, etc."
|
||||
Adornment="Adornment.Start"
|
||||
AdornmentIcon="@Icons.Material.Filled.Extension"
|
||||
AdornmentColor="Color.Info"
|
||||
Validation="@this.ValidateType"
|
||||
UserAttributes="@SPELLCHECK_ATTRIBUTES"
|
||||
/>
|
||||
|
||||
<MudList T="@string" Class="mb-3">
|
||||
<MudListItem Icon="@Icons.Material.Filled.Link" Href="https://en.wikipedia.org/wiki/Word_embedding" Target="_blank" Text="See Wikipedia for more information about word embeddings"/>
|
||||
<MudListItem Icon="@Icons.Material.Filled.Link" Href="https://en.wikipedia.org/wiki/Knowledge_graph_embedding" Target="_blank" Text="See Wikipedia for more information about knowledge graph embeddings"/>
|
||||
</MudList>
|
||||
|
||||
@* ReSharper disable once CSharpWarnings::CS8974 *@
|
||||
<MudTextField
|
||||
T="string"
|
||||
@bind-Text="@this.DataDescription"
|
||||
Label="Embedding Description"
|
||||
HelperText="A short description of the embedding method."
|
||||
Lines="3"
|
||||
AutoGrow="@true"
|
||||
MaxLines="6"
|
||||
Immediate="@true"
|
||||
Variant="Variant.Outlined"
|
||||
Class="mb-3"
|
||||
Adornment="Adornment.Start"
|
||||
AdornmentIcon="@Icons.Material.Filled.Extension"
|
||||
AdornmentColor="Color.Info"
|
||||
Validation="@this.ValidateDescription"
|
||||
UserAttributes="@SPELLCHECK_ATTRIBUTES"
|
||||
/>
|
||||
|
||||
@* ReSharper disable once CSharpWarnings::CS8974 *@
|
||||
<MudTextField
|
||||
T="string"
|
||||
@bind-Text="@this.DataUsedWhen"
|
||||
Label="Used when"
|
||||
HelperText="When is this embedding used? When you define multiple embeddings, it is helpful to know when to use which one."
|
||||
Lines="3"
|
||||
AutoGrow="@true"
|
||||
MaxLines="6"
|
||||
Immediate="@true"
|
||||
Variant="Variant.Outlined"
|
||||
Class="mb-3"
|
||||
Adornment="Adornment.Start"
|
||||
AdornmentIcon="@Icons.Material.Filled.Assessment"
|
||||
AdornmentColor="Color.Info"
|
||||
Validation="@this.ValidateUsedWhen"
|
||||
UserAttributes="@SPELLCHECK_ATTRIBUTES"
|
||||
/>
|
||||
|
||||
@* ReSharper disable once CSharpWarnings::CS8974 *@
|
||||
<MudTextField
|
||||
T="string"
|
||||
@bind-Text="@this.DataLink"
|
||||
Label="Embedding Link"
|
||||
HelperText="A link to the embedding, e.g., to the model, the source code, the paper, it's Wikipedia page, etc."
|
||||
Class="mb-3"
|
||||
Adornment="Adornment.Start"
|
||||
AdornmentIcon="@Icons.Material.Filled.Link"
|
||||
AdornmentColor="Color.Info"
|
||||
UserAttributes="@SPELLCHECK_ATTRIBUTES"
|
||||
/>
|
||||
|
||||
</MudForm>
|
||||
<Issues IssuesData="@this.dataIssues"/>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="@this.Cancel" Variant="Variant.Filled">Cancel</MudButton>
|
||||
<MudButton OnClick="@this.Store" Variant="Variant.Filled" Color="Color.Primary">
|
||||
@if(this.IsEditing)
|
||||
{
|
||||
@:Update
|
||||
}
|
||||
else
|
||||
{
|
||||
@:Add
|
||||
}
|
||||
</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
@@ -0,0 +1,129 @@
|
||||
using AIStudio.Assistants.ERI;
|
||||
using AIStudio.Settings;
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace AIStudio.Dialogs;
|
||||
|
||||
public partial class EmbeddingMethodDialog : ComponentBase
|
||||
{
|
||||
[CascadingParameter]
|
||||
private MudDialogInstance MudDialog { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// The user chosen embedding name.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string DataEmbeddingName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The user chosen embedding type.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string DataEmbeddingType { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The embedding description.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string DataDescription { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// When is the embedding used?
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string DataUsedWhen { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// A link to the embedding documentation or the source code. Might be null, which means no link is provided.
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public string? DataLink { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Should the dialog be in editing mode?
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public bool IsEditing { get; init; }
|
||||
|
||||
[Inject]
|
||||
private SettingsManager SettingsManager { get; init; } = null!;
|
||||
|
||||
private static readonly Dictionary<string, object?> SPELLCHECK_ATTRIBUTES = new();
|
||||
|
||||
private bool dataIsValid;
|
||||
private string[] dataIssues = [];
|
||||
|
||||
// We get the form reference from Blazor code to validate it manually:
|
||||
private MudForm form = null!;
|
||||
|
||||
private EmbeddingInfo CreateEmbeddingInfo() => new(this.DataEmbeddingType, this.DataEmbeddingName, this.DataDescription, this.DataUsedWhen, this.DataLink);
|
||||
|
||||
#region Overrides of ComponentBase
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
// Configure the spellchecking for the instance name input:
|
||||
this.SettingsManager.InjectSpellchecking(SPELLCHECK_ATTRIBUTES);
|
||||
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
// Reset the validation when not editing and on the first render.
|
||||
// We don't want to show validation errors when the user opens the dialog.
|
||||
if(!this.IsEditing && firstRender)
|
||||
this.form.ResetValidation();
|
||||
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private string? ValidateName(string name)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
return "The embedding name must not be empty. Please name the embedding.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateType(string type)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(type))
|
||||
return "The embedding type must not be empty. Please specify the embedding type.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateDescription(string description)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(description))
|
||||
return "The description must not be empty. Please describe the embedding method.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string? ValidateUsedWhen(string usedWhen)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(usedWhen))
|
||||
return "Please describe when the embedding is used. Might be anytime or when certain keywords are present, etc.";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private async Task Store()
|
||||
{
|
||||
await this.form.Validate();
|
||||
|
||||
// When the data is not valid, we don't store it:
|
||||
if (!this.dataIsValid)
|
||||
return;
|
||||
|
||||
var embeddingInfo = this.CreateEmbeddingInfo();
|
||||
this.MudDialog.Close(DialogResult.Ok(embeddingInfo));
|
||||
}
|
||||
|
||||
private void Cancel() => this.MudDialog.Cancel();
|
||||
}
|
||||
Reference in new issue
Block a user