feat(ai): ADR-032 Typhoon OCR integration - models, processors, cache, VRAM monitor, sandbox UI
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
// File: src/modules/ai/entities/ai-audit-log.entity.ts
|
||||
// Change Log
|
||||
// - 2026-05-14: เพิ่ม ADR-023 feedback fields โดยคง legacy audit fields ไว้ช่วงเปลี่ยนผ่าน.
|
||||
// - 2026-05-30: เพิ่ม modelType, vramUsageMB, cacheHit สำหรับ Typhoon OCR integration (T008, ADR-032).
|
||||
// Entity สำหรับตาราง ai_audit_logs — บันทึก AI Interaction และ feedback ตาม ADR-023
|
||||
|
||||
import {
|
||||
@@ -39,6 +40,19 @@ export class AiAuditLog extends UuidBaseEntity {
|
||||
@Column({ name: 'model_name', type: 'varchar', length: 100, nullable: true })
|
||||
modelName?: string;
|
||||
|
||||
// ประเภท OCR/LLM model ที่ใช้ เช่น tesseract, typhoon-ocr-3b, typhoon2.1-gemma3-4b (ADR-032)
|
||||
@Index('idx_ai_audit_model_type')
|
||||
@Column({ name: 'model_type', type: 'varchar', length: 50, nullable: true })
|
||||
modelType?: string;
|
||||
|
||||
// VRAM ที่ใช้จริง (MB) ณ เวลาประมวลผล (ADR-032)
|
||||
@Column({ name: 'vram_usage_mb', type: 'int', nullable: true })
|
||||
vramUsageMb?: number;
|
||||
|
||||
// ระบุว่าผลลัพธ์มาจาก Redis cache (true) หรือ OCR จริง (false) (ADR-032)
|
||||
@Column({ name: 'cache_hit', type: 'tinyint', width: 1, default: 0 })
|
||||
cacheHit!: boolean;
|
||||
|
||||
// JSON ที่ AI แนะนำก่อนมนุษย์ตรวจสอบ
|
||||
@Column({ name: 'ai_suggestion_json', type: 'json', nullable: true })
|
||||
aiSuggestionJson?: Record<string, unknown>;
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
// File: src/modules/ai/entities/ai-model-configuration.entity.ts
|
||||
// Change Log
|
||||
// - 2026-05-30: สร้าง AiModelConfiguration class สำหรับเก็บข้อมูลการตั้งค่า AI Model (T024, US2)
|
||||
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export enum AiModelType {
|
||||
LLM = 'llm',
|
||||
EMBEDDING = 'embedding',
|
||||
OCR = 'ocr',
|
||||
}
|
||||
|
||||
/** คลาสสำหรับเก็บข้อมูลการตั้งค่า AI Model (ไม่ผูกกับตาราง SQL โดยตรง ตาม data-model.md) */
|
||||
export class AiModelConfiguration {
|
||||
@ApiProperty({ description: 'รหัสประจำตัวโมเดล AI (UUIDv7)' })
|
||||
modelId!: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'ชื่อของโมเดล AI (เช่น gemma4:e4b, typhoon2.1-gemma3-4b)',
|
||||
})
|
||||
modelName!: string;
|
||||
|
||||
@ApiProperty({ description: 'ประเภทของโมเดล AI', enum: AiModelType })
|
||||
modelType!: AiModelType;
|
||||
|
||||
@ApiProperty({ description: 'ชื่อโมเดลใน Ollama Registry' })
|
||||
ollamaModelName!: string;
|
||||
|
||||
@ApiProperty({ description: 'ความต้องการ VRAM ในการประมวลผล (MB)' })
|
||||
vramRequirementMB!: number;
|
||||
|
||||
@ApiProperty({ description: 'สถานะเปิดใช้งานโมเดล' })
|
||||
isActive!: boolean;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'กรณีการใช้งานที่รองรับ (Use Cases)',
|
||||
type: [String],
|
||||
})
|
||||
useCases!: string[];
|
||||
|
||||
@ApiProperty({
|
||||
description: 'ประเภท Quantization (เช่น Q3_K_M)',
|
||||
nullable: true,
|
||||
})
|
||||
quantization?: string | null;
|
||||
|
||||
@ApiProperty({ description: 'เวลาที่สร้างข้อมูล' })
|
||||
createdAt!: Date;
|
||||
|
||||
@ApiProperty({ description: 'เวลาที่อัปเดตข้อมูลล่าสุด' })
|
||||
updatedAt!: Date;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// File: src/modules/ai/entities/ocr-engine-configuration.entity.ts
|
||||
// Change Log
|
||||
// - 2026-05-30: สร้าง OcrEngineConfiguration class สำหรับเก็บข้อมูลการตั้งค่า OCR Engine (T010, US1)
|
||||
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export enum OcrEngineType {
|
||||
TESSERACT = 'tesseract',
|
||||
TYPHOON_OCR = 'typhoon_ocr',
|
||||
}
|
||||
|
||||
/** คลาสสำหรับเก็บข้อมูลการตั้งค่า OCR Engine (ไม่ผูกกับตาราง SQL ตาม data-model.md) */
|
||||
export class OcrEngineConfiguration {
|
||||
@ApiProperty({ description: 'รหัสประจำตัว OCR Engine (UUIDv7)' })
|
||||
engineId!: string;
|
||||
|
||||
@ApiProperty({ description: 'ชื่อของ OCR Engine' })
|
||||
engineName!: string;
|
||||
|
||||
@ApiProperty({ description: 'ประเภทของ OCR Engine', enum: OcrEngineType })
|
||||
engineType!: OcrEngineType;
|
||||
|
||||
@ApiProperty({ description: 'สถานะเปิดใช้งาน' })
|
||||
isActive!: boolean;
|
||||
|
||||
@ApiProperty({ description: 'ความต้องการ VRAM ในการประมวลผล (MB)' })
|
||||
vramRequirementMB!: number;
|
||||
|
||||
@ApiProperty({ description: 'จำกัดเวลาในการประมวลผลสูงสุดต่อหน้า (วินาที)' })
|
||||
processingTimeLimitSeconds!: number;
|
||||
|
||||
@ApiProperty({ description: 'จำกัดการประมวลผลพร้อมกัน' })
|
||||
concurrentLimit!: number;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'รหัสประจำตัว OCR Engine สำรองกรณีขัดข้อง',
|
||||
nullable: true,
|
||||
})
|
||||
fallbackEngineId?: string | null;
|
||||
|
||||
@ApiProperty({ description: 'เวลาที่บันทึกข้อมูล' })
|
||||
createdAt!: Date;
|
||||
|
||||
@ApiProperty({ description: 'เวลาที่อัปเดตข้อมูลล่าสุด' })
|
||||
updatedAt!: Date;
|
||||
}
|
||||
Reference in New Issue
Block a user