ai insight rework #3, add root cause to daily ai insight

This commit is contained in:
Alberto-Audrix committed 2026-10-06 14:14:11 +07:00
1 parent c963bb778c
commit d5b0c12c40
8 files changed
+385 -47

No files matched your search

+18 -1
View File
@@ -15,6 +15,7 @@
export interface AiResult {
summary: string;
akar_masalah?: string;
insight: string;
}
@@ -28,6 +29,17 @@ const KESIMPULAN_KEYS = [
'conclusion',
];
/** Field names seen standing in for the root cause / factors. */
const AKAR_MASALAH_KEYS = [
'akar_masalah',
'akar_penyebab',
'root_cause',
'penyebab',
'faktor_penyebab',
'faktor_pemicu',
'indikasi_masalah',
];
/** Field names seen standing in for the recommendation. */
const INSIGHT_KEYS = [
'insight',
@@ -122,6 +134,9 @@ export const parseAiResult = (text: string): AiResult | null => {
const kesimpulanHit = takeFirst(parsed, KESIMPULAN_KEYS);
if (kesimpulanHit) used.add(kesimpulanHit.key);
const akarMasalahHit = takeFirst(parsed, AKAR_MASALAH_KEYS);
if (akarMasalahHit) used.add(akarMasalahHit.key);
const insightHit = takeFirst(parsed, INSIGHT_KEYS);
if (insightHit) used.add(insightHit.key);
@@ -136,6 +151,7 @@ export const parseAiResult = (text: string): AiResult | null => {
.filter((line) => line.length > 0);
let kesimpulan = kesimpulanHit?.text ?? '';
const akarMasalah = akarMasalahHit?.text ?? '';
let insight = insightHit?.text ?? '';
if (!kesimpulan && leftovers.length > 0) {
@@ -147,10 +163,11 @@ export const parseAiResult = (text: string): AiResult | null => {
insight = [insight, ...leftovers].filter(Boolean).join('\n\n');
}
if (!kesimpulan && !insight) return null;
if (!kesimpulan && !insight && !akarMasalah) return null;
return {
summary: kesimpulan || 'Model tidak mengembalikan ringkasan eksplisit.',
akar_masalah: akarMasalah || undefined,
insight: insight || 'Model tidak mengembalikan rekomendasi eksplisit.',
};
};