Spaces:
Sleeping
Sleeping
| 'use server'; | |
| /** | |
| * @fileOverview An AI flow to explain a given syllabus topic. | |
| * | |
| * - explainTopic - A function that handles the topic explanation. | |
| * - ExplainTopicInput - The input type for the explainTopic function. | |
| * - ExplainTopicOutput - The return type for the explainTopic function. | |
| */ | |
| import {ai} from '@/ai/genkit'; | |
| import {z} from 'genkit'; | |
| const ExplainTopicInputSchema = z.object({ | |
| topicText: z.string().describe('The syllabus topic text to be explained.'), | |
| }); | |
| export type ExplainTopicInput = z.infer<typeof ExplainTopicInputSchema>; | |
| const ExplainTopicOutputSchema = z.object({ | |
| explanation: z.string().describe('The AI-generated explanation for the topic, formatted in simple Markdown.'), | |
| }); | |
| export type ExplainTopicOutput = z.infer<typeof ExplainTopicOutputSchema>; | |
| export async function explainTopic(input: ExplainTopicInput): Promise<ExplainTopicOutput> { | |
| return explainTopicFlow(input); | |
| } | |
| const explainTopicPrompt = ai.definePrompt({ | |
| name: 'explainTopicPrompt', | |
| input: {schema: ExplainTopicInputSchema}, | |
| output: {schema: ExplainTopicOutputSchema}, | |
| prompt: `You are a helpful assistant. Explain the following syllabus topic concisely and clearly, in simple terms suitable for a university student. | |
| Make the explanation easy to understand and focus on the core concepts. | |
| Please use simple Markdown for formatting: | |
| - Use '#' for main headings and '##' for subheadings (e.g., # Main Title, ## Sub-section). | |
| - Use backticks (\`) for inline code snippets (e.g., \`String name = "Java"\`). | |
| - Use triple backticks (\`\`\`) for code blocks, specifying the language if known (e.g., \`\`\`java ...code... \`\`\`). | |
| - Use bullet points (-) for lists if appropriate. | |
| - Ensure paragraphs are well-separated. | |
| Topic: {{{topicText}}}`, | |
| }); | |
| const explainTopicFlow = ai.defineFlow( | |
| { | |
| name: 'explainTopicFlow', | |
| inputSchema: ExplainTopicInputSchema, | |
| outputSchema: ExplainTopicOutputSchema, | |
| }, | |
| async (input) => { | |
| const {output} = await explainTopicPrompt(input); | |
| if (!output) { | |
| throw new Error('No explanation was generated by the AI.'); | |
| } | |
| return output; | |
| } | |
| ); | |