This commit is contained in:
root
2025-10-07 16:28:52 +05:00
parent a65bd39499
commit 67d3a266a0
2 changed files with 15 additions and 30 deletions
@@ -154,17 +154,17 @@ public class OpenAiChartService {
// learningsAsString + "\n---"; // learningsAsString + "\n---";
// } // }
private String buildChartDataPrompt(String learningsAsString) { private String buildChartDataPrompt(String learningsAsString) {
return "You are an AI data analyst. Carefully analyze the following text. Find all sets of numerical data suitable for simple bar or pie charts. For EACH data set you find, create a JSON object." return "You are an AI data analyst robot. Carefully analyze the following text. Find all sets of numerical data suitable for simple bar or pie charts. For EACH data set you find, create a JSON object."
+ +
" Return ONLY a JSON array of these objects. The structure of each object MUST STRICTLY be: " + " Return ONLY a JSON array of these objects. The structure of each object MUST STRICTLY be: " +
"{\"chartType\": \"bar\" or \"pie\", \"title\": \"Chart Title\", \"labels\": [\"Label 1\"], \"data\": [number1]}. " "{\"chartType\": \"bar\" or \"pie\", \"title\": \"Chart Title\", \"labels\": [\"Label 1\"], \"data\": [number1, number2]}. "
+ +
// --- НОВЫЕ ВАЖНЫЕ ПРАВИЛА --- "CRITICAL RULES:\n" +
"IMPORTANT RULES:\n" + "1. The 'data' array MUST contain ONLY NUMBERS. Do not include text, units, or placeholders like 'trillion' or 'placeholder'. Convert all values to simple numbers (e.g., '1.08 trillion' becomes 1.08).\n"
"1. The 'data' array MUST contain ONLY NUMBERS (e.g., 1.08), not text like 'KZT1.08 trillion'.\n" + +
"2. DO NOT omit any keys.\n\n" + "2. If a numerical value is not available for a label, you MUST use the number 0 as a placeholder.\n" +
// --- КОНЕЦ НОВЫХ ПРАВИЛ --- "3. DO NOT omit any keys.\n\n" +
"Example of a correct response:\n" + "Example of a correct response:\n" +
"[{\"chartType\":\"bar\",\"title\":\"Growth by Year\",\"labels\":[\"2023\",\"2024\"],\"data\":[100,150]}]" "[{\"chartType\":\"bar\",\"title\":\"Growth by Year\",\"labels\":[\"2023\",\"2024\"],\"data\":[100,150]}]"
@@ -92,38 +92,23 @@ public class ReportSynthesisService {
} }
private String buildTextPrompt(String originalQuery, String learningsAsString, String lang) { private String buildTextPrompt(String originalQuery, String learningsAsString, String lang) {
return "You are a professional AI analyst. Your task is to write a detailed, structured, and well-written report based on the provided data." return "You are a professional AI report writer. Your task is to write a detailed and structured report based on the provided data."
+ +
"\n\n" + "\n\n" +
"IMPORTANT: Do not ask any clarifying questions at the end. Do not write any personal introductions or conclusions outside of the report's content. Your response must be ONLY the report itself and nothing more." "CRITICAL INSTRUCTION: Your entire response must be ONLY the final report in Markdown format. Start directly with the main title. Do NOT include any conversational text, introductions, summaries of your instructions, or any questions at the end. Your output should be pure Markdown."
+ +
"\n\n" + "\n\n" +
"### Research Topic:\n" + "### Research Topic:\n" +
originalQuery + "\n\n" + originalQuery + "\n\n" +
"### Collected Data (Learnings):\n" + "### Collected Data (Learnings):\n" +
learningsAsString + "\n\n" + learningsAsString + "\n\n" +
"### Your Task:\n" + "### Report Requirements:\n" +
"1. **Language:** Write the report entirely in the " + (lang == null ? "English" : lang) "1. **Language:** " + (lang == null ? "English" : lang) + ".\n" +
+ " language.\n" + "2. **Structure:** The report must have an introduction, a main body with sections (using `##`) and subsections (using `###`), and a conclusion.\n"
"2. **Structure:** The report must have a clear structure: an introduction, a main body with several sections and subsections, and a conclusion.\n"
+ +
"3. **Formatting:** Use Markdown. For main section headings, use `##`. For subsections, use `###`. For lists, use `-`.\n" "3. **Style:** Transform the disjointed learnings into a cohesive, well-written article.\n" +
+ "4. **Constraint:** Use ONLY the information from the 'Collected Data'.\n\n" +
"4. **Style:** Transform the disjointed learnings into a single, cohesive, and well-written article. Do not just list the facts; analyze, summarize, and build a logical narrative.\n" "Begin your response immediately with the main title using '#'.";
+
"5. **Constraint:** Use ONLY the information provided in the collected data. Do not add any information that is not present in the source learnings.\n\n"
+
"Start the report with a main title (using `#`).";
}
private String buildChartDataPrompt(String learningsAsString) {
return "Ты — AI-аналитик данных. Внимательно проанализируй следующий текст. Найди в нём все наборы числовых данных, которые можно представить в виде простых диаграмм (столбчатых или круговых). Для КАЖДОГО найденного набора данных создай JSON-объект. Верни ТОЛЬКО JSON-массив этих объектов. Структура каждого объекта: {\"chartType\": \"bar\" или \"pie\", \"title\": \"Название диаграммы\", \"labels\": [\"Метка 1\"], \"data\": [число1]}. Если подходящих данных нет, верни пустой массив []. Текст для анализа:\n---\n"
+ learningsAsString + "\n---";
}
private String buildSvgPrompt(String json) {
return "Ты — эксперт по визуализации данных. На основе следующего JSON, сгенерируй полный и валидный SVG-код для диаграммы. SVG должен быть стильным и читаемым, с подписями на русском языке. Не добавляй никаких комментариев, верни ТОЛЬКО SVG-код. JSON с данными:\n---\n"
+ json + "\n---";
} }
private String extractJsonArray(String ollamaResponse) { private String extractJsonArray(String ollamaResponse) {