Skip to content

Commit 19b6c7e

Browse files
committed
Try to add promptfoo into the ci flow
1 parent 2ace40f commit 19b6c7e

File tree

6 files changed

+89
-98
lines changed

6 files changed

+89
-98
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ jobs:
1818
steps:
1919
- uses: actions/checkout@v4
2020

21+
- name: Set up Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: '18'
25+
cache: 'npm'
26+
27+
- name: Install promptfoo
28+
run: npm install -g promptfoo
29+
2130
- name: Set up Python ${{ matrix.python-version }}
2231
uses: actions/setup-python@v4
2332
with:
@@ -36,6 +45,10 @@ jobs:
3645
run: |
3746
uv run pytest --cov=src/isnt_that_odd --cov-report=xml
3847
48+
- name: Run promptfoo tests
49+
run: |
50+
promptfoo eval --config promptfoo.yaml
51+
3952
- name: Upload coverage to Codecov
4053
uses: codecov/codecov-action@v3
4154
with:
@@ -48,6 +61,15 @@ jobs:
4861
steps:
4962
- uses: actions/checkout@v4
5063

64+
- name: Set up Node.js
65+
uses: actions/setup-node@v4
66+
with:
67+
node-version: '18'
68+
cache: 'npm'
69+
70+
- name: Install promptfoo
71+
run: npm install -g promptfoo
72+
5173
- name: Set up Python
5274
uses: actions/setup-python@v4
5375
with:
@@ -67,6 +89,10 @@ jobs:
6789
uv run ruff check src/ tests/
6890
uv run mypy src/
6991
92+
- name: Run promptfoo lint
93+
run: |
94+
promptfoo lint --config promptfoo.yaml
95+
7096
build:
7197
runs-on: ubuntu-latest
7298
needs: [test, lint]

Makefile

Lines changed: 0 additions & 52 deletions
This file was deleted.

promptfoo.yaml

Lines changed: 28 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,131 +2,114 @@
22
description: Test prompts for determining if numbers are even or odd
33

44
prompts:
5-
- even_odd_prompt: |
6-
You are a mathematical assistant. Your task is to determine if the given number is even or odd.
7-
8-
Number: {{number}}
9-
10-
Instructions:
11-
1. A number is even if it is divisible by 2 with no remainder
12-
2. A number is odd if it is not divisible by 2
13-
3. For decimal numbers, only the integer part matters
14-
4. For negative numbers, the same rules apply
15-
5. Zero (0) is considered even
16-
17-
Please respond with ONLY a JSON object containing a boolean field "is_even":
18-
- Set "is_even" to true if the number is even
19-
- Set "is_even" to false if the number is odd
20-
21-
Example response format:
22-
{"is_even": true}
23-
24-
Your response:
5+
- id: even_odd_prompt
6+
raw: file://src/isnt_that_odd/prompts/even_odd.txt
7+
label: Even/Odd Determination Prompt
8+
vars:
9+
number: "{{number}}"
2510

2611
providers:
27-
- id: openai:gpt-3.5-turbo
12+
- id: xai:grok-3
2813
config:
2914
temperature: 0.0
3015
max_tokens: 50
31-
response_format:
32-
type: json_object
3316

3417
tests:
3518
- vars:
3619
number: 2
3720
assert:
38-
- type: contains-json
39-
value: '{"is_even": true}'
21+
- type: contains
22+
value: '"is_even": true'
4023
- type: contains
4124
value: "true"
4225
description: "Even number (2) should return true"
4326

4427
- vars:
4528
number: 3
4629
assert:
47-
- type: contains-json
48-
value: '{"is_even": false}'
30+
- type: contains
31+
value: '"is_even": false'
4932
- type: contains
5033
value: "false"
5134
description: "Odd number (3) should return false"
5235

5336
- vars:
5437
number: 0
5538
assert:
56-
- type: contains-json
57-
value: '{"is_even": true}'
39+
- type: contains
40+
value: '"is_even": true'
5841
- type: contains
5942
value: "true"
6043
description: "Zero (0) should return true (even)"
6144

6245
- vars:
6346
number: -4
6447
assert:
65-
- type: contains-json
66-
value: '{"is_even": true}'
48+
- type: contains
49+
value: '"is_even": true'
6750
- type: contains
6851
value: "true"
6952
description: "Negative even number (-4) should return true"
7053

7154
- vars:
7255
number: -7
7356
assert:
74-
- type: contains-json
75-
value: '{"is_even": false}'
57+
- type: contains
58+
value: '"is_even": false'
7659
- type: contains
7760
value: "false"
7861
description: "Negative odd number (-7) should return false"
7962

8063
- vars:
8164
number: 10.5
8265
assert:
83-
- type: contains-json
84-
value: '{"is_even": true}'
66+
- type: contains
67+
value: '"is_even": true'
8568
- type: contains
8669
value: "true"
8770
description: "Decimal number (10.5) should return true (integer part 10 is even)"
8871

8972
- vars:
9073
number: 15.8
9174
assert:
92-
- type: contains-json
93-
value: '{"is_even": false}'
75+
- type: contains
76+
value: '"is_even": false'
9477
- type: contains
9578
value: "false"
9679
description: "Decimal number (15.8) should return false (integer part 15 is odd)"
9780

9881
- vars:
9982
number: 100
10083
assert:
101-
- type: contains-json
102-
value: '{"is_even": true}'
84+
- type: contains
85+
value: '"is_even": true'
10386
- type: contains
10487
value: "true"
10588
description: "Large even number (100) should return true"
10689

10790
- vars:
10891
number: 999
10992
assert:
110-
- type: contains-json
111-
value: '{"is_even": false}'
93+
- type: contains
94+
value: '"is_even": false'
11295
- type: contains
11396
value: "false"
11497
description: "Large odd number (999) should return false"
11598

11699
- vars:
117100
number: "42"
118101
assert:
119-
- type: contains-json
120-
value: '{"is_even": true}'
102+
- type: contains
103+
value: '"is_even": true'
121104
- type: contains
122105
value: "true"
123106
description: "String number ('42') should return true"
124107

125108
- vars:
126109
number: "17"
127110
assert:
128-
- type: contains-json
129-
value: '{"is_even": false}'
111+
- type: contains
112+
value: '"is_even": false'
130113
- type: contains
131114
value: "false"
132115
description: "String number ('17') should return false"

src/isnt_that_odd/core.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Core functionality for determining if numbers are even using LLM APIs."""
2+
23
from typing import Optional
34
from typing import Union
45

@@ -42,7 +43,20 @@ def _create_prompt(self, number: Union[int, float, str]) -> str:
4243
Returns:
4344
A formatted prompt string
4445
"""
45-
return f"""You are a mathematical assistant. Your task is to determine if the given number is even or odd.
46+
import os
47+
from pathlib import Path
48+
49+
# Get the directory where this module is located
50+
current_dir = Path(__file__).parent
51+
prompt_file = current_dir / "prompts" / "even_odd.txt"
52+
53+
try:
54+
with open(prompt_file, "r", encoding="utf-8") as f:
55+
prompt_template = f.read()
56+
return prompt_template.format(number=number)
57+
except FileNotFoundError:
58+
# Fallback to hardcoded prompt if file not found
59+
return f"""You are a mathematical assistant. Your task is to determine if the given number is even or odd.
4660
4761
Number: {number}
4862
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Prompts package for the isn't that odd library."""
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
You are a mathematical assistant. Your task is to determine if the given number is even or odd.
2+
3+
Number: {{number}}
4+
5+
Instructions:
6+
1. A number is even if it is divisible by 2 with no remainder
7+
2. A number is odd if it is not divisible by 2
8+
3. For decimal numbers, only the integer part matters
9+
4. For negative numbers, the same rules apply
10+
5. Zero (0) is considered even
11+
12+
Please respond with ONLY a JSON object containing a boolean field "is_even":
13+
- Set "is_even" to true if the number is even
14+
- Set "is_even" to false if the number is odd
15+
16+
Example response format:
17+
{"is_even": true}
18+
19+
Your response:

0 commit comments

Comments
 (0)