feat: add structured output and better prompt

This commit is contained in:
2025-07-28 16:24:41 +02:00
parent 62340f390a
commit c0ba3ea26d

27
App.tsx
View File

@ -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": <boolean>,\n "explanation": "<string>"\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"]
}
},
});