diff --git a/client/src/components/AnswerResultModal.tsx b/client/src/components/AnswerResultModal.tsx
index e69de29..4bb7a2c 100644
--- a/client/src/components/AnswerResultModal.tsx
+++ b/client/src/components/AnswerResultModal.tsx
@@ -0,0 +1,25 @@
+import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
+
+interface AnswerResultModalProps {
+ isOpen: boolean;
+ onClose: () => void;
+ isCorrect: boolean;
+ drDanQuote: string;
+}
+
+const AnswerResultModal = ({ isOpen, onClose, isCorrect, drDanQuote }: AnswerResultModalProps) => {
+ return (
+
+ );
+};
+
+export default AnswerResultModal;
diff --git a/client/src/components/MinionModal.tsx b/client/src/components/MinionModal.tsx
index e69de29..b575d2c 100644
--- a/client/src/components/MinionModal.tsx
+++ b/client/src/components/MinionModal.tsx
@@ -0,0 +1,23 @@
+import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
+
+interface MinionModalProps {
+ isOpen: boolean;
+ onClose: () => void;
+ minionName: string;
+ minionQuote: string;
+}
+
+const MinionModal = ({ isOpen, onClose, minionName, minionQuote }: MinionModalProps) => {
+ return (
+
+ );
+};
+
+export default MinionModal;
diff --git a/client/src/graphql/queries.ts b/client/src/graphql/queries.ts
index 4b76e20..fec6426 100644
--- a/client/src/graphql/queries.ts
+++ b/client/src/graphql/queries.ts
@@ -1,13 +1,13 @@
import { gql } from '@apollo/client';
-export const GET_QUESTIONS = gql`
- query GetQuestions {
+export const GENERATE_QUESTIONS = gql`
+ query GenerateQuestion($track: String!, level: $level, minion: $minion) {
questions {
- _id
- questionText
- options
- correctAnswer
+ question
+ choices
+ answer
}
}
`;
+
diff --git a/server/src/schemas/resolvers.ts b/server/src/schemas/resolvers.ts
index 54998fa..70a165d 100644
--- a/server/src/schemas/resolvers.ts
+++ b/server/src/schemas/resolvers.ts
@@ -2,6 +2,13 @@ import User from '../models/User';
import Character from '../models/Characters';
import { signToken } from '../utils/auth';
import { AuthenticationError } from 'apollo-server-express';
+import { OpenAI } from 'openai';
+import { PromptBuilder } from '../utils/PromptBuilder';
+import dotenv from 'dotenv';
+
+dotenv.config();
+
+const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
interface AddUserArgs {
input: {
@@ -24,6 +31,35 @@ const resolvers = {
}
throw new AuthenticationError('You need to be logged in!');
},
+<<<<<<< HEAD
+ generateQuestion: async (_parent: any, args: { track: string; level: string; minion: string }) => {
+ const { track, level, minion } = args;
+ const prompt = PromptBuilder.getPrompt(track, level);
+
+ try {
+ const completion = await openai.chat.completions.create({
+ model: 'gpt-3.5-turbo',
+ messages: [{ role: 'user', content: prompt }],
+ max_tokens: 250,
+ });
+
+ const raw = completion.choices[0].message.content ?? '';
+ const [question, ...choicesAndAnswer] = raw.split('\n').filter(Boolean);
+ const choices = choicesAndAnswer.slice(0, -1);
+ const answer = choicesAndAnswer[choicesAndAnswer.length - 1];
+
+ return { question, choices, answer };
+ } catch (error) {
+ console.error('OpenAI failed, falling back to hardcoded question:', error);
+ const fallback = PromptBuilder.getFallbackQuestion(minion);
+
+ return {
+ question: fallback.question,
+ choices: fallback.choices,
+ answer: fallback.choices[fallback.correctIndex],
+ };
+ }
+=======
users: async () => {
return await User.find();
},
@@ -35,8 +71,10 @@ const resolvers = {
},
character: async (_: any, { id }: { id: string }) => {
return await Character.findById(id);
+>>>>>>> d7567a5c20d729e2d5c004a2d70be9176db8ea33
},
},
+
Mutation: {
addUser: async (_parent: any, { input }: AddUserArgs) => {
const user = await User.create(input);
diff --git a/server/src/schemas/typeDefs.ts b/server/src/schemas/typeDefs.ts
index a9b876e..be51e79 100644
--- a/server/src/schemas/typeDefs.ts
+++ b/server/src/schemas/typeDefs.ts
@@ -16,6 +16,8 @@ const typeDefs = gql`
password: String!
}
+<<<<<<< HEAD
+=======
type Character {
_id: ID!
name: String!
@@ -23,18 +25,29 @@ const typeDefs = gql`
voice: String!
}
+>>>>>>> d7567a5c20d729e2d5c004a2d70be9176db8ea33
type Auth {
token: ID!
user: User
}
+ type Question {
+ question: String!
+ choices: [String!]!
+ answer: String!
+ }
+
type Query {
users: [User]
user(username: String!): User
me: User
+<<<<<<< HEAD
+ generateQuestion(track: String!, level: String!, minion: String!): Question
+=======
updateStats(isCorrect: Boolean!): User
characters: [Character]
character(id: ID!): Character
+>>>>>>> d7567a5c20d729e2d5c004a2d70be9176db8ea33
}
type Mutation {
diff --git a/server/src/utils/PromptBuilder.ts b/server/src/utils/PromptBuilder.ts
index deaa247..14d919b 100644
--- a/server/src/utils/PromptBuilder.ts
+++ b/server/src/utils/PromptBuilder.ts
@@ -1,6 +1,10 @@
+<<<<<<< HEAD
+import { FallbackQuestion, fallbackQuestion } from "../utils/fallbackQuestions";
+=======
import { FallbackQuestion, fallbackQuestion } from "../utils/fallbackQuestions";
+>>>>>>> d7567a5c20d729e2d5c004a2d70be9176db8ea33
export class PromptBuilder {
/**