diff --git a/src/components/Card/PlanLessonCard.tsx b/src/components/Card/PlanLessonCard.tsx index 3abb306..5debfb6 100644 --- a/src/components/Card/PlanLessonCard.tsx +++ b/src/components/Card/PlanLessonCard.tsx @@ -71,7 +71,6 @@ const PlanLessonCard = ({ updateNodeAt(id, { type: planNode.type, topic: planNode.topic, - explanation: planNode.explanation, details: planNode.details, learning_outcome: planNode.learning_outcome, duration: planNode.duration, @@ -356,7 +355,6 @@ const PlanLessonCard = ({ updateNodeAt(id, { type: type, topic: plannedNode.topic, - explanation: plannedNode.explanation, details: plannedNode.details, learning_outcome: plannedNode.learning_outcome, duration: plannedNode.duration, diff --git a/src/components/Modals/AIToolModal.tsx b/src/components/Modals/AIToolModal.tsx index 1f746d2..cf9d30b 100644 --- a/src/components/Modals/AIToolModal.tsx +++ b/src/components/Modals/AIToolModal.tsx @@ -27,6 +27,7 @@ import { API } from '../../data/api'; import { AIExerciseGenerated, AIMaterialGenerated, + AIMaterialType, EducationLevel, LearningOutcome, QuestionTypeMap, @@ -136,7 +137,7 @@ const AIToolModal = ({ throw ': no text given'; } const response: AxiosResponse = await API.analyseMaterial({ - text: sourceMaterial, + url: sourceMaterial, }); console.log(response); setTitle(response.data.title); @@ -583,27 +584,38 @@ const AIToolModal = ({ macro_subject: macroSubjectGen, topics: [ { - title: titleGen, - learning_outcome: learningOutcome, topics: topicGen, + title: '', + learning_outcome: learningOutcome, }, ], education_level: eduLevel, learning_outcome: learningOutcome, duration: duration, language: language, + type_of_file: 'md', model: 'Gemini', - }); + } as AIMaterialType); + setScreen1(true); setScreen3(false); + + if (!response) throw 'Error generate'; + console.log(response.data); - const dataGen: AIMaterialGenerated = response.data; + + const dataGen: AIMaterialGenerated = { + type_of_file: 'md', + content: response.data, + }; + let adaptedData; + switch (exerciseTypeKey) { case 'ReadMaterial': console.log('creating readMaterial'); adaptedData = { - text: dataGen.material, + text: dataGen.content, link: '', }; break; diff --git a/src/components/Modals/CreateAILPModal.tsx b/src/components/Modals/CreateAILPModal.tsx index fe35b6e..093ced7 100644 --- a/src/components/Modals/CreateAILPModal.tsx +++ b/src/components/Modals/CreateAILPModal.tsx @@ -39,6 +39,7 @@ import { import { AIExerciseGenerated, AIMaterialGenerated, + AIMaterialType, AIPlanLessonResponse, AnalyzedMaterial, EducationLevel, @@ -322,7 +323,7 @@ const CreateAILPModal = ({ isOpen, onClose, action }: ModaTemplateProps) => { throw new Error('Missing sourceMaterial'); } const response: AxiosResponse = await API.analyseMaterial({ - text: sourceMaterial, + url: sourceMaterial, }); console.log(response.data as AnalyzedMaterial); setAnalyzedMaterial(response.data as AnalyzedMaterial); @@ -580,11 +581,14 @@ const CreateAILPModal = ({ isOpen, onClose, action }: ModaTemplateProps) => { const isIntegrated = QuestionTypeMap.find( (qType) => qType.integrated && qType.key === node.type ); + const topicExplanation = selectedTopic.find( + (topic) => topic.topic === node.topic + )?.explanation; return { type: isIntegrated ? node.type : 'open question', topic: node.topic, - explanation: node.explanation || '', + explanation: topicExplanation || '', details: node.details, learning_outcome: node.learning_outcome, duration: node.duration, @@ -737,20 +741,26 @@ const CreateAILPModal = ({ isOpen, onClose, action }: ModaTemplateProps) => { learning_outcome: analysedMaterial.learning_outcome, duration: analysedMaterial.estimated_duration, language: analysedMaterial.language, + type_of_file: 'md', model: 'Gemini', - }); - const readMaterialGen: AIMaterialGenerated = - response.data; + } as AIMaterialType); + + const readMaterialGen: AIMaterialGenerated = { + type_of_file: 'md', + content: response.data, + }; + const _id = UUIDv4(); + generatedNodes.push({ _id: _id, type: 'ReadMaterialNode', - title: readMaterialGen.title, - description: readMaterialGen.macro_subject, + title: analysedMaterial.title, + description: analysedMaterial.macro_subject, difficulty: 1, platform: 'WebApp', data: { - text: readMaterialGen.material, + text: readMaterialGen.content, link: '', }, reactFlow: { @@ -771,6 +781,12 @@ const CreateAILPModal = ({ isOpen, onClose, action }: ModaTemplateProps) => { data: {}, }, }); + + x += 450; + if (x > 1605) { + x = -195; + y += 195; + } } catch (error) { console.log('errror in generation readMaterial ' + error); } @@ -778,6 +794,9 @@ const CreateAILPModal = ({ isOpen, onClose, action }: ModaTemplateProps) => { counter--; const activity = nodesToGenerate[i]; if (!activity) break; + const topicExplanation = selectedTopic.find( + (topic) => topic.topic === activity.topic + )?.explanation; try { let response: AxiosResponse | null = null; const typeExercise = @@ -791,7 +810,7 @@ const CreateAILPModal = ({ isOpen, onClose, action }: ModaTemplateProps) => { response = await API.generateNewExercise({ macro_subject: activity?.learning_outcome, topic: activity.topic, - topic_explanation: activity.explanation, + topic_explanation: topicExplanation || '', education_level: analysedMaterial.education_level, learning_outcome: activity.learning_outcome, material: sourceMaterial, @@ -813,7 +832,7 @@ const CreateAILPModal = ({ isOpen, onClose, action }: ModaTemplateProps) => { response = await API.generateNewExercise({ macro_subject: activity?.learning_outcome, topic: activity.topic, - topic_explanation: activity.explanation, + topic_explanation: topicExplanation || '', education_level: analysedMaterial.education_level, learning_outcome: activity.learning_outcome, material: sourceMaterial, diff --git a/src/components/Properties/Edges/failDebtEdgeProperties.tsx b/src/components/Properties/Edges/failDebtEdgeProperties.tsx index fb5d8fa..2043b0c 100644 --- a/src/components/Properties/Edges/failDebtEdgeProperties.tsx +++ b/src/components/Properties/Edges/failDebtEdgeProperties.tsx @@ -78,7 +78,7 @@ const FailDebtEdgeProperties = () => { if (!generatingLoading) return; setGeneratingLoading(true); const response: AxiosResponse = await API.analyseMaterial({ - text: getValues('data.material'), + url: getValues('data.material'), }); //da gestire la response รจ cambiata aaaaaaaaaaaaaaaaaaaaaaaaa setValue('data.title', response.data.Title); diff --git a/src/components/Properties/Nodes/AbstractNodeProperties.tsx b/src/components/Properties/Nodes/AbstractNodeProperties.tsx index 7d09cfc..2da18dc 100644 --- a/src/components/Properties/Nodes/AbstractNodeProperties.tsx +++ b/src/components/Properties/Nodes/AbstractNodeProperties.tsx @@ -137,7 +137,7 @@ const AbstractNodeProperties = () => { return; } const response: AxiosResponse = await API.analyseMaterial({ - text: sourceMaterial, + url: sourceMaterial, }); setValue( 'data.learning_outcome', diff --git a/src/data/api.ts b/src/data/api.ts index 3044fc3..5d0dbc6 100644 --- a/src/data/api.ts +++ b/src/data/api.ts @@ -13,9 +13,8 @@ import { } from '../types/polyglotElements'; import { AIExerciseType, + AIMaterialType, AIPlanLesson, - AnalyseType, - MaterialType, SummerizerBody, } from '../types/polyglotElements/AIGenerativeTypes/AIGenerativeTypes'; import { ConceptMap } from '../types/polyglotElements/concept/Conceptmap'; @@ -334,18 +333,22 @@ export const API = { ); }, - analyseMaterial: (body: AnalyseType): Promise => { - return axios.post<{}, AxiosResponse, {}>( - `/api/openai/MaterialAnalyser`, - body - ); + analyseMaterial: (body: Record): Promise => { + const formData = new FormData(); + + Object.entries(body).forEach(([key, value]) => { + if (value !== undefined && value !== null) { + formData.append(key, value); + } + }); + + return axios.post(`/api/openai/MaterialAnalyser`, formData, { + headers: { 'Content-Type': 'multipart/form-data' }, + }); }, - generateMaterial: (body: MaterialType): Promise => { - return axios.post<{}, AxiosResponse, {}>( - `/api/openai/MaterialGenerator`, - body - ); + generateMaterial: (body: AIMaterialType): Promise => { + return axios.post(`/api/openai/MaterialGenerator`, body); }, summarize: (body: SummerizerBody): Promise => { diff --git a/src/types/polyglotElements/AIGenerativeTypes/AIGenerativeTypes.ts b/src/types/polyglotElements/AIGenerativeTypes/AIGenerativeTypes.ts index 5b18c63..7a63e87 100644 --- a/src/types/polyglotElements/AIGenerativeTypes/AIGenerativeTypes.ts +++ b/src/types/polyglotElements/AIGenerativeTypes/AIGenerativeTypes.ts @@ -157,7 +157,11 @@ export type LessonNodeAI = { topics: Topic[]; }; -export type AnalyseType = { text: string; model?: string }; +export type AnalyseType = { + file?: string; + url: string; + model?: string; +}; export type AnalyzedMaterial = { title: string; @@ -209,7 +213,7 @@ export type LOType = { Context: string; }; -export type MaterialType = { +export type AIMaterialType = { title: string; macro_subject: string; topics: LessonNodeAI[]; @@ -218,18 +222,10 @@ export type MaterialType = { duration: number; language: string; model: string; + type_of_file: string; }; -export type AIMaterialGenerated = { - title: string; - macro_subject: string; - topics: LessonNodeAI[]; - education_level: EducationLevel; - learning_outcome: LearningOutcome; - duration: number; - material: string; - language: string; -}; +export type AIMaterialGenerated = { type_of_file: string; content: any }; export type SummerizerBody = { text: string; @@ -253,7 +249,6 @@ export type AIPlanLesson = { export type PlanLessonNode = { type: string; topic: string; - explanation: string; details: string; learning_outcome: LearningOutcome; duration: number; @@ -269,4 +264,5 @@ export type AIPlanLessonResponse = { nodes: PlanLessonNode[]; context: string; language: string; + data?: any; };