This commit is contained in:
1 parent
208e11e4f8
commit
a8b49374f1
44 files changed
+119956
-552
No files matched your search
@@ -220,8 +220,16 @@ const parseDashboardInsightJson = (text) => {
|
||||
|
||||
|
||||
|
||||
const buildDashboardInsightPrompt = (contextText, dayAge) => {
|
||||
const buildDashboardInsightPrompt = (contextText, dayAge, reportType = 'daily', reportPeriod = null) => {
|
||||
const bookRef = dayAge ? cp707.buildBookReferenceContext(dayAge) : '';
|
||||
|
||||
let taskInstruction = 'Analisis data operasional harian berikut dan hasilkan insight terstruktur.';
|
||||
if (reportType === 'weekly') {
|
||||
taskInstruction = `Hasilkan LAPORAN MINGGUAN (${reportPeriod || 'Minggu ini'}) yang merangkum performa minggu ini dibandingkan standar CP 707. Analisis tren dan rata-rata performa.`;
|
||||
} else if (reportType === 'end_cycle') {
|
||||
taskInstruction = 'Hasilkan LAPORAN AKHIR SIKLUS (EVALUASI PANEN) yang merangkum keseluruhan performa dari awal hingga akhir periode (panen). Evaluasi total keberhasilan siklus ini.';
|
||||
}
|
||||
|
||||
return `
|
||||
Anda adalah analis operasional peternakan ayam broiler CP 707.
|
||||
|
||||
@@ -234,7 +242,7 @@ PANDUAN PENTING:
|
||||
${bookRef}
|
||||
|
||||
Tugas:
|
||||
Analisis data operasional berikut dan hasilkan insight terstruktur.
|
||||
${taskInstruction}
|
||||
Kembalikan HANYA satu objek JSON valid dengan struktur persis seperti berikut (tanpa ada teks penjelasan atau komentar di luar objek JSON):
|
||||
|
||||
{
|
||||
@@ -296,8 +304,8 @@ ${contextText}
|
||||
`.trim();
|
||||
};
|
||||
|
||||
const buildCacheKey = (cycleId, kandangId, version) =>
|
||||
`${cycleId}:${kandangId || 'all'}:${version}`;
|
||||
const buildCacheKey = (cycleId, kandangId, version, reportType = 'daily', reportPeriod = null) =>
|
||||
`${cycleId}:${kandangId || 'all'}:${version}:${reportType}:${reportPeriod || 'current'}`;
|
||||
|
||||
const toNumber = (value) => {
|
||||
const n = Number(value);
|
||||
@@ -723,8 +731,10 @@ const generateDashboardInsight = async ({
|
||||
contextPack,
|
||||
version = INSIGHT_VERSION,
|
||||
forceRefresh = false,
|
||||
reportType = 'daily',
|
||||
reportPeriod = null,
|
||||
}) => {
|
||||
const cacheKey = buildCacheKey(cycleId, kandangId, version);
|
||||
const cacheKey = buildCacheKey(cycleId, kandangId, version, reportType, reportPeriod);
|
||||
|
||||
if (!forceRefresh) {
|
||||
const existingRequest = dashboardInsightRequests.get(cacheKey);
|
||||
@@ -775,7 +785,7 @@ const generateDashboardInsight = async ({
|
||||
}
|
||||
|
||||
const lmStudioBaseUrl = process.env.LM_STUDIO_BASE_URL || 'http://127.0.0.1:11434';
|
||||
let modelName = process.env.LLM_MODEL_NAME || 'deepseek-r1:8b';
|
||||
let modelName = process.env.LLM_MODEL_NAME || 'qwen2.5:7b';
|
||||
try {
|
||||
const modelsResponse = await fetch(`${lmStudioBaseUrl}/v1/models`, { signal: AbortSignal.timeout(2000) });
|
||||
if (modelsResponse.ok) {
|
||||
@@ -798,20 +808,20 @@ const generateDashboardInsight = async ({
|
||||
const payload = isOllama ? {
|
||||
model: modelName,
|
||||
messages: [
|
||||
{ role: 'system', content: 'Anda adalah analis operasional peternakan ayam broiler CP 707. Kembalikan HANYA format JSON valid. DILARANG BERPIKIR TERLALU PANJANG. RINGKAS ANALISIS ANDA, LANGSUNG KE INTI MASALAH!' },
|
||||
{ role: 'user', content: buildDashboardInsightPrompt(finalContextText, dayAge) }
|
||||
{ role: 'system', content: 'Anda adalah analis operasional peternakan ayam broiler CP 707. Kembalikan HANYA format JSON valid, tanpa teks tambahan di luar JSON. Langsung ke poin utama.' },
|
||||
{ role: 'user', content: buildDashboardInsightPrompt(finalContextText, dayAge, reportType, reportPeriod) }
|
||||
],
|
||||
stream: false,
|
||||
options: {
|
||||
num_ctx: 8192,
|
||||
num_predict: 2048,
|
||||
num_predict: 8192,
|
||||
temperature: 0.1
|
||||
}
|
||||
} : {
|
||||
model: modelName,
|
||||
messages: [
|
||||
{ role: 'system', content: 'Anda adalah analis operasional peternakan ayam broiler CP 707 (PT Charoen Pokphand Indonesia). Analisis HANYA berdasarkan standar buku CP 707 edisi Juli 2023. Kembalikan HANYA format JSON valid. Dilarang memberikan penjelasan di luar JSON.' },
|
||||
{ role: 'user', content: buildDashboardInsightPrompt(finalContextText, dayAge) }
|
||||
{ role: 'user', content: buildDashboardInsightPrompt(finalContextText, dayAge, reportType, reportPeriod) }
|
||||
],
|
||||
temperature: 0.1,
|
||||
max_tokens: 2048,
|
||||
@@ -865,7 +875,7 @@ const generateDashboardInsight = async ({
|
||||
|
||||
let parsed = null;
|
||||
if (success) {
|
||||
// Bersihkan markdown code block (```json ... ```) dan think tags dari DeepSeek R1
|
||||
// Bersihkan markdown code block (```json ... ```) dan think tags dari LLM (Qwen)
|
||||
const cleanedResponseText = responseText
|
||||
.replace(/<think>[\s\S]*?<\/think>/g, '')
|
||||
.replace(/```json\s*/gi, '')
|
||||
|
||||
Reference in new issue
Block a user