feat(ai): implement unified prompt management UX/UI (ADR-037)
- Add context config endpoints (GET/PUT /api/ai/prompts/:type/:version/context-config) - Add execution profile endpoints (CRUD /api/ai/execution-profiles) - Add sandbox RAG Prep endpoint (POST /api/ai/admin/sandbox/rag-prep) - Create Prompt Management UI with multi-type support - Add ContextConfigEditor, PromptEditor, RuntimeParametersPanel components - Add SandboxTabs for 3-step workflow (OCR, Extract, RAG Prep) - Add database deltas for ai_execution_profiles and additional prompt types - Update quickstart.md with production backend URLs - Add comprehensive test coverage for new features
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
-- File: specs/03-Data-and-Storage/deltas/2026-06-14-create-ai-execution-profiles.sql
|
||||
-- Change Log:
|
||||
-- - 2026-06-14: Created ai_execution_profiles and ai_sandbox_profiles tables (conforming to task T001)
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ai_execution_profiles (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT COMMENT 'ID ภายใน',
|
||||
profile_name VARCHAR(50) NOT NULL COMMENT 'ชื่อ profile',
|
||||
canonical_model VARCHAR(20) NOT NULL DEFAULT 'np-dms-ai' COMMENT 'Model identity',
|
||||
temperature DECIMAL(4,3) NOT NULL COMMENT 'LLM temperature',
|
||||
top_p DECIMAL(4,3) NOT NULL COMMENT 'LLM top_p',
|
||||
max_tokens INT NULL COMMENT 'Maximum tokens',
|
||||
num_ctx INT NULL COMMENT 'Context window size',
|
||||
repeat_penalty DECIMAL(5,3) NOT NULL COMMENT 'Repeat penalty',
|
||||
keep_alive_seconds INT NOT NULL COMMENT 'Model keep_alive in seconds',
|
||||
is_active TINYINT(1) NOT NULL DEFAULT 1 COMMENT '1 = active; 0 = disabled',
|
||||
updated_by INT NULL COMMENT 'user_id',
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE KEY uk_profile_name (profile_name),
|
||||
INDEX idx_profile_active (profile_name, is_active),
|
||||
FOREIGN KEY (updated_by) REFERENCES users(user_id)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci
|
||||
COMMENT = 'ตาราง execution profile parameters สำหรับ np-dms-ai';
|
||||
|
||||
CREATE TABLE IF NOT EXISTS ai_sandbox_profiles (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT COMMENT 'ID ภายใน',
|
||||
profile_name VARCHAR(50) NOT NULL COMMENT 'ชื่อ profile',
|
||||
canonical_model VARCHAR(20) NOT NULL DEFAULT 'np-dms-ai' COMMENT 'Model identity',
|
||||
temperature DECIMAL(4,3) NOT NULL COMMENT 'LLM temperature',
|
||||
top_p DECIMAL(4,3) NOT NULL COMMENT 'LLM top_p',
|
||||
max_tokens INT NULL COMMENT 'Maximum tokens',
|
||||
num_ctx INT NULL COMMENT 'Context window size',
|
||||
repeat_penalty DECIMAL(5,3) NOT NULL COMMENT 'Repeat penalty',
|
||||
keep_alive_seconds INT NOT NULL COMMENT 'Model keep_alive in seconds',
|
||||
updated_by INT NULL COMMENT 'user_id',
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE KEY uk_ai_sandbox_profile_name (profile_name),
|
||||
INDEX idx_ai_sandbox_profile_model (canonical_model),
|
||||
FOREIGN KEY (updated_by) REFERENCES users(user_id)
|
||||
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci
|
||||
COMMENT = 'ตาราง sandbox profile parameters';
|
||||
@@ -0,0 +1,54 @@
|
||||
-- File: specs/03-Data-and-Storage/deltas/2026-06-14-seed-additional-prompt-types.sql
|
||||
-- Change Log:
|
||||
-- - 2026-06-14: Seed additional prompt types for RAG Query, RAG Prep, and Classification (conforming to task T003)
|
||||
|
||||
INSERT INTO ai_prompts (
|
||||
public_id,
|
||||
prompt_type,
|
||||
version_number,
|
||||
template,
|
||||
field_schema,
|
||||
context_config,
|
||||
is_active,
|
||||
manual_note,
|
||||
activated_at,
|
||||
created_by
|
||||
) VALUES
|
||||
(
|
||||
UUID(),
|
||||
'rag_query_prompt',
|
||||
1,
|
||||
'You are a professional assistant analyzing project documents. Based on the provided context, answer the user query.\n\nContext:\n{{context}}\n\nUser Query:\n{{ocr_text}}\n\nAnswer:',
|
||||
NULL,
|
||||
NULL,
|
||||
1,
|
||||
'Initial seed for RAG query prompt',
|
||||
CURRENT_TIMESTAMP,
|
||||
(SELECT user_id FROM users WHERE username = 'superadmin' LIMIT 1)
|
||||
),
|
||||
(
|
||||
UUID(),
|
||||
'rag_prep_prompt',
|
||||
1,
|
||||
'Analyze the following OCR text and prepare chunks for retrieval database.\n\nOCR TEXT:\n{{ocr_text}}\n\nChunks:',
|
||||
NULL,
|
||||
NULL,
|
||||
1,
|
||||
'Initial seed for RAG prep prompt',
|
||||
CURRENT_TIMESTAMP,
|
||||
(SELECT user_id FROM users WHERE username = 'superadmin' LIMIT 1)
|
||||
),
|
||||
(
|
||||
UUID(),
|
||||
'classification_prompt',
|
||||
1,
|
||||
'Classify the following document based on its OCR text.\n\nOCR TEXT:\n{{ocr_text}}\n\nClassification (Correspondence, Transmittal, Circulation, RFA, Shop Drawing, Contract Drawing):',
|
||||
NULL,
|
||||
NULL,
|
||||
1,
|
||||
'Initial seed for Classification prompt',
|
||||
CURRENT_TIMESTAMP,
|
||||
(SELECT user_id FROM users WHERE username = 'superadmin' LIMIT 1)
|
||||
)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
prompt_type = prompt_type;
|
||||
@@ -0,0 +1,21 @@
|
||||
-- File: specs/03-Data-and-Storage/deltas/2026-06-14-seed-execution-profiles.sql
|
||||
-- Change Log:
|
||||
-- - 2026-06-14: Seed default profiles for execution profiles (conforming to task T002)
|
||||
|
||||
INSERT INTO ai_execution_profiles (
|
||||
profile_name, canonical_model, temperature, top_p, max_tokens, num_ctx, repeat_penalty, keep_alive_seconds, is_active
|
||||
) VALUES
|
||||
('interactive', 'np-dms-ai', 0.700, 0.900, 2048, 4096, 1.150, 300, 1),
|
||||
('standard', 'np-dms-ai', 0.500, 0.800, 4096, 8192, 1.150, 600, 1),
|
||||
('quality', 'np-dms-ai', 0.100, 0.950, 8192, 8192, 1.150, 600, 1),
|
||||
('deep-analysis', 'np-dms-ai', 0.300, 0.850, 8192, 32768, 1.150, 0, 1),
|
||||
('ocr-extract', 'np-dms-ocr', 0.100, 0.100, NULL, NULL, 1.100, 0, 1)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
canonical_model = VALUES(canonical_model),
|
||||
temperature = VALUES(temperature),
|
||||
top_p = VALUES(top_p),
|
||||
max_tokens = VALUES(max_tokens),
|
||||
num_ctx = VALUES(num_ctx),
|
||||
repeat_penalty = VALUES(repeat_penalty),
|
||||
keep_alive_seconds = VALUES(keep_alive_seconds),
|
||||
is_active = VALUES(is_active);
|
||||
Reference in New Issue
Block a user