DeepEval Example - Comparing Models in Parallel
DeepEval is an open source LLM evaluation framework that integrates with pytest,
making it a natural fit for treating LLM evaluations as regular tests. The Workflow below runs the same
DeepEval test suite against three different OpenAI models in parallel using a
matrix, and exports each model's results as metrics, so you
can compare how the models perform against the same quality criteria.
You can paste this directly into the YAML of an existing or new Workflow, just make sure to update the
name and namespace for your environment if needed.
- The
spec.content.filesproperty defines two inline files:requirements.txt- the Python packages the test suite needs.test_answers.py- a DeepEval test suite that asks the model under test two questions and scores each answer with theAnswerRelevancyMetric.
- The
spec.containerproperty defines the working directory, Python image, and environment variables for the Workflow; theOPENAI_API_KEYis resolved using the credential expression so the key is never stored in the Workflow definition itself.DEEPEVAL_RESULTS_FOLDERmakes DeepEval write a JSON file with the results of each test. - The Compare models step uses
parallel.matrixto fan out three workers - one per model - each with theMODEL_UNDER_TESTenvironment variable set to the corresponding matrix value. Thetransferproperty copies the test files to each worker. - Each worker runs three steps of its own:
- Run DeepEval installs DeepEval and runs the test suite. Its
cacheblock keeps the pip download cache between executions, so later runs install the packages from the cache instead of downloading them again; see Dependency Caching. - Export metrics runs the
testkube-ai-metrics-parserimage, which converts the DeepEval results into ametrics.lpfile tagged with the model name. It runs inside each worker because every worker has its own filesystem. - Save results uploads the results and the metrics file as artifacts; the
alwayscondition makes sure they are uploaded even if a test fails.
- Run DeepEval installs DeepEval and runs the test suite. Its
kind: TestWorkflow
apiVersion: testworkflows.testkube.io/v1
metadata:
name: deepeval-model-comparison
namespace: testkube
labels:
docs: example
type: ai
spec:
content:
files:
- path: /data/tests/requirements.txt
content: |
deepeval
openai
- path: /data/tests/test_answers.py
content: |
import os
from deepeval import assert_test
from deepeval.metrics import AnswerRelevancyMetric
from deepeval.test_case import LLMTestCase
from openai import OpenAI
client = OpenAI()
MODEL = os.environ["MODEL_UNDER_TEST"]
def ask(question):
response = client.chat.completions.create(
model=MODEL, messages=[{"role": "user", "content": question}]
)
return response.choices[0].message.content
def check(question, context):
case = LLMTestCase(input=question, actual_output=ask(question), retrieval_context=context)
assert_test(case, [AnswerRelevancyMetric(threshold=0.5)])
def test_refund_policy():
check("What if these shoes don't fit?",
["All customers are eligible for a 30 day full refund at no extra cost."])
def test_shipping_time():
check("How long does shipping take?",
["Standard shipping takes 3 to 5 business days."])
container:
workingDir: /data/tests
image: python:3.12-slim
env:
- name: HOME
value: /data
- name: PIP_CACHE_DIR
value: /root/.cache/pip
- name: DEEPEVAL_RESULTS_FOLDER
value: /data/tests/results
- name: DEEPEVAL_TELEMETRY_OPT_OUT
value: "YES"
- name: OPENAI_API_KEY
value: '{{credential("OPENAI_API_KEY")}}'
resources:
requests:
cpu: 500m
memory: 1Gi
steps:
- name: Compare models
parallel:
matrix:
model:
- gpt-4o
- gpt-5
- gpt-5.2
description: "Model: {{matrix.model}}"
transfer:
- from: /data/tests
container:
env:
- name: MODEL_UNDER_TEST
value: "{{matrix.model}}"
steps:
- name: Run DeepEval
cache:
key: 'pip-{{ hash_files("requirements.txt") }}'
restoreKeys:
- "pip-"
paths:
- /root/.cache/pip
shell: |
set -e
pip install -r requirements.txt
deepeval test run test_answers.py
- name: Export metrics
condition: always
container:
image: docker.io/kubeshop/testkube-ai-metrics-parser:latest
shell: testkube-ai-metrics-parser deepeval -i 'results/test_run_*.json' -o results/metrics.lp --tag model={{matrix.model}} --stdout
- name: Save results
condition: always
artifacts:
paths:
- results/*.json
- results/*.lp
After execution, each parallel worker is shown separately in the execution view with its own log output and
artifacts. Testkube ingests the metrics.lp files as custom metrics under
the deepeval measurement, with the mean score, test counts and cost of each metric tagged by model, so you can
compare the models side by side in Insights.