tagged title and a paragraph." +
+ "and generate a" + Mood + " marketing-oriented welcome message and a summary of the content and introduction of the brand for the user, aiming to explain clearly, what does the company/person offer, constructed as simple Bootstrap HTML
codeblock with a
tagged title and a paragraph." +
"If there is any logo, or not logo but main brand image in the document use that url, and add that as a bootstrap responsive ('img-fluid py-3') image, with the maximum height of 30vh." +
//"In the end of your answer, always add in a new row: 'If you have any questions, you can simply ask either by typing in the message box, or by clicking the microphone icon on the top of the page. '"+
"Here is a list of topics " + menuList +
@@ -159,14 +164,14 @@ namespace BLAIzor.Services
}
//_scopedContentService.CurrentDOM = streamedHtmlContent;
- //Console.Write("Answer: " + streamedHtmlContent);
+ ////Console.Write("Answer: " + streamedHtmlContent);
//return streamedHtmlContent;
}
public async Task ProcessUserIntent(string sessionId, string userPrompt, int siteId, int templateId, string collectionName, string menuList = "")
{
- Console.WriteLine($"SITE ID: {siteId}");
+ //Console.WriteLine($"SITE ID: {siteId}");
OnStatusChangeReceived?.Invoke(sessionId, "Understanding your request...");
// Get JSON result based on siteId presence
@@ -174,7 +179,7 @@ namespace BLAIzor.Services
? await GetJsonResultFromQuery(sessionId, siteId, userPrompt)
: await GetJsonResultFromQuery(sessionId, userPrompt);
- Console.WriteLine(resultJson);
+ //Console.WriteLine(resultJson);
var baseResult = await ValidateAndFixJson(resultJson, FixJsonWithAI);
@@ -183,7 +188,7 @@ namespace BLAIzor.Services
if (baseResult == null)
{
- Console.WriteLine("Invalid JSON response.");
+ //Console.WriteLine("Invalid JSON response.");
return;
}
@@ -209,7 +214,7 @@ namespace BLAIzor.Services
break;
default:
- Console.WriteLine("Unknown result type.");
+ //Console.WriteLine("Unknown result type.");
break;
}
@@ -227,15 +232,16 @@ namespace BLAIzor.Services
///
public async Task ProcessContentRequest(string sessionId, MenuItem requestedMenu, int siteId, int templateId, string collectionName, string menuList = "", bool forceUnmodified = false)
{
-
- Console.Write($"\n\n SessionId: {sessionId}\n\n");
+
+ //Console.Write($"\n\n SessionId: {sessionId}\n\n");
//string rootpath = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "wwwroot/Documents/" + _contentService.SelectedDocument);
string extractedText = "";
- if (requestedMenu != null) {
-
+ if (requestedMenu != null)
+ {
+
string qDrantData = await _qDrantService.GetContentAsync(siteId, requestedMenu.PointId);
QDrantGetContentPointResult _selectedPoint = new QDrantGetContentPointResult();
@@ -246,7 +252,7 @@ namespace BLAIzor.Services
extractedText = _selectedPoint.result.payload.name + ": " + _selectedPoint.result.payload.content + ", ";
}
-
+
string contentJson = await GetContentFromQuery(sessionId,
"Enhance this text if needed, making its style and grammar suitable to be displayed as the content of a webpage",
extractedText,
@@ -258,38 +264,38 @@ namespace BLAIzor.Services
public async Task ProcessContentRequest(string sessionId, string requestedMenu, int siteId, int templateId, string collectionName, string menuList = "", bool forceUnmodified = false)
{
- Console.Write($"\n\n SessionId: {sessionId}\n\n");
+ //Console.Write($"\n\n SessionId: {sessionId}\n\n");
//string rootpath = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "wwwroot/Documents/" + _contentService.SelectedDocument);
string extractedText = "";
- float[] vector = [];
- OnStatusChangeReceived?.Invoke(sessionId, "Determining search vectors");
- vector = await _openAIEmbeddingService.GenerateEmbeddingAsync(requestedMenu);
- OnStatusChangeReceived?.Invoke(sessionId, "Looking up content in the knowledge database");
- var pointId = await _qDrantService.QueryContentAsync(siteId, vector, 3);
+ float[] vector = [];
+ OnStatusChangeReceived?.Invoke(sessionId, "Determining search vectors");
+ vector = await _openAIEmbeddingService.GenerateEmbeddingAsync(requestedMenu);
+ OnStatusChangeReceived?.Invoke(sessionId, "Looking up content in the knowledge database");
+ var pointId = await _qDrantService.QueryContentAsync(siteId, vector, 3);
- if (pointId.Length > 0)
+ if (pointId.Length > 0)
+ {
+ foreach (var item in pointId)
{
- foreach (var item in pointId)
+ string qDrantData = await _qDrantService.GetContentAsync(siteId, item);
+ QDrantGetContentPointResult _selectedPoint = new QDrantGetContentPointResult();
+
+ if (qDrantData != null)
{
- string qDrantData = await _qDrantService.GetContentAsync(siteId, item);
- QDrantGetContentPointResult _selectedPoint = new QDrantGetContentPointResult();
-
- if (qDrantData != null)
- {
- _selectedPoint = JsonConvert.DeserializeObject(qDrantData)!;
- }
- extractedText += _selectedPoint.result.payload.name + ": " + _selectedPoint.result.payload.content + ", ";
+ _selectedPoint = JsonConvert.DeserializeObject(qDrantData)!;
}
+ extractedText += _selectedPoint.result.payload.name + ": " + _selectedPoint.result.payload.content + ", ";
+ }
+
+ }
+ else
+ {
+ extractedText = "VECTOR ERROR: ZERO INFORMATION FOUND";
+ }
- }
- else
- {
- extractedText = "VECTOR ERROR: ZERO INFORMATION FOUND";
- }
-
string contentJson = await GetContentFromQuery(sessionId,
"Enhance this text if needed, making its style and grammar suitable to be displayed as the content of a webpage",
@@ -308,7 +314,7 @@ namespace BLAIzor.Services
if (fixedResult != null)
{
OnStatusChangeReceived?.Invoke(sessionId, "Initiating the task you requested");
- await DisplayHtml(sessionId, fixedResult.Text, fixedResult.MethodToCall, fixedResult.Parameter, "");
+ await DisplayHtml(sessionId, fixedResult.Text, fixedResult.MethodToCall, fixedResult.Parameter);
}
}
@@ -319,7 +325,7 @@ namespace BLAIzor.Services
if (fixedResult != null)
{
string contentJson = await GetContentFromQuery(sessionId, fixedResult.Text, _workingContent);
- Console.Write("\r \n ProcessTextResult: Content: " + contentJson + "\r \n");
+ //Console.Write("\r \n ProcessTextResult: Content: " + contentJson + "\r \n");
await ProcessContent(sessionId, contentJson, templateId, collectionName);
}
}
@@ -335,7 +341,7 @@ namespace BLAIzor.Services
}
catch (Exception ex)
{
- Console.WriteLine($"❌ JSON parse failed: {ex.Message}");
+ //Console.WriteLine($"❌ JSON parse failed: {ex.Message}");
var prompt = BuildJsonFixPrompt(json, ex.Message, typeof(T).Name);
var fixedJson = await aiFixer(prompt);
@@ -349,7 +355,7 @@ namespace BLAIzor.Services
}
catch (Exception ex2)
{
- Console.WriteLine($"❌ AI-fix parse failed: {ex2.Message}");
+ //Console.WriteLine($"❌ AI-fix parse failed: {ex2.Message}");
return default;
}
}
@@ -380,18 +386,18 @@ namespace BLAIzor.Services
private string BuildJsonFixPrompt(string json, string errorMessage, string targetTypeName)
{
return $"""
- The following JSON was supposed to be parsed into an object of type {targetTypeName}, but it failed with this error:
+ The following JSON was supposed to be parsed into an object of type {targetTypeName}, but it failed with this error:
- {errorMessage}
+ {errorMessage}
- Please fix the formatting of the JSON so that it becomes valid and deserializable:
+ Please fix the formatting of the JSON so that it becomes valid and deserializable:
- --- JSON START ---
- {json}
- --- JSON END ---
+ --- JSON START ---
+ {json}
+ --- JSON END ---
- Only return the fixed JSON, with no explanation or formatting like ```json.
- """;
+ Only return the fixed JSON, with no explanation or formatting like ```json.
+ """;
}
@@ -422,15 +428,19 @@ namespace BLAIzor.Services
//contentResult.Photos.Add("Compliment response", "https://www.reactiongifs.com/r/review.gif");
//We have the text all available now, let's pass it to the voice generator
+ //TODO modify photos handling, move audio generation to the layout area
OnTextContentAvailable?.Invoke(sessionId, fixedResult.Text);
-
- string snippets = await GetSnippetsForDisplay(sessionId, templateId, fixedResult.Text, collectionName);
- await DisplayHtml(sessionId, fixedResult.Text, "", "", snippets, fixedResult.Topics, fixedResult.Photos);
+ List snippets = await GetSnippetsForDisplay(sessionId, collectionName);
+ //await DisplayLayoutPlanFromContent(sessionId, fixedResult.Text, snippets, fixedResult.Topics, fixedResult.Photos);
+ var result = await DisplayLayoutPlanFromContent(sessionId, fixedResult.Text, snippets, fixedResult.Topics, fixedResult.Photos);
+ if (result == null) result = new LayoutPlan();
+ await DisplayHtml(sessionId, result, snippets, fixedResult.Topics);
+ //OnContentReceived?.Invoke(sessionId, result.Blocks.Count.ToString());
}
}
catch (Exception ex)
{
- Console.WriteLine($"Error processing content: {ex.Message}");
+ //Console.WriteLine($"Error processing content: {ex.Message}");
OnContentReceived?.Invoke(sessionId, ex.Message);
}
}
@@ -440,8 +450,8 @@ namespace BLAIzor.Services
var errorResult = System.Text.Json.JsonSerializer.Deserialize(resultJson);
if (errorResult != null)
{
- Console.WriteLine($"Error Result: {errorResult.Text}");
- await DisplayHtml(sessionId, errorResult.Text, "", "", "");
+ //Console.WriteLine($"Error Result: {errorResult.Text}");
+ await DisplayLayoutPlanFromContent(sessionId, errorResult.Text, null, null, null);
}
}
@@ -463,9 +473,9 @@ namespace BLAIzor.Services
_apiKey = GetApiKey();
- //Console.Write("GetJSONResult called: " +extractedText);
+ ////Console.Write("GetJSONResult called: " +extractedText);
string systemMessage = "";
- if(forceUnmodified)
+ if (forceUnmodified)
{
systemMessage = "You are a helpful assistant of a website. Display the Content strictly in " + _scopedContentService.SelectedLanguage + " with a plain JSON object in the following format:\r\n\r\n1. " +
//"**chatGPTContentResult**:\r\n " +
@@ -478,7 +488,7 @@ namespace BLAIzor.Services
"Step 1: Start with defining above mentioned key topics of the initial document, and making the list of them. " +
"Step 2: After that add the above mentioned relevant image urls list." +
"Step 3: " +
- "- Turn the following content into a nice informative webpage content.\r\n " +
+ "- Turn the following content into a nice informative webpage content (DO NOT REMOVE URLS, PHOTO URLS though).\r\n " +
"- Start with the page title.\r\n" +
"- Structure it nicely without leaving out any information.\r\n " +
//"*** CONTENT START *** {" + extractedText + "} *** CONTENT END ***.\r\n" +
@@ -521,7 +531,7 @@ namespace BLAIzor.Services
"Do not include linebreaks or any formatting, just the plain json string. Make sure it is valid json, and every objects is closed properly" +
"Do NOT mark your answer with anything like `````json, and do not add any explanation.";
}
-
+
OnStatusChangeReceived?.Invoke(sessionId, "Constructing the answer");
string interMediateResult = string.Empty;
if (!UseWebsocket)
@@ -549,7 +559,7 @@ namespace BLAIzor.Services
interMediateResult = await _openAIRealtimeService.GetFullChatGPTResponseAsync(sessionId, systemMessage, userPrompt);
}
OnStatusChangeReceived?.Invoke(sessionId, "Mkay, I know now");
- Console.Write("GetContentFromQuery: Result decision: " + interMediateResult);
+ //Console.Write("GetContentFromQuery: Result decision: " + interMediateResult);
return interMediateResult;
}
@@ -565,7 +575,7 @@ namespace BLAIzor.Services
_apiKey = GetApiKey();
- //Console.Write("GetJSONResult called: " +extractedText);
+ ////Console.Write("GetJSONResult called: " +extractedText);
var systemMessage = "You are a helpful assistant. Respond strictly in " + _scopedContentService.SelectedLanguage + " as a JSON object in the following format:\r\n\r\n1. " +
//"**chatGPTContentResult**:\r\n " +
@@ -616,7 +626,7 @@ namespace BLAIzor.Services
interMediateResult = await _openAIRealtimeService.GetFullChatGPTResponseAsync(sessionId, systemMessage, userPrompt);
}
OnStatusChangeReceived?.Invoke(sessionId, "Mkay, I know now");
- Console.Write("GetExaminationResult: Result decision: " + interMediateResult);
+ //Console.Write("GetExaminationResult: Result decision: " + interMediateResult);
return interMediateResult;
}
@@ -631,7 +641,7 @@ namespace BLAIzor.Services
_apiKey = GetApiKey();
string extractedText = WordFileReader.ExtractText(rootpath);
- Console.Write("GetJSONResult called!");
+ //Console.Write("GetJSONResult called!");
var systemMessage = "You are a helpful assistant. Respond strictly in " + _scopedContentService.SelectedLanguage + " as a JSON object in the following formats:\r\n\r\n1. " +
"1. MethodResult:\r\n " +
@@ -685,7 +695,7 @@ namespace BLAIzor.Services
{
interMediateResult = await _openAIRealtimeService.GetFullChatGPTResponseAsync(sessionId, systemMessage, userPrompt);
}
- Console.Write("Result decision: " + interMediateResult);
+ //Console.Write("Result decision: " + interMediateResult);
return interMediateResult;
}
@@ -721,11 +731,11 @@ namespace BLAIzor.Services
extractedText = "VECTOR ERROR: ZERO INFORMATION FOUND";
}
- _workingContent = extractedText;
- Console.Write("\r \n GetJsonResultFromQuery: Working content: " + _workingContent + "\r \n");
+ _workingContent = extractedText.Replace("\"", "'");
+ //Console.Write("\r \n GetJsonResultFromQuery: Working content: " + _workingContent + "\r \n");
//string extractedText = WordFileReader.ExtractText(rootpath);
- Console.Write("GetJSONResult called!");
+ //Console.Write("GetJSONResult called!");
string systemMessage = $"You are a helpful assistant built in a website, trying to figure out what the User wants to do or know about.\r\n" +
"Your job is to classify the user's request into one of the following categories:\r\n" +
@@ -801,129 +811,513 @@ namespace BLAIzor.Services
interMediateResult = await _openAIRealtimeService.GetFullChatGPTResponseAsync(sessionId, systemMessage, userPrompt);
}
- Console.Write("\r \n GetJsonResultFromQuery: Result decision: " + interMediateResult + "\r \n");
+ //Console.Write("\r \n GetJsonResultFromQuery: Result decision: " + interMediateResult + "\r \n");
return interMediateResult;
}
- public async Task GetSnippetsForDisplay(string sessionId, int templateId, string interMediateResult, string collectionName)
+ public async Task> GetSnippetsForDisplay(string sessionId, string collectionName)
{
_apiKey = GetApiKey();
OnStatusChangeReceived?.Invoke(sessionId, "Looking up the UI template elements for you");
- string availableSnippetList = "";
+ //string availableSnippetList = "";
+
+ List snippets = new List();
+
var snippetscount = await _qDrantService.GetCollectionCount(collectionName);
for (int j = 1; j <= snippetscount; j++)
{
var snippet = await _qDrantService.GetSnippetAsync(j, collectionName);
QDrantGetPointResult x = JsonConvert.DeserializeObject(snippet);
-
- availableSnippetList += ("- " + x.result.payload.Name + ": " + x.result.payload.Description + ".\r\n");
+ snippets.Add(new HtmlSnippet { Id = x.result.payload.Id,
+ Name = x.result.payload.Name,
+ Description = x.result.payload.Description,
+ Type = x.result.payload.Type,
+ Variant = x.result.payload.Variant,
+ Tags = x.result.payload.Tags,
+ Slots = x.result.payload.Slots,
+ Html = x.result.payload.Html,
+ SampleHtml = x.result.payload.SampleHtml
+ });
+ //availableSnippetList += ("- " + x.result.payload.Name + ": " + x.result.payload.Description + ".\r\n");
}
- Console.Write(availableSnippetList);
- OnStatusChangeReceived?.Invoke(sessionId, "Fitting content to available UI elements");
- var systemMessage = "You are a helpful assistant for generating responses using HTML templates. Analyze the user query and choose the most suitable snippet type(s) for rendering the response." +
- "Respond with only the snippet name(s), comma-separated. No explanation. Identify the most suitable " +
- "HTML code snippet type to use for rendering your response based on user queries. The available snippet types are: " +
- availableSnippetList +
- //"The content to answer from from is here: " + extractedText + ". " +
- "If multiple snippets apply, list them in order of priority. ";
+ ////Console.Write(availableSnippetList);
+ OnStatusChangeReceived?.Invoke(sessionId, "Loading UI elements from the design database");
- var userMessage = "How would you render the following text in html: " + interMediateResult + " ? ";
+ //WTF????????
- string result = string.Empty;
- if (!UseWebsocket)
+
+ //var systemMessage = "You are a helpful assistant for generating responses using HTML templates. Analyze the user query and choose the most suitable snippet type(s) for rendering the response." +
+ // "Respond with only the snippet name(s), comma-separated. No explanation. Identify the most suitable " +
+ // "HTML code snippet type to use for rendering your response based on user queries. The available snippet types are: " +
+ // availableSnippetList +
+ // //"The content to answer from from is here: " + extractedText + ". " +
+ // "If multiple snippets apply, list them in order of priority. ";
+
+ //var userMessage = "How would you render the following text in html: " + interMediateResult + " ? ";
+
+ //string result = string.Empty;
+ //if (!UseWebsocket)
+ //{
+
+ // AiProvider = GetAiSettings();
+ // if (AiProvider == "cerebras")
+ // {
+ // result = await _cerebrasAPIService.GetSimpleCerebrasResponse(sessionId, systemMessage, userMessage);
+ // }
+ // else if (AiProvider == "chatgpt")
+ // {
+ // result = await _openAIApiService.GetSimpleChatGPTResponse(sessionId, systemMessage, userMessage);
+
+ // }
+ // else if (AiProvider == "deepseek")
+ // {
+ // result = await _deepSeekApiService.GetSimpleChatGPTResponse(sessionId, systemMessage, userMessage);
+ // }
+
+ //}
+ //else
+ //{
+ // result = await _openAIRealtimeService.GetFullChatGPTResponseAsync(sessionId, systemMessage, userMessage);
+ //}
+
+ //////Console.Write(result);
+ //List snippetList = result.Split(new[] { ',' }).ToList();
+
+ //int i = 0;
+
+ //OnStatusChangeReceived?.Invoke(sessionId, "Oooh got it! Loading UI elements from the design database");
+ ////Console.Write("ChatGPT decided!!!! ");
+ //let's send result to embeddingservice
+
+ //List vectorsList = new List();
+
+ //foreach (var snippet in snippetList)
+ //{
+ // var vectors = await _openAIEmbeddingService.GenerateEmbeddingAsync(result);
+ // vectorsList.Add(vectors);
+ //}
+
+ //List pointIds = new List();
+ //var collectionCount = await _qDrantService.GetCollectionCount(collectionName);
+
+ //if (collectionCount > 0)
+ //{
+ // foreach (var vector in vectorsList)
+ // {
+ // var qDrantresult = await _qDrantService.QuerySnippetAsync(vector, 3, collectionName);
+ // pointIds.Add(qDrantresult);
+ // }
+
+ // List qDrantDataList = new List();
+
+ // foreach (var pointId in pointIds)
+ // {
+ // var qDrantData = await _qDrantService.GetSnippetAsync(pointId, collectionName);
+ // qDrantDataList.Add(qDrantData);
+ // }
+
+ // List selectedPointList = new List();
+ // if (qDrantDataList != null)
+ // {
+ // foreach (var x in qDrantDataList)
+ // {
+ // var selectedPoint = JsonConvert.DeserializeObject(x)!;
+ // selectedPointList.Add(selectedPoint);
+ // }
+ // }
+
+ // string htmlToUse = "Your snippets to use: ";
+ // foreach (var selectedPoint in selectedPointList)
+ // {
+ // htmlToUse += selectedPoint.result.payload.Name + ": " + selectedPoint.result.payload.Html + ", ";
+
+ // }
+ // ////Console.Write(htmlToUse);
+ // return htmlToUse;
+ //}
+
+ return snippets;
+
+ }
+
+ public async Task DisplayHtml(string sessionId, LayoutPlan layoutPlan, List htmlToUse, string[]? topics = null)
+ {
+ //for textresult and errorresult
+ //Console.Write($"\n SessionId: {sessionId} \n");
+ OnStatusChangeReceived?.Invoke(sessionId, "Casting spells to draw customized UI");
+
+ //Console.WriteLine($"DISPLAYHTML Snippets: {htmlToUse.Count}\n\n");
+ //Console.WriteLine($"DISPLAYHTML Topics: {topics} \n\n");
+
+ StringBuilder lst = new StringBuilder("You are a helpful assistant generating HTML content in " + _scopedContentService.SelectedLanguage + " using Bootstrap. \n\n" +
+ "### Rules to Follow: \n" +
+ "- Please generate clean and structured HTML that goes between the menu and the footer of a Bootstrap5 webpage.\n" +
+ "- DO NOT include ``, ``, or `