Skip to content

Commit

Permalink
Code(WEB::AssistantForm): Add logic to update assistant in the Assist…
Browse files Browse the repository at this point in the history
…antForm
  • Loading branch information
ktutak1337 committed May 23, 2024
1 parent f5b0357 commit ace3136
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@
@code
{
[Parameter] public Guid AssistantId { get; set; }
[Parameter] public EventCallback OnAssistantUpdate { get; set; }
private Assistant? Assistant { get; set; } = new();
private List<string> AvailableModels { get; set; } = new() { "gpt-4", "gpt-3.5-turbo" };

private const string assistantBehaviorGuidelines = @"
Enter the Metaprompt here. This set of instructions will define your assistant's behavior
in every conversation, guiding how it interacts and responds. Keep it concise, clear, and
Expand All @@ -72,9 +73,11 @@ reflective of the assistant's intended personality and capabilities.";
await PopulateForm();
}

private void OnValidSubmit(EditContext context)
private async void OnValidSubmit(EditContext context)
{
await UpdateAssistantAsync(Assistant!);
success = true;
await OnAssistantUpdate.InvokeAsync();
StateHasChanged();
}

Expand Down Expand Up @@ -105,4 +108,26 @@ reflective of the assistant's intended personality and capabilities.";
}
}
}

private async Task UpdateAssistantAsync(Assistant assistant)
{
if (assistant is not null)
{
await _assistantService.UpdateAssistant(Map(assistant));
}
}

private AssistantResponse Map(Assistant assistant)
=> new AssistantResponse(
assistant.Id,
assistant.Name,
assistant.Metaprompt,
assistant.Description,
assistant.AvatarUrl,
assistant.DefaultModel,
assistant.DefaultVoice,
assistant.IsDefault,
assistant.CreatedAt,
assistant.UpdatedAt);

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</MudDrawerHeader>
<div>
<MudDivider />
<AssistantForm AssistantId="selectedAssistantId" />
<AssistantForm AssistantId="selectedAssistantId" OnAssistantUpdate="HandleAssistantUpdated" />
</div>
}
else
Expand Down Expand Up @@ -72,4 +72,10 @@
selectedAssistantId = id;
isEditing = true;
}

private async Task HandleAssistantUpdated()
{
isEditing = false;
await LoadAssistants();
}
}

0 comments on commit ace3136

Please sign in to comment.