diff --git a/services/cms-service/src/handlers_test_templates.rs b/services/cms-service/src/handlers_test_templates.rs index b0a6d09..9038981 100644 --- a/services/cms-service/src/handlers_test_templates.rs +++ b/services/cms-service/src/handlers_test_templates.rs @@ -901,6 +901,7 @@ pub async fn generate_questions_with_rag( ) -> Result>, (StatusCode, String)> { use common::ai::{self, generate_embedding}; use serde_json::json; + let requested_num_questions = payload.num_questions.unwrap_or(5).clamp(1, 20); let mut mysql_questions: Vec; @@ -952,7 +953,7 @@ pub async fn generate_questions_with_rag( .bind(&pgvector) .bind(org_ctx.id) .bind(payload.course_id) - .bind(payload.num_questions.unwrap_or(5) * 3) // Get more for diversity + .bind(requested_num_questions * 3) // Get more for diversity .fetch_all(&pool) .await .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("Semantic search failed: {}", e)))?; @@ -997,7 +998,7 @@ pub async fn generate_questions_with_rag( .bind(org_ctx.id) .bind(payload.course_id) .bind(&format!("%{}%", topic)) - .bind(payload.num_questions.unwrap_or(5) * 3) + .bind(requested_num_questions * 3) .fetch_all(&pool) .await .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("Keyword fallback failed: {}", e)))?; @@ -1081,7 +1082,7 @@ pub async fn generate_questions_with_rag( .bind(org_ctx.id) .bind(payload.course_id) .bind(&format!("%{}%", topic)) - .bind(payload.num_questions.unwrap_or(5) * 3) + .bind(requested_num_questions * 3) .fetch_all(&pool) .await .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("Keyword search failed: {}", e)))?; @@ -1283,7 +1284,7 @@ pub async fn generate_questions_with_rag( // Save topic for later use let topic = payload.topic.clone().unwrap_or_else(|| "English grammar".to_string()); - let num_questions = payload.num_questions.unwrap_or(5); + let num_questions = requested_num_questions; let requested_question_type = match payload.question_type.as_deref() { Some("multiple-choice") => "multiple-choice".to_string(), Some("true-false") => "true-false".to_string(), diff --git a/web/studio/src/app/test-templates/page.tsx b/web/studio/src/app/test-templates/page.tsx index 72b0a6d..9581ba1 100644 --- a/web/studio/src/app/test-templates/page.tsx +++ b/web/studio/src/app/test-templates/page.tsx @@ -6,18 +6,33 @@ import TestTemplateManager from '@/components/TestTemplates/TestTemplateManager' import TestTemplateForm from '@/components/TestTemplates/TestTemplateForm'; export default function TestTemplatesPage() { - const [view, setView] = useState<'list' | 'create'>('list'); + const [view, setView] = useState<'list' | 'create' | 'edit'>('list'); + const [editingTemplateId, setEditingTemplateId] = useState(null); return ( {view === 'list' ? ( setView('create')} + onCreateTemplate={() => { + setEditingTemplateId(null); + setView('create'); + }} + onEditTemplate={(template) => { + setEditingTemplateId(template.id); + setView('edit'); + }} /> ) : ( setView('list')} - onCancel={() => setView('list')} + templateId={view === 'edit' ? editingTemplateId || undefined : undefined} + onSuccess={() => { + setEditingTemplateId(null); + setView('list'); + }} + onCancel={() => { + setEditingTemplateId(null); + setView('list'); + }} /> )} diff --git a/web/studio/src/components/TestTemplates/TestTemplateForm.tsx b/web/studio/src/components/TestTemplates/TestTemplateForm.tsx index a4d4f24..2d472c4 100644 --- a/web/studio/src/components/TestTemplates/TestTemplateForm.tsx +++ b/web/studio/src/components/TestTemplates/TestTemplateForm.tsx @@ -53,6 +53,7 @@ export default function TestTemplateForm({ onSuccess, onCancel }: TestTemplateFo const [expandedQuestion, setExpandedQuestion] = useState(null); const [aiContext, setAiContext] = useState(''); const [aiQuestionType, setAiQuestionType] = useState('multiple-choice'); + const [aiQuestionCount, setAiQuestionCount] = useState(5); // MySQL course selection state const [mysqlPlans, setMysqlPlans] = useState([]); @@ -249,7 +250,7 @@ export default function TestTemplateForm({ onSuccess, onCancel }: TestTemplateFo }, body: JSON.stringify({ topic: aiContext, - num_questions: 5, + num_questions: aiQuestionCount, question_type: aiQuestionType, }), }); @@ -577,6 +578,26 @@ export default function TestTemplateForm({ onSuccess, onCancel }: TestTemplateFo +