Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/components/Card/PlanLessonCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 18 additions & 6 deletions src/components/Modals/AIToolModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { API } from '../../data/api';
import {
AIExerciseGenerated,
AIMaterialGenerated,
AIMaterialType,
EducationLevel,
LearningOutcome,
QuestionTypeMap,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
39 changes: 29 additions & 10 deletions src/components/Modals/CreateAILPModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
import {
AIExerciseGenerated,
AIMaterialGenerated,
AIMaterialType,
AIPlanLessonResponse,
AnalyzedMaterial,
EducationLevel,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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: {
Expand All @@ -771,13 +781,22 @@ 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);
}
} else {
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 =
Expand All @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/components/Properties/Edges/failDebtEdgeProperties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Properties/Nodes/AbstractNodeProperties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const AbstractNodeProperties = () => {
return;
}
const response: AxiosResponse = await API.analyseMaterial({
text: sourceMaterial,
url: sourceMaterial,
});
setValue(
'data.learning_outcome',
Expand Down
27 changes: 15 additions & 12 deletions src/data/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -334,18 +333,22 @@ export const API = {
);
},

analyseMaterial: (body: AnalyseType): Promise<AxiosResponse> => {
return axios.post<{}, AxiosResponse, {}>(
`/api/openai/MaterialAnalyser`,
body
);
analyseMaterial: (body: Record<string, any>): Promise<AxiosResponse> => {
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<AxiosResponse> => {
return axios.post<{}, AxiosResponse, {}>(
`/api/openai/MaterialGenerator`,
body
);
generateMaterial: (body: AIMaterialType): Promise<any> => {
return axios.post(`/api/openai/MaterialGenerator`, body);
},

summarize: (body: SummerizerBody): Promise<AxiosResponse> => {
Expand Down
22 changes: 9 additions & 13 deletions src/types/polyglotElements/AIGenerativeTypes/AIGenerativeTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -209,7 +213,7 @@ export type LOType = {
Context: string;
};

export type MaterialType = {
export type AIMaterialType = {
title: string;
macro_subject: string;
topics: LessonNodeAI[];
Expand All @@ -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;
Expand All @@ -253,7 +249,6 @@ export type AIPlanLesson = {
export type PlanLessonNode = {
type: string;
topic: string;
explanation: string;
details: string;
learning_outcome: LearningOutcome;
duration: number;
Expand All @@ -269,4 +264,5 @@ export type AIPlanLessonResponse = {
nodes: PlanLessonNode[];
context: string;
language: string;
data?: any;
};
Loading