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
397 changes: 225 additions & 172 deletions src/components/Modals/AIToolModal.tsx

Large diffs are not rendered by default.

98 changes: 90 additions & 8 deletions src/components/Modals/SummarizerModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ import {
ModalContent,
ModalHeader,
ModalOverlay,
Select,
Text,
Textarea,
useToast,
} from '@chakra-ui/react';
import { AxiosResponse } from 'axios';
import { useState } from 'react';
import { API } from '../../data/api';
import {
EducationLevel,
LearningOutcome,
SummarizeStyle,
} from '../../types/polyglotElements';

export type ModaTemplateProps = {
isOpen: boolean;
Expand All @@ -26,10 +32,28 @@ const SummarizerModal = ({ isOpen, onClose }: ModaTemplateProps) => {
const [generatingLoading, setGeneratingLoading] = useState(false);
const [sourceMaterial, setSourceMaterial] = useState('');
const [generatedMaterial, setGeneratedMaterial] = useState('');
const [learningOutcome, setLearningOutcome] = useState<LearningOutcome>(
LearningOutcome.ApplyKnowledge
);
const [summarizeStyle, setSummarizeStyle] = useState<SummarizeStyle>(
SummarizeStyle.Abstractive
);
const [eduLevel, setEduLevel] = useState<EducationLevel>(
EducationLevel.College
);
const [noW, setNoW] = useState('');
const toast = useToast();
return (
<Modal isOpen={isOpen} onClose={onClose} size={'2xl'} isCentered>
<Modal
isOpen={isOpen}
onClose={() => {
setSourceMaterial('');
setGeneratingLoading(false);
onClose();
}}
size={'2xl'}
isCentered
>
<ModalOverlay />
<ModalContent>
<ModalHeader>Do you need help to summarize your material?</ModalHeader>
Expand All @@ -41,6 +65,7 @@ const SummarizerModal = ({ isOpen, onClose }: ModaTemplateProps) => {
marginTop={'5px'}
onClick={async () => {
try {
console.log('testing');
if (generateButton) {
toast({
title: 'Invalid syntax',
Expand All @@ -54,19 +79,21 @@ const SummarizerModal = ({ isOpen, onClose }: ModaTemplateProps) => {
return;
}
setGeneratingLoading(true);
const level = 1;
if (!sourceMaterial) {
setGeneratedMaterial('No text given');
//
throw ': no text given';
}
if (!noW) setNoW('200');
if (!summarizeStyle || !eduLevel || !learningOutcome) return;
const response: AxiosResponse = await API.summarize({
material: sourceMaterial,
level: level,
numberOfWords: Number(noW),
text: sourceMaterial,
model: 'Gemini',
style: summarizeStyle,
education_level: eduLevel,
learning_outcome: learningOutcome,
});
setGeneratedMaterial(response.data);
setGeneratedMaterial(response.data.summary);
setGeneratingLoading(false);
} catch (error: any) {
setGeneratingLoading(false);
Expand Down Expand Up @@ -121,7 +148,62 @@ const SummarizerModal = ({ isOpen, onClose }: ModaTemplateProps) => {
}}
/>
</FormLabel>

<FormLabel mb={2} fontWeight={'bold'}>
Summarize style:
</FormLabel>
<Select
paddingBottom={'5px'}
borderColor="grey"
onChange={(event) =>
setSummarizeStyle(event.currentTarget.value as SummarizeStyle)
}
>
{Object.values(SummarizeStyle).map((style) => (
<option
key={style}
value={style}
selected={summarizeStyle === style}
>
{style}
</option>
))}
</Select>
<FormLabel mb={2} fontWeight={'bold'}>
Educational Level:
</FormLabel>
<Select
paddingBottom={'5px'}
borderColor={'grey'}
onChange={(event) =>
setEduLevel(event.currentTarget.value as EducationLevel)
}
>
{Object.values(EducationLevel).map((level) => (
<option key={level} value={level} selected={eduLevel === level}>
{level}
</option>
))}
</Select>
<FormLabel mb={2} fontWeight={'bold'}>
Learning outcome:
</FormLabel>
<Select
paddingBottom={'5px'}
borderColor="grey"
onChange={(event) =>
setLearningOutcome(event.currentTarget.value as LearningOutcome)
}
>
{Object.values(LearningOutcome).map((outcome) => (
<option
key={outcome}
value={outcome}
selected={learningOutcome === outcome}
>
{outcome}
</option>
))}
</Select>
<FormLabel mb={2} fontWeight={'bold'}>
Your material:
</FormLabel>
Expand All @@ -135,7 +217,7 @@ const SummarizerModal = ({ isOpen, onClose }: ModaTemplateProps) => {
setSourceMaterial(e.currentTarget.value);
}}
/>
<FormLabel mb={2} fontWeight={'bold'}>
<FormLabel mb={2} fontWeight={'bold'} paddingTop={'5px'}>
Generated Material:
</FormLabel>
<Textarea
Expand Down
12 changes: 7 additions & 5 deletions src/components/Properties/Edges/failDebtEdgeProperties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import { AxiosResponse } from 'axios';
import { useState } from 'react';
import { useFormContext } from 'react-hook-form';
import { API } from '../../../data/api';
import { TypeOfExercise } from '../../../types/polyglotElements/AIGenerativeTypes/AIGenerativeTypes';
import { QuestionType } from '../../../types/polyglotElements/AIGenerativeTypes/AIGenerativeTypes';
import EnumField from '../../Forms/Fields/EnumField';
import TextField from '../../Forms/Fields/TextField';
import EdgeProperties from './EdgeProperties';

type Topic = {
Topic: string;
Type: TypeOfExercise;
Type: QuestionType;
Description: string;
};

Expand Down Expand Up @@ -76,10 +76,12 @@ const FailDebtEdgeProperties = () => {
marginTop={'5px'}
onClick={async () => {
try {
if (!generatingLoading) return;
setGeneratingLoading(true);
const response: AxiosResponse = await API.analyseMaterial({
material: getValues('data.material'),
text: getValues('data.material'),
});
//da gestire la response è cambiata aaaaaaaaaaaaaaaaaaaaaaaaa
setValue('data.title', response.data.Title);
setValue('data.language', response.data.Language);
setValue('data.macroSubject', response.data.MacroSubject);
Expand Down Expand Up @@ -143,7 +145,7 @@ const FailDebtEdgeProperties = () => {
setGeneratingLoading(true);
const level: number = getValues('data.level');
console.log(level);
const response: AxiosResponse = await API.generateLO({
/*const response: AxiosResponse = await API.generateLO({
Topic: topicGen[topicIndex].Topic,
Level: Number(level),
Context: '',
Expand All @@ -159,7 +161,7 @@ const FailDebtEdgeProperties = () => {
response.data.Analyzing[1],
response.data.Evaluating[0],
response.data.Evaluating[1],
]);
]);*/
console.log('step2');
setGeneratingLoading(false);
} catch (error) {
Expand Down
12 changes: 2 additions & 10 deletions src/data/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import {
import {
AIExerciseType,
AnalyseType,
LOType,
MaterialType,
SummarizeType,
SummerizerBody,
} from '../types/polyglotElements/AIGenerativeTypes/AIGenerativeTypes';
import { ConceptMap } from '../types/polyglotElements/concept/Conceptmap';
import {
Expand Down Expand Up @@ -403,21 +402,14 @@ export const API = {
);
},

generateLO: (body: LOType): Promise<AxiosResponse> => {
return axios.post<{}, AxiosResponse, {}>(
`/api/openai/LearningObjectiveGenerator`,
body
);
},

generateMaterial: (body: MaterialType): Promise<AxiosResponse> => {
return axios.post<{}, AxiosResponse, {}>(
`/api/openai/MaterialGenerator`,
body
);
},

summarize: (body: SummarizeType): Promise<AxiosResponse> => {
summarize: (body: SummerizerBody): Promise<AxiosResponse> => {
return axios.post<{}, AxiosResponse, {}>(`/api/openai/Summarizer`, body);
},

Expand Down
142 changes: 111 additions & 31 deletions src/types/polyglotElements/AIGenerativeTypes/AIGenerativeTypes.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,127 @@
export enum TypeOfExercise {
fill_in_the_blanks,
question,
choice,
conceptual,
practical,
export enum EducationLevel {
ElementarySchool = 'elementary school',
MiddleSchool = 'middle school',
HighSchool = 'high school',
College = 'college',
Graduate = 'graduate',
Professional = 'professional',
}

export type AnalyseType = { material: string };
export enum LearningOutcome {
RecallRecognize = 'the ability to recall or recognize simple facts and definitions',
ExplainRelate = 'the ability to explain concepts and principles, and recognize how different ideas are related',
ApplyKnowledge = 'the ability to apply knowledge and perform operations in practical contexts',
SelfAssess = 'the ability to assess your own understanding, identify gaps in knowledge, and strategize ways to close those gaps',
SynthesizeOrganize = 'the ability to synthesize and organize concepts into a framework that allows for advanced problem-solving and prediction',
GenerateContribute = 'the ability to generate new knowledge, challenge existing paradigms, and make significant contributions to the field',
}

export type LOType = {
Topic: string;
Level: number;
Context: string;
export enum QuestionType {
OpenQuestion = 'open question',
ShortAnswerQuestion = 'short answer question',
TrueOrFalse = 'true or false',
FillInTheBlanks = 'fill in the blanks',
Matching = 'matching',
Ordering = 'ordering',
MultipleChoice = 'multiple choice',
MultipleSelect = 'multiple select',
Coding = 'coding',
Essay = 'essay',
KnowledgeExposition = 'knowledge exposition',
Debate = 'debate',
Brainstorming = 'brainstorming',
GroupDiscussion = 'group discussion',
Simulation = 'simulation',
InquiryBasedLearning = 'inquiry based learning',
NonWrittenMaterialAnalysis = 'non written material analysis',
NonWrittenMaterialProduction = 'non written material production',
CaseStudyAnalysis = 'case study analysis',
ProjectBasedLearning = 'project based learning',
ProblemSolvingActivity = 'problem solving activity',
}

export enum SummarizeStyle {
TopicSynthetic = 'topic / synthetic',
StandardDescriptive = 'standard descriptive',
Abstractive = 'abstractive',
Extractive = 'extractive',
ExplanatoryEvaluative = 'explanatory and evaluative',
Informal = 'informal',
StructuredInformative = 'structured and informative',
}

export type Topic = { topic: string; explanation: string };

export type LessonNodeAI = {
title: string;
learning_outcome: LearningOutcome;
topics: Topic[];
};

export type MaterialType = {
export type AnalyseType = { text: string; model?: string };

export type AIExerciseType = {
macro_subject: string;
topic: string;
numberOfWords: number;
level: number;
learningObjective: string;
education_level: EducationLevel;
learning_outcome: LearningOutcome;
material: string;
solutions_number: number;
distractors_number: number;
easily_discardable_distractors_number: number;
type: QuestionType;
language: string;
model: string;
};

export type SummarizeType = {
export type AIExerciseGenerated = {
macro_subject: string;
topic: string;
education_level: EducationLevel;
learning_outcome: LearningOutcome;
material: string;
numberOfWords: number;
level: number;
assignment: string;
plus: string;
solutions: string[];
distractors: string[];
easily_discardable_distractors: string[];
type: QuestionType;
language: string;
};

export type AIExerciseType = {
macroSubject: string;
export type LOType = {
//outdate
Topic: string;
Level: number;
Context: string;
};

export type MaterialType = {
title: string;
level: number; //0=primary_school, 1=middle_school, 2=high_school, 3=college, 4=academy
typeOfActivity: TypeOfExercise; //0=fill_in_the_blanks, 1=question, 2=choice, 3=conceptual, 4=practical
learningObjective?: string;
bloomLevel: number; //0=Remembering, 1=Understanding, 2=Applying, 3=Analyzing, 4=Evaluating, 5=Creating
macro_subject: string;
topics: LessonNodeAI[];
education_level: EducationLevel;
learning_outcome: LearningOutcome;
duration: number;
language: string;
model: string;
};

export type AIMaterialGenerated = {
title: string;
macro_subject: string;
topics: LessonNodeAI[];
education_level: EducationLevel;
learning_outcome: LearningOutcome;
duration: number;
material: string;
correctAnswersNumber?: number;
distractorsNumber?: number;
easilyDiscardableDistractorsNumber?: number;
assignmentType: number; //0=theoretical, 1=code, 2=problem_resolution,
topic: string;
temperature: number;
language: string;
};

export type SummarizerBody = { lesson: string; noW: string; level: string };
export type SummerizerBody = {
text: string;
model: string;
style: SummarizeStyle;
education_level: EducationLevel;
learning_outcome: LearningOutcome;
};
Loading
Loading