site/docs/integrations/circle-ci.md
This guide shows how to integrate promptfoo's LLM evaluation into your CircleCI pipeline. This allows you to automatically test your prompts and models whenever changes are made to your repository.
Create a .circleci/config.yml file in your repository. Here's a basic configuration that installs promptfoo and runs evaluations:
```yaml
version: 2.1
jobs:
evaluate_prompts:
docker:
- image: cimg/node:20.0.0
steps:
- checkout
- restore_cache:
keys:
- promptfoo-cache-v1-{{ .Branch }}-{{ checksum "prompts/**/*" }}
- promptfoo-cache-v1-{{ .Branch }}
- promptfoo-cache-v1-
- run:
name: Install promptfoo
command: npm install -g promptfoo
- run:
name: Run prompt evaluation
command: promptfoo eval -c promptfooconfig.yaml --prompts prompts/**/*.json --share -o output.json
environment:
OPENAI_API_KEY: ${OPENAI_API_KEY}
PROMPTFOO_CACHE_PATH: ~/.promptfoo/cache
- save_cache:
key: promptfoo-cache-v1-{{ .Branch }}-{{ checksum "prompts/**/*" }}
paths:
- ~/.promptfoo/cache
- store_artifacts:
path: output.json
destination: evaluation-results
workflows:
version: 2
evaluate:
jobs:
- evaluate_prompts:
filters:
paths:
- prompts/**/*
```
OPENAI_API_KEY if you're using OpenAIThe configuration above includes caching to save time and API costs. The cache:
~/.promptfoo/cacheThe configuration stores the evaluation results as artifacts:
output.json--share flag creates a shareable web URL for resultsYou can add custom steps to process the evaluation results:
```yaml
- run:
name: Check evaluation results
command: |
if jq -e '.results.stats.failures > 0' output.json; then
echo "Evaluation had failures"
exit 1
fi
```
For large test suites, you can parallelize evaluations:
```yaml
jobs:
evaluate_prompts:
parallelism: 3
steps:
- run:
name: Split tests
command: |
prompts=$(find prompts -name "*.json" | circleci tests split)
promptfoo eval -c promptfooconfig.yaml --prompts $prompts
```
After the evaluation runs, you'll see:
Common issues and solutions:
Cache not working:
API key errors:
Evaluation timeout:
no_output_timeout setting in your jobFor more details on promptfoo configuration, see the configuration reference.