@using BLAIzor.Models @using BLAIzor.Services @using Newtonsoft.Json @using BLAIzor.Components.Partials @inject ContentEditorService ContentEditorService @inject HtmlSnippetProcessor HtmlSnippetProcessor @inject QDrantService QDrantService
@if (isLoading) {

Loading suggestions...

} else if (menuItems.Any()) {

Suggested Menu Items

@foreach (var item in menuItems) { @{ if (MenuItemsSaved) { } } }
} else if (!string.IsNullOrEmpty(errorMessage)) {

@errorMessage

} @code { [Parameter] public int SiteId { get; set; } [Parameter] public string SessionId { get; set; } private string subject = string.Empty; private List menuItems = new(); private bool MenuItemsSaved = false; private bool isLoading = false; private string? errorMessage; private bool hasCollection = false; protected override async Task OnParametersSetAsync() { List Site = await ContentEditorService.GetMenuItemsBySiteIdAsync(SiteId); var collectionResult = await QDrantService.GetCollectionBySiteIdAsync(SiteId); if (!string.IsNullOrEmpty(collectionResult)) { //create colection hasCollection = true; Console.Write("Has collection already"); } if (Site.Count() > 0) { foreach (var menuItem in Site) { string content; MenuItemModel model = new MenuItemModel(); //try to get content from qDrant if (menuItem.QdrantPointId != null) { content = await QDrantService.GetContentAsync(SiteId, menuItem.SortOrder); // content = await QDrantService.GetContentAsync(SiteId, menuItem.QdrantPointId); TODO var selectedPoint = JsonConvert.DeserializeObject(content)!; if (selectedPoint != null) { model.Content = selectedPoint.result.payload.content; Console.Write($"Found point: {selectedPoint.result.payload.content}"); } } model.Name = menuItem.Name; menuItems.Add(model); // UpdateMenuItem(model); } MenuItemsSaved = true; } //get menu content from QDrant for each menu item } private async Task GenerateMenuItems() { if (string.IsNullOrWhiteSpace(subject)) { errorMessage = "Please enter a subject."; return; } isLoading = true; errorMessage = null; try { var prompt = $"Suggest a list of menu items for a website about: {subject}. Please do not attach any explanation."; var response = await ContentEditorService.GetMenuSuggestionsAsync(SessionId, prompt); menuItems = response.Select(name => new MenuItemModel { Name = name }).ToList(); } catch (Exception ex) { errorMessage = "An error occurred while generating menu items."; } finally { isLoading = false; } } private async Task AddMenuItem() { isLoading = true; errorMessage = null; menuItems.Add(new()); } private void RemoveMenuItem(MenuItemModel item) { menuItems.Remove(item); } private void UpdateMenuItem(MenuItemModel updatedItem) { Console.Write("Updating menu item"); var item = menuItems.FirstOrDefault(i => i.Name == updatedItem.Name); if (item != null) { item.Content = updatedItem.Content; } else{ Console.Write("Not found"); } } private async Task SaveAllContent() { var result = await ContentEditorService.ProcessMenuItems(SiteId, hasCollection, menuItems, subject, MenuItemsSaved); if (result == "OK") { MenuItemsSaved = true; hasCollection = true; errorMessage = "Menu saved"; } else { errorMessage = result; } } }