89 lines
3.1 KiB
Plaintext
89 lines
3.1 KiB
Plaintext
@using BLAIzor.Services
|
|
|
|
@inject OpenAIApiService AiService
|
|
|
|
<h3>AI-Guided Form</h3>
|
|
|
|
@if (currentStep < formSteps.Count)
|
|
{
|
|
<p><strong>@formSteps[currentStep].Prompt</strong></p>
|
|
<p><em>@formSteps[currentStep].Explanation</em></p>
|
|
<input @bind="formSteps[currentStep].Value" class="form-control" />
|
|
<br />
|
|
<button class="btn btn-primary" @onclick="PreviousStep" disabled="@(currentStep == 0)">Back</button>
|
|
<button class="btn btn-primary" @onclick="AskForClarification">Ask AI</button>
|
|
<button class="btn btn-primary" @onclick="NextStep">Next</button>
|
|
<p><em>@aiClarification</em></p>
|
|
}
|
|
else
|
|
{
|
|
<p>AI is reviewing your responses...</p>
|
|
<p>@aiReview</p>
|
|
<button @onclick="RestartForm">Start Over</button>
|
|
}
|
|
|
|
@code {
|
|
[Parameter] public string SessionId { get; set; }
|
|
|
|
private class FormStep
|
|
{
|
|
public string Prompt { get; set; } = string.Empty;
|
|
public string Explanation { get; set; } = string.Empty;
|
|
public string Value { get; set; } = string.Empty;
|
|
}
|
|
|
|
private List<FormStep> formSteps = new()
|
|
{
|
|
new FormStep { Prompt = "What is your full name?", Explanation = "Please enter your legal full name as it appears on official documents." },
|
|
new FormStep { Prompt = "What is your email address?", Explanation = "We'll use this to send you updates and confirmations." },
|
|
new FormStep { Prompt = "What is your home address?", Explanation = "This is needed for official correspondence." },
|
|
new FormStep { Prompt = "Describe your work experience.", Explanation = "Provide a summary of your relevant job history." },
|
|
new FormStep { Prompt = "What is your preferred method of contact?", Explanation = "Phone, email, or other? Please specify why you prefer it." }
|
|
};
|
|
|
|
private int currentStep = 0;
|
|
private string aiReview = string.Empty;
|
|
private string aiClarification = string.Empty;
|
|
|
|
private void NextStep()
|
|
{
|
|
if (currentStep < formSteps.Count - 1)
|
|
{
|
|
currentStep++;
|
|
aiClarification = string.Empty; // Reset AI response when moving to the next question
|
|
}
|
|
else
|
|
{
|
|
ValidateWithAI();
|
|
}
|
|
}
|
|
|
|
private void PreviousStep()
|
|
{
|
|
if (currentStep > 0)
|
|
{
|
|
currentStep--;
|
|
aiClarification = string.Empty; // Reset AI response when going back
|
|
}
|
|
}
|
|
|
|
private async void AskForClarification()
|
|
{
|
|
aiClarification = "AI is thinking...";
|
|
aiClarification = await AiService.GetSimpleChatGPTResponse(SessionId, "Provide additional clarification for the following question:", formSteps[currentStep].Prompt);
|
|
}
|
|
|
|
private async void ValidateWithAI()
|
|
{
|
|
string formData = string.Join("\n", formSteps.Select(s => $"{s.Prompt} {s.Value}"));
|
|
aiReview = await AiService.GetSimpleChatGPTResponse(SessionId, "Review the form for completeness and correctness:", formData);
|
|
}
|
|
|
|
private void RestartForm()
|
|
{
|
|
currentStep = 0;
|
|
aiReview = string.Empty;
|
|
aiClarification = string.Empty;
|
|
formSteps.ForEach(step => step.Value = string.Empty);
|
|
}
|
|
} |