Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question Component Page updated #77

Merged
merged 25 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6ab33e4
add new timer component input logic
aasmal97 Nov 7, 2023
79a0460
fixed millisecond parser, and added auto play feature to time controls
aasmal97 Nov 8, 2023
b667267
finalized timer/stopwatch logic to auto play timer and routed it with…
aasmal97 Nov 8, 2023
59dcb0d
commented out add quiz button, until a future date
aasmal97 Nov 8, 2023
dec3267
styled and made timer form responsive
aasmal97 Nov 8, 2023
e17b83f
added time change handler, so that intial time can be saved every tim…
aasmal97 Nov 8, 2023
49d1323
added ability to trash timer and get local storage data for question …
aasmal97 Nov 9, 2023
fef484e
added initial time finished modal
aasmal97 Nov 9, 2023
d810273
converted use time hook, to context provider and adjusted passing of …
aasmal97 Nov 9, 2023
268ab69
fixed side effect error where we updated a component from inside the …
aasmal97 Nov 9, 2023
0c2c755
finalized timer modal
aasmal97 Nov 9, 2023
20bea7b
added responsive styling to time modal
aasmal97 Nov 9, 2023
35c531e
finished question component page, full screen logic
aasmal97 Nov 9, 2023
16e25df
added share btn logic. Meta tags are still needed
aasmal97 Nov 10, 2023
4a3ea8b
add favicons and added question metadata on page. Finish Share Btn
aasmal97 Nov 10, 2023
dd572ae
modifed use dropdown to store element so that share btn can have an e…
aasmal97 Nov 10, 2023
51082a7
added dropdown btn label to describe question buttons/icon buttons
aasmal97 Nov 10, 2023
8ac9a99
changed dropdown btn logic, to use pointer events handler instead of …
aasmal97 Nov 10, 2023
cd08d0f
updated prisma types for answer option, and modified gql queries to a…
aasmal97 Nov 10, 2023
d49bdef
Merge branch 'development' of https://github.com/chingu-voyages/v46-t…
aasmal97 Nov 10, 2023
f8965e0
Merge branch 'development' of https://github.com/chingu-voyages/v46-t…
aasmal97 Nov 10, 2023
f66b0f1
restructured question id files into seperate directories for maintain…
aasmal97 Nov 10, 2023
2a9a8ee
fixed metadata title return undefined instead of default question tit…
aasmal97 Nov 10, 2023
47deb09
Modified generate question api route, and part of control route
aasmal97 Nov 10, 2023
e3bfba0
adjust question title from prompt moving to new line
aasmal97 Nov 10, 2023
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
61 changes: 31 additions & 30 deletions studyAi/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ type AggregateVerificationToken {
}

type AnswerData {
correctAnswer: [String!]!
correctAnswer: [AnswerOption!]!
}

input AnswerDataCompositeFilter {
Expand All @@ -519,19 +519,15 @@ input AnswerDataCreateEnvelopeInput {
}

input AnswerDataCreateInput {
correctAnswer: AnswerDataCreatecorrectAnswerInput
}

input AnswerDataCreatecorrectAnswerInput {
set: [String!]!
correctAnswer: [AnswerOptionCreateInput!]
}

input AnswerDataObjectEqualityInput {
correctAnswer: [String!]
correctAnswer: [AnswerOptionObjectEqualityInput!]
}

input AnswerDataOrderByInput {
correctAnswer: SortOrder
correctAnswer: AnswerOptionOrderByCompositeAggregateInput
}

input AnswerDataUpdateEnvelopeInput {
Expand All @@ -540,19 +536,33 @@ input AnswerDataUpdateEnvelopeInput {
}

input AnswerDataUpdateInput {
correctAnswer: AnswerDataUpdatecorrectAnswerInput
}

input AnswerDataUpdatecorrectAnswerInput {
push: [String!]
set: [String!]
correctAnswer: [AnswerOptionCreateInput!]
}

input AnswerDataWhereInput {
AND: [AnswerDataWhereInput!]
NOT: [AnswerDataWhereInput!]
OR: [AnswerDataWhereInput!]
correctAnswer: StringNullableListFilter
correctAnswer: [AnswerOptionObjectEqualityInput!]
}

type AnswerOption {
id: String!
value: String!
}

input AnswerOptionCreateInput {
id: String!
value: String!
}

input AnswerOptionObjectEqualityInput {
id: String!
value: String!
}

input AnswerOptionOrderByCompositeAggregateInput {
_count: SortOrder
}

input BoolFieldUpdateOperationsInput {
Expand Down Expand Up @@ -1282,7 +1292,7 @@ type QuestionGroupBy {

type QuestionInfoData {
description: String!
options: [String!]!
options: [AnswerOption!]!
title: String!
}

Expand All @@ -1298,23 +1308,19 @@ input QuestionInfoDataCreateEnvelopeInput {

input QuestionInfoDataCreateInput {
description: String!
options: QuestionInfoDataCreateoptionsInput
options: [AnswerOptionCreateInput!]
title: String!
}

input QuestionInfoDataCreateoptionsInput {
set: [String!]!
}

input QuestionInfoDataObjectEqualityInput {
description: String!
options: [String!]
options: [AnswerOptionObjectEqualityInput!]
title: String!
}

input QuestionInfoDataOrderByInput {
description: SortOrder
options: SortOrder
options: AnswerOptionOrderByCompositeAggregateInput
title: SortOrder
}

Expand All @@ -1325,21 +1331,16 @@ input QuestionInfoDataUpdateEnvelopeInput {

input QuestionInfoDataUpdateInput {
description: StringFieldUpdateOperationsInput
options: QuestionInfoDataUpdateoptionsInput
options: [AnswerOptionCreateInput!]
title: StringFieldUpdateOperationsInput
}

input QuestionInfoDataUpdateoptionsInput {
push: [String!]
set: [String!]
}

input QuestionInfoDataWhereInput {
AND: [QuestionInfoDataWhereInput!]
NOT: [QuestionInfoDataWhereInput!]
OR: [QuestionInfoDataWhereInput!]
description: StringFilter
options: StringNullableListFilter
options: [AnswerOptionObjectEqualityInput!]
title: StringFilter
}

Expand Down
1 change: 1 addition & 0 deletions studyAi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"nexus": "^1.3.0",
"openai": "^3.3.0",
"react": "18",
"react-device-detect": "^2.2.3",
"react-dom": "18",
"react-select": "^5.7.7",
"react-sweet-state": "^2.7.1",
Expand Down
9 changes: 6 additions & 3 deletions studyAi/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}

type AnswerOption {
id String @db.ObjectId
value String
}
type LocationData {
locationType String
//latitude and longitude
Expand All @@ -32,7 +35,7 @@ type QuestionInfoData {
title String
description String
//for mc and select multiple. short answer will contain empty arr
options String[]
options AnswerOption[]
}

type UserQuestionData {
Expand All @@ -41,7 +44,7 @@ type UserQuestionData {
}

type AnswerData {
correctAnswer String[]
correctAnswer AnswerOption[]
}

type LikeCounter {
Expand Down
Binary file added studyAi/public/logo/android-chrome-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added studyAi/public/logo/android-chrome-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added studyAi/public/logo/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added studyAi/public/logo/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added studyAi/public/logo/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added studyAi/public/logo/favicon.ico
Binary file not shown.
Binary file added studyAi/public/logo/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions studyAi/public/site.webmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "Study AI",
"short_name": "Study AI",
"icons": [
{
"src": "/logo/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/logo/android-chrome-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"theme_color": "#ffffff",
"background_color": "#ffffff",
"display": "standalone"
}
130 changes: 119 additions & 11 deletions studyAi/src/app/api/generateQuestion/generateQuestion.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,136 @@
import generatePrompts from "../../util/openAI/openAI";
import { NextResponse } from "next/server";
import * as z from "zod";

//schema for validating user inputs
const questionSchema = z.object({
type: z.string(),
tags: z.array(z.string()),
title: z.array(z.string()),
question: z.string(),
numberOfOptions: z.number()
answers: z.array(
z.object({
value: z.string(),
id: z.string(),
})
),
numberOfOptions: z.number(),
});

type QuesitonSchema = z.infer<typeof questionSchema>;
const determinePromptTemplateStr = (questionType: string) => {
let str: string;
switch (questionType) {
case "Multiple Choice":
str = `
{
description: 'QuestionDescription'
title: 'QuestionTitle'
options: 'QuestionOptions'
answer: 'CorrectAnswers'
}
`;
return str;
case "Short Answer":
str = `
{
description: 'QuestionDescription'
title: 'QuestionTitle'
answer: 'CorrectAnswers'
}
`;
return str;
case "Select Multiple":
str = `
{
description: 'QuestionDescription'
title: 'QuestionTitle'
options: 'QuestionOptions'
answer: 'CorrectAnswers'
}
`;
return str;
default:
str = `
{
description: 'QuestionDescription'
title: 'QuestionTitle'
answer: 'CorrectAnswers'
}
`;
return str;
}
};
const determineVariableTypeTemplateStr = (
questionType: string,
numberOfOptions: number
) => {
let str: string;
switch (questionType) {
case "Multiple Choice":
str = `the new options as a list of strings with length ${numberOfOptions} called 'QuestionOptions', and the new correct answer inside a list of strings, with length 1, called 'CorrectAnswers'.`;
break;
case "Short Answer":
str = `the new correct answer inside a list of strings with length 1, called 'CorrectAnswers'`;
break;
case "Select Multiple":
str = `the new options as a list of strings with length ${numberOfOptions} called 'QuestionOptions', and the new correct answer/answers as a list of strings called 'CorrectAnswers'`;
break;
default:
str = `the new correct answer inside a list of strings with length 1, called 'CorrectAnswers'`;
break;
}
return str;
};
export async function generateQuestion(req: Request) {
try {
const bodyPromise = req.json();
const body = await bodyPromise;
const { type, tags, question, numberOfOptions } = questionSchema.parse(body);
const questionType = (type === "mcq") ? `multiple choice with ${numberOfOptions} different potential answers` : ("checkbox") ? `with ${numberOfOptions} different potential answers some correct and some incorrect` : "short answer";
let parsedBody: QuesitonSchema;
try {
parsedBody = questionSchema.parse(body);
} catch (err) {
return NextResponse.json({
status: 400,
message: "Invalid input",
error: err,
});
}
const { type, tags, title, question, numberOfOptions, answers } =
parsedBody;
const questionType =
type === "Multiple Choice"
? `A Multiple choice question, with ${numberOfOptions} unique options, but only one correct answer`
: "Select Multiple"
? `A Select Multiple/Select All question, with ${numberOfOptions} unique options, where each option can be a correct answer OR incorrect answer. However, there MUST be at least ONE correct answer`
: "Short Answer question";

const prompt = `Give me a completely NEW question where the question type is: ${questionType}.
It should also be similar to the following question:
questionTitle: ${title}, description: ${question}, answer: ${answers
.map((a) => a.value)
.join(", ")}.

Also, try to ensure that the question is related to the following subjects: ${tags.join(
", "
)}

const prompt = `Ask me a question, ${questionType}, similar to this question: ${question} and from the following subjects: ${tags}. Indicate which is the correct response, and Return your response in a JSON object, with the following format: {"question": "", "correct": ["",...], "incorrect": ["",...]}`;
const model = "gpt-3.5-turbo";
const questionGenerated = await generatePrompts(model, prompt) || "";
const newQuestion = JSON.parse(questionGenerated);
newQuestion.options = [...newQuestion.correct, ...newQuestion.incorrect];
Then, store the new question description as a string called 'QuestionDescription', the new question title as a string 'QuestionTitle', ${determineVariableTypeTemplateStr(type, numberOfOptions)}

Finally, return the new generated question data as a JSON object, in the following format:
${determinePromptTemplateStr(type)}`;
// Indicate which is the correct response, and Return your response in a JSON object,
// with the following format: {"question": "", "correct": ["",...], "incorrect": ["",...]};
const model = "gpt-3.5-turbo";
const questionGenerated = (await generatePrompts(model, prompt)) || "";
let newQuestion = null;
try {
newQuestion = JSON.parse(questionGenerated);
} catch (err) {
return NextResponse.json({
status: 500,
message: `Failed to parse the following response ${questionGenerated}`,
error: err,
});
}
return NextResponse.json({
newQuestion,
message: `Question Generated Successfully`,
Expand All @@ -34,4 +142,4 @@ export async function generateQuestion(req: Request) {
message: "Something went wrong",
});
}
}
}
35 changes: 0 additions & 35 deletions studyAi/src/app/dashboard/blah.tsx

This file was deleted.

Binary file removed studyAi/src/app/favicon.ico
Binary file not shown.
Loading