Flesh out payment stuff
This commit is contained in:
parent
b0dcdd6438
commit
acfed861ab
27 changed files with 938 additions and 173 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { GoogleGenAI, Type, createUserContent, createPartFromUri } from "@google/genai";
|
||||
import { Quiz, Question, AnswerOption, GenerateQuizOptions, ProcessedDocument, AIProvider } from "../types";
|
||||
import { buildQuizPrompt, JSON_EXAMPLE_GUIDANCE } from "../server/src/shared/quizPrompt";
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
const getGeminiClient = (apiKey?: string) => {
|
||||
|
|
@ -50,45 +51,17 @@ const QUIZ_SCHEMA = {
|
|||
|
||||
function buildPrompt(options: GenerateQuizOptions, hasDocuments: boolean, includeJsonExample: boolean = false): string {
|
||||
const questionCount = options.questionCount || 10;
|
||||
|
||||
let baseInstructions = `Create ${questionCount} engaging multiple-choice questions. Each question must have exactly 4 options, and exactly one correct answer. Vary the difficulty.
|
||||
|
||||
IMPORTANT: For each option's reason, write as if you are directly explaining facts - never reference "the document", "the text", "the material", or "the source". Write explanations as standalone factual statements.`;
|
||||
let prompt = buildQuizPrompt({
|
||||
topic: options.topic,
|
||||
questionCount,
|
||||
hasDocuments,
|
||||
});
|
||||
|
||||
if (includeJsonExample) {
|
||||
baseInstructions += `
|
||||
|
||||
You MUST respond with a single JSON object in this exact structure:
|
||||
{
|
||||
"title": "Quiz Title Here",
|
||||
"questions": [
|
||||
{
|
||||
"text": "Question text here?",
|
||||
"options": [
|
||||
{ "text": "Option A", "isCorrect": false, "reason": "Explanation why this is wrong" },
|
||||
{ "text": "Option B", "isCorrect": true, "reason": "Explanation why this is correct" },
|
||||
{ "text": "Option C", "isCorrect": false, "reason": "Explanation why this is wrong" },
|
||||
{ "text": "Option D", "isCorrect": false, "reason": "Explanation why this is wrong" }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Return ONLY valid JSON with no additional text before or after.`;
|
||||
prompt += `\n\n${JSON_EXAMPLE_GUIDANCE}`;
|
||||
}
|
||||
|
||||
if (hasDocuments) {
|
||||
const topicContext = options.topic
|
||||
? ` Focus on aspects related to "${options.topic}".`
|
||||
: '';
|
||||
return `Generate a quiz based on the provided content.${topicContext}
|
||||
|
||||
${baseInstructions}`;
|
||||
}
|
||||
|
||||
return `Generate a trivia quiz about "${options.topic}".
|
||||
|
||||
${baseInstructions}`;
|
||||
return prompt;
|
||||
}
|
||||
|
||||
function shuffleArray<T>(array: T[]): T[] {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue