From the course: Claude with Amazon Bedrock by Anthropic
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Code-based grading
From the course: Claude with Amazon Bedrock by Anthropic
Code-based grading
Next up, we need to implement our code grader. So our code grader is gonna take in some output from the model and make sure that we get back just plain Python, JSON, or regular expression without any kind of explanation. In addition, we should also make sure that we have valid syntax for whatever type of code we actually got. You might be kind of curious, how are we going to validate the syntax of say Python at all? Well, we use a little trick for this. We're going to define three helper functions. One will be called validateJSON, another validatePython, and another validateRegEx. Then inside of each of those, we're gonna take whatever output we got from the model and try to either parse it as JSON, we'll try to parse it as a Python abstract syntax tree or AST, or we'll try to compile it as a regular expression. And then for each of these, if we successfully parse or load or whatever else, we'll return a full score of 10. Otherwise, if we get an error during this parsing operation…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.