Update app.py
Browse files129 unmodified lines130131132133134135136137135136138139140141142143144145146147139140141142143148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177145178179180129 unmodified lines is_ar = language != "en" lang = "Arabic" if is_ar else "English"
if task == "insights": key = "insights" schema = ( '{"insights":[' schema = ('{"insights":[{"title":"...","finding":"...",' '"evidence":"...","recommendation":"..."}]}') '{"title":"...","finding":"...",' '"evidence":"...","recommendation":"..."},' '{"title":"...","finding":"...",' '"evidence":"...","recommendation":"..."},' '{"title":"...","finding":"...",' '"evidence":"...","recommendation":"..."}' ']}' ) system = ( f"You are a careful KPI performance analyst. Reply in {lang}. " "Use only supplied data; never invent figures, trends, causes or facts. " f"Return valid JSON only with schema {schema}. Exactly 3 insights in this order: " "notable improvement, alert, recommendation. For Arabic, titles must be exactly: " "تحسين ملحوظ, تنبيه, توصية. For English: Notable Improvement, Alert, Recommendation. " "Evidence must cite provided values or say data is insufficient. Keep each field concise and actionable." "Use only the supplied data. Never invent figures, trends, causes, " "or facts. Return valid JSON only, matching the exact schema. " "Return exactly 3 insights in this order: improvement, alert, recommendation. " "The title is already displayed separately in the user interface. " "For Arabic, titles must be exactly: تحسين ملحوظ, تنبيه, توصية. " "For English, titles must be exactly: Notable Improvement, Alert, Recommendation. " "Do not repeat the title inside the finding. " "For each insight, write finding as a natural, concise sentence that uses " "the KPI's actual human-readable kpi_name, never its technical kpi_id. " "For example, say 'تحسين رضا المتعاملين' instead of 'KPI_01'. " "Do not include KPI IDs in finding, evidence, or recommendation unless " "absolutely necessary to distinguish indicators. " "The evidence field must begin with 'الدليل من البيانات:' in Arabic " "or 'Evidence from the data:' in English, followed by specific supplied " "values, dates, or trends. " "The recommendation field must begin with 'الإجراء المقترح:' in Arabic " "or 'Suggested action:' in English, followed by a practical action. " "Keep the labels inside evidence and recommendation because they are part " "of the desired response format. " "For the improvement insight, describe the actual improvement and its values. " "For the alert insight, describe the concern or state that data is insufficient. " "For the recommendation insight, provide a useful action grounded in the data. " "Do not add Markdown headings or extra fields. " "Keep all statements concise, readable, and actionable." ) user = ( "Analyze the current KPI values, targets, statuses and recent history. " "Use the human-readable kpi_name in the analysis, not kpi_id. " "KPI data:\n" + json.dumps(kpis, ensure_ascii=False) ) user = "Analyze the current KPI values, targets, statuses and recent history. KPI data:\n" + json.dumps(kpis, ensure_ascii=False) else: key = "indicators" schema = ('{"indicators":[{"kpi_name":"...","description":"...",'app.py+40-8