Gauntlet-Incept MCP

/** * Article Service * * This file implements the core functionality for the Article API endpoints: * - tagArticle: Identifies subject, grade, standard, and lesson of a given article * - gradeArticle: Evaluates a tagged article against quality standards * - generateArticle: Creates articles based on specified tags or example articles */ // Import utilities and models const { callLLM } = require('../utils/llmUtils'); const { connectToCCC } = require('../utils/cccUtils'); const { saveToQTI } = require('../utils/qtiUtils'); const { measureAccuracy } = require('../utils/testHarness'); /** * Tag an article with subject, grade, standard, and lesson * * @param {Object} article - The article to tag * @returns {Object} The tags for the article */ async function tagArticle(article) { try { // TODO: Implement actual tagging logic using LLM console.log('Tagging article:', article.substring(0, 50) + '...'); // Placeholder implementation const tags = { subject: 'math', grade: '6', standard: 'CCSS.Math.6.NS.1', lesson: 'Division of Fractions' }; return tags; } catch (error) { console.error('Error in tagArticle:', error); throw new Error('Failed to tag article: ' + error.message); } } /** * Grade a tagged article against quality standards * * @param {Object} article - The article to grade * @param {Object} tags - The tags for the article * @returns {Object} The grading result */ async function gradeArticle(article, tags) { try { // TODO: Implement actual grading logic using LLM console.log('Grading article:', article.substring(0, 50) + '...'); console.log('With tags:', tags); // Placeholder implementation const gradeResult = { pass: true, scorecard: { appropriateCategorization: true, directInstructionStyle: true, workedExamples: true, stepByStepBreakdowns: true, factuallyAccurate: true, gradeAppropriateLanguage: true, clearAndUnambiguousWording: true, properlyFormatted: true, consistentExplanations: true }, feedback: 'This article meets all quality standards.' }; return gradeResult; } catch (error) { console.error('Error in gradeArticle:', error); throw new Error('Failed to grade article: ' + error.message); } } /** * Generate an article based on tags or an example article * * @param {Object} tags - The tags for the article to generate * @param {Object} exampleArticle - An example article to base the generation on * @returns {Object} The generated article */ async function generateArticle(tags, exampleArticle) { try { // TODO: Implement actual generation logic using LLM console.log('Generating article with tags:', tags); if (exampleArticle) { console.log('Based on example:', exampleArticle.substring(0, 50) + '...'); } // Placeholder implementation let attempts = 0; let generatedArticle; let gradeResult; do { attempts++; console.log(`Generation attempt ${attempts}`); // Generate article generatedArticle = await generateArticleInternal(tags, exampleArticle); // Grade the generated article gradeResult = await gradeArticle(generatedArticle, tags); } while (!gradeResult.pass && attempts < 3); if (!gradeResult.pass) { throw new Error('Failed to generate an article that meets quality standards after 3 attempts'); } // Save the generated article to QTI await saveToQTI(generatedArticle, tags, 'article'); return { article: generatedArticle, tags: tags, gradeResult: gradeResult }; } catch (error) { console.error('Error in generateArticle:', error); throw new Error('Failed to generate article: ' + error.message); } } /** * Internal function to generate an article without quality control * * @param {Object} tags - The tags for the article to generate * @param {Object} exampleArticle - An example article to base the generation on * @returns {Object} The generated article */ async function generateArticleInternal(tags, exampleArticle) { // TODO: Implement actual generation logic using LLM // Placeholder implementation const articleTemplate = ` # Division of Fractions In this lesson, you will learn how to divide fractions. Dividing fractions is an important skill that builds on your knowledge of multiplication and reciprocals. ## What is Division of Fractions? When we divide one fraction by another, we are finding out how many times the second fraction goes into the first fraction. ## The Rule for Dividing Fractions To divide fractions, follow this simple rule: 1. Take the reciprocal (flip) of the second fraction (the divisor) 2. Multiply the first fraction by the reciprocal of the second fraction 3. Simplify the result if possible ## Worked Example 1 Let's divide 3/4 by 1/2. Step 1: Take the reciprocal of the divisor (1/2). The reciprocal of 1/2 is 2/1 or simply 2. Step 2: Multiply the first fraction by the reciprocal of the second fraction. 3/4 × 2/1 = 6/4 Step 3: Simplify the result if possible. 6/4 = 3/2 or 1 1/2 So, 3/4 ÷ 1/2 = 3/2 or 1 1/2. ## Worked Example 2 Let's divide 2/3 by 4/5. Step 1: Take the reciprocal of the divisor (4/5). The reciprocal of 4/5 is 5/4. Step 2: Multiply the first fraction by the reciprocal of the second fraction. 2/3 × 5/4 = 10/12 Step 3: Simplify the result if possible. 10/12 = 5/6 So, 2/3 ÷ 4/5 = 5/6. ## Why This Works Division is the inverse of multiplication. When we divide by a number, we can multiply by its reciprocal instead. This is because a number multiplied by its reciprocal equals 1, and multiplying by 1 doesn't change the value. ## Practice Now try these examples on your own: 1. 1/2 ÷ 1/4 = ? 2. 3/5 ÷ 2/3 = ? 3. 4/7 ÷ 2/3 = ? Remember the rule: "Keep, Change, Flip" - Keep the first fraction, change division to multiplication, and flip (take the reciprocal of) the second fraction. `; return articleTemplate; } module.exports = { tagArticle, gradeArticle, generateArticle };