-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from polyglot-edu/20-new-execution-api-concept
20 new execution api concept
- Loading branch information
Showing
66 changed files
with
8,940 additions
and
6,874 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
dist | ||
node_modules | ||
charts | ||
.github | ||
Dockerfile | ||
.drone.yml | ||
docker-compose.yml | ||
tsconfig.json | ||
jest.config.js | ||
package-lock.json | ||
package.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
# polyglot-server | ||
# polyglot-server |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import axiosCreate, { AxiosError, AxiosInstance, AxiosResponse } from "axios"; | ||
|
||
export type aiAPIResponse = { | ||
Date: string; | ||
Question: string; | ||
CorrectAnswer: string; | ||
}; | ||
|
||
enum TypeOfExercise { | ||
fill_in_the_blanks, | ||
question, | ||
choice, | ||
conceptual, | ||
practical, | ||
} | ||
|
||
type AIExerciseType = { | ||
macroSubject: string; | ||
title: string; | ||
level: number; //0=primary_school, 1=middle_school, 2=high_school, 3=college, 4=academy | ||
typeOfExercise: 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 | ||
language: string; | ||
material: string; | ||
correctAnswersNumber: number; | ||
distractorsNumber: number; | ||
easilyDiscardableDistractorsNumber: number; | ||
assignmentType: number; //0=theoretical, 1=code, 2=problem_resolution, | ||
topic: string; | ||
temperature: number; | ||
}; | ||
|
||
const AIAPIGeneration = axiosCreate.create({ | ||
baseURL: "https://skapi.polyglot-edu.com", | ||
headers: { | ||
"Content-Type": "application/json", | ||
ApiKey: process.env.APIKEY, | ||
SetupModel: | ||
'{"secretKey": "72ad445a32ad4b899c9a90cb496aae20","modelName": "gpt35Turbo","endpoint": "https://ai4edu.openai.azure.com/"}', | ||
}, | ||
}); | ||
|
||
export const API = { | ||
generateNewExercise: (body: AIExerciseType): Promise<AxiosResponse> => { | ||
return AIAPIGeneration.post<{}, AxiosResponse, {}>( | ||
`/Exercises/GenerateExercise`, | ||
body, | ||
); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,40 @@ | ||
import express from 'express'; | ||
import bodyParser from "body-parser"; | ||
import { loggerMiddleware } from "./middlewares/logger.middleware"; | ||
import router from "./routes"; | ||
import cors from "cors"; | ||
import { ENV } from "./utils/secrets"; | ||
|
||
/* | ||
STRUCTURE | ||
│ app.js # App entry point | ||
└───routes # Our routes controllers for all the endpoints of the app | ||
└───config # Environment variables and configuration related stuff | ||
└───controllers # Functions for our APIs | ||
└───models # Database models | ||
└───middlewares # Contains all the middleware that we need | ||
└───utils # Common functions that would be used repetitively | ||
*/ | ||
|
||
const app = express(); | ||
|
||
if (ENV === 'production') { | ||
app.set('trust proxy', 1) // trust first proxy | ||
} | ||
|
||
app.use(cors({ | ||
origin: (origin, callback) => { | ||
// automatically set cors origin header based on client request for faster developing | ||
// TODO: check domain cors in production env | ||
return callback(null, true); | ||
}, | ||
})); | ||
|
||
app.use(bodyParser.json({limit: "1mb"})); | ||
app.use(loggerMiddleware); | ||
|
||
app.use(router); | ||
|
||
export default app; | ||
import express from "express"; | ||
import bodyParser from "body-parser"; | ||
import { loggerMiddleware } from "./middlewares/logger.middleware"; | ||
import router from "./routes"; | ||
import cors from "cors"; | ||
import { ENV } from "./utils/secrets"; | ||
|
||
/* | ||
STRUCTURE | ||
│ app.js # App entry point | ||
└───routes # Our routes controllers for all the endpoints of the app | ||
└───config # Environment variables and configuration related stuff | ||
└───controllers # Functions for our APIs | ||
└───models # Database models | ||
└───middlewares # Contains all the middleware that we need | ||
└───utils # Common functions that would be used repetitively | ||
*/ | ||
|
||
const app = express(); | ||
|
||
if (ENV === "production") { | ||
app.set("trust proxy", 1); // trust first proxy | ||
} | ||
|
||
app.use( | ||
cors({ | ||
origin: (origin, callback) => { | ||
// automatically set cors origin header based on client request for faster developing | ||
// TODO: check domain cors in production env | ||
return callback(null, true); | ||
}, | ||
}), | ||
); | ||
|
||
app.use(bodyParser.json({ limit: "1mb" })); | ||
app.use(loggerMiddleware); | ||
|
||
app.use(router); | ||
|
||
export default app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,36 @@ | ||
import { NextFunction, Request, Response } from "express"; | ||
import { PolyglotConceptMap } from "../types/PolyglotConcept"; | ||
import { PolyglotConceptMapModel } from "../models/concept.models"; | ||
|
||
type CreateConceptMapBody = PolyglotConceptMap | ||
export async function createConceptMap(req: Request<{}, any, CreateConceptMapBody>, res: Response, next: NextFunction) { | ||
const conceptMap = req.body; | ||
|
||
try { | ||
const polyglotConceptMap = await PolyglotConceptMapModel.create(conceptMap); | ||
|
||
return res.status(200).json(polyglotConceptMap); | ||
} catch (err) { | ||
next(err); | ||
} | ||
} | ||
|
||
export async function findConceptMapById(req: Request, res: Response, next: NextFunction) { | ||
const conceptMapId = req.params.id; | ||
|
||
try { | ||
const conceptMap = await PolyglotConceptMapModel.findById(conceptMapId); | ||
|
||
return res.status(200).json(conceptMap); | ||
} catch (err) { | ||
next(err); | ||
} | ||
} | ||
import { NextFunction, Request, Response } from "express"; | ||
import { PolyglotConceptMap } from "../types/PolyglotConcept"; | ||
import { PolyglotConceptMapModel } from "../models/concept.models"; | ||
|
||
type CreateConceptMapBody = PolyglotConceptMap; | ||
export async function createConceptMap( | ||
req: Request<{}, any, CreateConceptMapBody>, | ||
res: Response, | ||
next: NextFunction, | ||
) { | ||
const conceptMap = req.body; | ||
|
||
try { | ||
const polyglotConceptMap = await PolyglotConceptMapModel.create(conceptMap); | ||
|
||
return res.status(200).json(polyglotConceptMap); | ||
} catch (err) { | ||
next(err); | ||
} | ||
} | ||
|
||
export async function findConceptMapById( | ||
req: Request, | ||
res: Response, | ||
next: NextFunction, | ||
) { | ||
const conceptMapId = req.params.id; | ||
|
||
try { | ||
const conceptMap = await PolyglotConceptMapModel.findById(conceptMapId); | ||
|
||
return res.status(200).json(conceptMap); | ||
} catch (err) { | ||
next(err); | ||
} | ||
} |
Oops, something went wrong.