Spaces:
Sleeping
Sleeping
| 'use server'; | |
| /** | |
| * @fileOverview Provides an explanation for why a selected MCQ answer is correct. | |
| * | |
| * - explainCorrectAnswer - A function that generates an explanation for a correct MCQ answer. | |
| * - ExplainCorrectAnswerInput - The input type for the explainCorrectAnswer function. | |
| * - ExplainCorrectAnswerOutput - The return type for the explainCorrectAnswer function. | |
| */ | |
| import {ai} from '@/ai/genkit'; | |
| import {z} from 'genkit'; | |
| const ExplainCorrectAnswerInputSchema = z.object({ | |
| question: z.string().describe('The multiple-choice question that was asked.'), | |
| options: z.array(z.string()).describe('All the options provided for the question.'), | |
| correctAnswer: z.string().describe('The actual correct answer to the question.'), | |
| }); | |
| export type ExplainCorrectAnswerInput = z.infer<typeof ExplainCorrectAnswerInputSchema>; | |
| const ExplainCorrectAnswerOutputSchema = z.object({ | |
| explanation: z.string().describe('The explanation of why the answer is correct.'), | |
| }); | |
| export type ExplainCorrectAnswerOutput = z.infer<typeof ExplainCorrectAnswerOutputSchema>; | |
| export async function explainCorrectAnswer(input: ExplainCorrectAnswerInput): Promise<ExplainCorrectAnswerOutput> { | |
| return explainCorrectAnswerFlow(input); | |
| } | |
| const prompt = ai.definePrompt({ | |
| name: 'explainCorrectAnswerPrompt', | |
| input: {schema: ExplainCorrectAnswerInputSchema}, | |
| output: {schema: ExplainCorrectAnswerOutputSchema}, | |
| prompt: `You are an expert educator. The following multiple-choice question was asked: | |
| Question: "{{question}}" | |
| Options: | |
| {{#each options}} | |
| - {{this}} | |
| {{/each}} | |
| The correct answer is "{{correctAnswer}}". | |
| Explain concisely why "{{correctAnswer}}" is the correct choice for the question. | |
| Your explanation should be helpful for the student to understand the concept. | |
| `, | |
| }); | |
| const explainCorrectAnswerFlow = ai.defineFlow( | |
| { | |
| name: 'explainCorrectAnswerFlow', | |
| inputSchema: ExplainCorrectAnswerInputSchema, | |
| outputSchema: ExplainCorrectAnswerOutputSchema, | |
| }, | |
| async input => { | |
| const {output} = await prompt(input); | |
| return output!; | |
| } | |
| ); | |