Skip to content

Commit

Permalink
Merge pull request #43 from polyglot-edu/20-new-execution-api-concept
Browse files Browse the repository at this point in the history
20 new execution api concept
  • Loading branch information
tmaog authored May 19, 2024
2 parents efff597 + f8cd9c4 commit e83adcc
Show file tree
Hide file tree
Showing 66 changed files with 8,940 additions and 6,874 deletions.
11 changes: 11 additions & 0 deletions .prettierignore
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# polyglot-server
# polyglot-server
3,089 changes: 2,134 additions & 955 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"dependencies": {
"@azure/identity": "^3.2.2",
"@azure/openai": "^1.0.0-beta.2",
"axios": "^1.6.8",
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"errorhandler": "^1.5.1",
Expand Down
51 changes: 51 additions & 0 deletions src/api/api.ts
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,
);
},
};
78 changes: 40 additions & 38 deletions src/app.ts
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;
64 changes: 36 additions & 28 deletions src/controllers/concept.controllers.ts
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);
}
}
Loading

0 comments on commit e83adcc

Please sign in to comment.