From 5104684dbd16784188a890de135f578d79999197 Mon Sep 17 00:00:00 2001 From: thsparks Date: Fri, 9 Feb 2024 16:29:42 -0800 Subject: [PATCH] Send AI Question to editor for evaluation --- localtypings/validatorPlan.d.ts | 7 ++++++- .../code-validation/runValidatorPlanAsync.ts | 10 +++++++++- teachertool/src/transforms/runEvaluateAsync.ts | 18 +++++++++++++++++- teachertool/src/types/errorCode.ts | 2 ++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/localtypings/validatorPlan.d.ts b/localtypings/validatorPlan.d.ts index 76ed715b496f..6aa057649264 100644 --- a/localtypings/validatorPlan.d.ts +++ b/localtypings/validatorPlan.d.ts @@ -35,7 +35,12 @@ declare namespace pxt.blocks { count: number; } + export interface AiQuestionValidatorCheck extends ValidatorCheckBase { + validator: "aiQuestion"; + question: string; + } + export interface EvaluationResult { result: boolean; } -} \ No newline at end of file +} diff --git a/pxteditor/code-validation/runValidatorPlanAsync.ts b/pxteditor/code-validation/runValidatorPlanAsync.ts index 347763cb2ee9..2a430bac4855 100644 --- a/pxteditor/code-validation/runValidatorPlanAsync.ts +++ b/pxteditor/code-validation/runValidatorPlanAsync.ts @@ -23,6 +23,8 @@ export async function runValidatorPlanAsync(usedBlocks: Blockly.Block[], plan: p return runValidateSpecificBlockCommentsExist(usedBlocks, check as pxt.blocks.SpecificBlockCommentsExistValidatorCheck); case "blocksInSetExist": return runBlocksInSetExistValidation(usedBlocks, check as pxt.blocks.BlocksInSetExistValidatorCheck); + case "aiQuestion": + return runAiQuestionValidation(check as pxt.blocks.AiQuestionValidatorCheck); default: pxt.debug(`Unrecognized validator: ${check.validator}`); return false; @@ -64,4 +66,10 @@ function runValidateSpecificBlockCommentsExist(usedBlocks: Blockly.Block[], inpu function runBlocksInSetExistValidation(usedBlocks: Blockly.Block[], inputs: pxt.blocks.BlocksInSetExistValidatorCheck): boolean { const blockResults = validateBlocksInSetExist({ usedBlocks, blockIdsToCheck: inputs.blocks, count: inputs.count }); return blockResults.passed; -} \ No newline at end of file +} + +function runAiQuestionValidation(inputs: pxt.blocks.AiQuestionValidatorCheck): boolean { + // TODO thsparks - send question to AI and get a response. + console.log(`Ask question: '${inputs.question}'`); + return true; +} diff --git a/teachertool/src/transforms/runEvaluateAsync.ts b/teachertool/src/transforms/runEvaluateAsync.ts index be5f27236b15..8da687ebb115 100644 --- a/teachertool/src/transforms/runEvaluateAsync.ts +++ b/teachertool/src/transforms/runEvaluateAsync.ts @@ -7,6 +7,7 @@ import { CriteriaEvaluationResult, CriteriaInstance } from "../types/criteria"; import { ErrorCode } from "../types/errorCode"; import { makeToast } from "../utils"; import { showToast } from "./showToast"; +import jp from "jsonpath"; function generateValidatorPlan(criteriaInstance: CriteriaInstance): pxt.blocks.ValidatorPlan | undefined { const { state: teacherTool } = stateAndDispatch(); @@ -27,7 +28,22 @@ function generateValidatorPlan(criteriaInstance: CriteriaInstance): pxt.blocks.V return undefined; } - // TODO: Fill in any parameters. Error if parameters are missing. + // Fill in parameters. + for (const param of criteriaInstance.params ?? []) { + const catalogParam = catalogCriteria.params?.find(p => p.name === param.name); + if (!catalogParam) { + logError(ErrorCode.evalMissingCatalogParameter, "Attempting to evaluate criteria with unrecognized parameter", {catalogId: criteriaInstance.catalogCriteriaId, paramName: param.name}); + return undefined; + } + + if (!param.value) { + // User didn't set a value for the parameter. + logError(ErrorCode.evalParameterUnset, "Attempting to evaluate criteria with unset parameter value", {catalogId: criteriaInstance.catalogCriteriaId, paramName: param.name}); + showToast(makeToast("error", lf("Unable to evaluate criteria: missing value for {0} in {1}", param.name, catalogCriteria.template))); + } + + jp.apply(plan, catalogParam.path, () => param.value); + } return plan; } diff --git a/teachertool/src/types/errorCode.ts b/teachertool/src/types/errorCode.ts index 94a23a5c7265..af7deadd15de 100644 --- a/teachertool/src/types/errorCode.ts +++ b/teachertool/src/types/errorCode.ts @@ -6,6 +6,8 @@ export enum ErrorCode { downloadTargetConfigAsync = "downloadTargetConfigAsync", evalMissingCriteria = "evalMissingCriteria", evalMissingPlan = "evalMissingPlan", + evalParameterUnset = "evalParameterUnset", + evalMissingCatalogParameter = "evalMissingCatalogParameter", loadCollectionFileFailed = "loadCollectionFileFailed", unableToGetIndexedDbRecord = "unableToGetIndexedDbRecord", unableToSetIndexedDbRecord = "unableToSetIndexedDbRecord",