From c0ba3ea26d0f1530458066e5f850ae86d4d2b1e9 Mon Sep 17 00:00:00 2001 From: Yandrik Date: Mon, 28 Jul 2025 16:24:41 +0200 Subject: [PATCH] feat: add structured output and better prompt --- App.tsx | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/App.tsx b/App.tsx index 1370d16..de73c3c 100644 --- a/App.tsx +++ b/App.tsx @@ -82,7 +82,18 @@ const evaluateWithGemini = async ( solution: string, prompt: string ): Promise<{ correct: boolean, explanation: string }> => { - const systemInstruction = `You are an expert Software Architecture (SWA) tutor. Your task is to evaluate a user's answer against a model solution for a specific exercise. The user's answer might be phrased differently but contain the correct key concepts. Focus on semantic correctness, not just literal string matching. For Mermaid diagrams, check if the user's diagram correctly represents the required structures and relationships.\n\nThe exercise is: "${prompt}"\n\nAnalyze the user's answer and compare it to the provided model solution.\n\nRespond ONLY with a single JSON object in the format:\n{\n "correct": ,\n "explanation": ""\n}\n\n- "correct": true if the user's answer is a valid and correct solution, false otherwise.\n- "explanation": If correct, provide a brief confirmation and elaborate on why the answer is good. If incorrect, provide a clear, concise explanation of what is wrong or missing. Use markdown for formatting. **Your entire explanation must be in German.**`; + const systemInstruction = `You are an expert Software Architecture (SWA) tutor. Your task is to evaluate a user's answer against a model solution for a specific exercise. The user's answer might be phrased differently but contain the correct key concepts. Focus on semantic correctness, not just literal string matching. For Mermaid diagrams, check if the user's diagram correctly represents the required structures and relationships. + +The exercise is: "${prompt}" + +Analyze the user's answer and compare it to the provided model solution. + +Determine if the user's answer is correct and provide an explanation: +- If correct, provide a brief confirmation and elaborate on why the answer is good. +- If incorrect, provide a clear, concise explanation of what is wrong or missing. +- Use markdown for formatting. +- Your entire explanation must be in German. +- Start your explanation with phrases like: "Ihre Antwort ist...", "Ihre Definition ist...", "Fast richtig! Ihre...", "Perfekt, alles richtig! Ihre Antwort..."`; const contents = `Here is the user's answer: \`\`\` @@ -102,6 +113,20 @@ Please evaluate the user's answer and provide your response in the specified JSO config: { systemInstruction: systemInstruction, responseMimeType: "application/json", + responseSchema: { + type: "object", + properties: { + correct: { + type: "boolean", + description: "Whether the user's answer is correct" + }, + explanation: { + type: "string", + description: "Explanation of the evaluation in German" + } + }, + required: ["correct", "explanation"] + } }, });