Skip to content

Commit

Permalink
Send AI Question to editor for evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
thsparks committed Feb 10, 2024
1 parent 7ec4ef4 commit 5104684
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
7 changes: 6 additions & 1 deletion localtypings/validatorPlan.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ declare namespace pxt.blocks {
count: number;
}

export interface AiQuestionValidatorCheck extends ValidatorCheckBase {
validator: "aiQuestion";
question: string;
}

export interface EvaluationResult {
result: boolean;
}
}
}
10 changes: 9 additions & 1 deletion pxteditor/code-validation/runValidatorPlanAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

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;
}
18 changes: 17 additions & 1 deletion teachertool/src/transforms/runEvaluateAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions teachertool/src/types/errorCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export enum ErrorCode {
downloadTargetConfigAsync = "downloadTargetConfigAsync",
evalMissingCriteria = "evalMissingCriteria",
evalMissingPlan = "evalMissingPlan",
evalParameterUnset = "evalParameterUnset",
evalMissingCatalogParameter = "evalMissingCatalogParameter",
loadCollectionFileFailed = "loadCollectionFileFailed",
unableToGetIndexedDbRecord = "unableToGetIndexedDbRecord",
unableToSetIndexedDbRecord = "unableToSetIndexedDbRecord",
Expand Down

0 comments on commit 5104684

Please sign in to comment.