diff --git a/backend/src/modules/ai/processors/ai-batch.processor.spec.ts b/backend/src/modules/ai/processors/ai-batch.processor.spec.ts index c57a3d82..619e9da1 100644 --- a/backend/src/modules/ai/processors/ai-batch.processor.spec.ts +++ b/backend/src/modules/ai/processors/ai-batch.processor.spec.ts @@ -1,5 +1,6 @@ // File: src/modules/ai/processors/ai-batch.processor.spec.ts // Change Log +// - 2026-06-08: เพิ่มการทดสอบการส่งตัวเลือก generate (format: json, num_ctx: 16384) สำหรับ migrate-document // - 2026-05-21: สร้าง Unit Test สำหรับ AiBatchProcessor ครอบคลุม embed-document และ sandbox-rag (T032). // - 2026-05-21: เพิ่มการทดสอบ sandbox-extract พร้อม mock OcrService, OllamaService และ Redis (T039). // - 2026-05-21: แก้ไข ESLint unexpected any และ unsafe member access โดยกำหนด type ให้ redis เป็น Record @@ -520,7 +521,14 @@ describe('AiBatchProcessor', () => { expect(ocrService.detectAndExtract).toHaveBeenCalledWith({ pdfPath: '/files/test.pdf', }); - expect(ollamaService.generate).toHaveBeenCalledTimes(1); + expect(ollamaService.generate).toHaveBeenCalledWith( + expect.any(String), + expect.objectContaining({ + format: 'json', + timeoutMs: 120000, + options: { num_ctx: 16384, num_predict: 4096 }, + }) + ); expect(mockTagsService.findOrSuggestTags).toHaveBeenCalledTimes(1); expect(mockMigrationService.enqueueRecord).toHaveBeenCalledWith( expect.objectContaining({ diff --git a/backend/src/modules/ai/processors/ai-batch.processor.ts b/backend/src/modules/ai/processors/ai-batch.processor.ts index 69bbcd60..4d8528c7 100644 --- a/backend/src/modules/ai/processors/ai-batch.processor.ts +++ b/backend/src/modules/ai/processors/ai-batch.processor.ts @@ -1,5 +1,6 @@ // File: src/modules/ai/processors/ai-batch.processor.ts // Change Log +// - 2026-06-08: แก้ไขปัญหา LLM JSON response truncated โดยการเพิ่ม num_ctx เป็น 16384 ใน sandbox-extract, sandbox-ai-extract และ migrate-document // - 2026-05-15: เพิ่ม processor สำหรับ ai-batch queue ตาม ADR-023A. // - 2026-05-15: เพิ่ม EmbeddingService สำหรับ embed-document logic (T022). // - 2026-05-21: เพิ่มการรองรับ sandbox-rag และ sandbox-extract สำหรับ Superadmin sandbox. @@ -533,7 +534,7 @@ export class AiBatchProcessor extends WorkerHost { { format: 'json', timeoutMs: 120000, - ollamaOptions: { num_ctx: 8192, num_predict: 4096 }, // num_predict ป้องกัน output ถูก truncate + ollamaOptions: { num_ctx: 16384, num_predict: 4096 }, // num_predict ป้องกัน output ถูก truncate } ); await this.aiPromptsService.saveTestResult( @@ -737,7 +738,7 @@ export class AiBatchProcessor extends WorkerHost { { format: 'json', timeoutMs: 120000, - ollamaOptions: { num_ctx: 8192, num_predict: 4096 }, // num_predict ป้องกัน output ถูก truncate + ollamaOptions: { num_ctx: 16384, num_predict: 4096 }, // num_predict ป้องกัน output ถูก truncate } ); @@ -930,7 +931,9 @@ export class AiBatchProcessor extends WorkerHost { let aiResponse: string; try { aiResponse = await this.ollamaService.generate(resolvedPrompt, { + format: 'json', timeoutMs: 120000, + options: { num_ctx: 16384, num_predict: 4096 }, }); } catch (err: unknown) { const errMsg = err instanceof Error ? err.message : String(err); diff --git a/specs/88-logs/_backend_logs.md b/specs/88-logs/_backend_logs.md index b436337b..54075380 100644 Binary files a/specs/88-logs/_backend_logs.md and b/specs/88-logs/_backend_logs.md differ