Accuracy with Given Answer
Example showing how to evaluate the accuracy of an Kern Agent's response with a given answer.
Create a Python file
1from typing import Optional23from kern.eval.accuracy import AccuracyEval, AccuracyResult4from kern.models.openai import OpenAIResponses56evaluation = AccuracyEval(7 name="Given Answer Evaluation",8 model=OpenAIResponses(id="gpt-5.2"),9 input="What is 10*5 then to the power of 2? do it step by step",10 expected_output="2500",11)12result_with_given_answer: Optional[AccuracyResult] = evaluation.run_with_output(13 output="2500", print_results=True14)15assert result_with_given_answer is not None and result_with_given_answer.avg_score >= 8Set up your virtual environment
1uv venv --python 3.122source .venv/bin/activate1uv venv --python 3.122.venv\Scripts\activateInstall dependencies
1uv pip install -U openai kern-aiExport your OpenAI API key
1export OPENAI_API_KEY="your_openai_api_key_here"1$Env:OPENAI_API_KEY="your_openai_api_key_here"Run Agent
1python accuracy_with_given_answer.py