Skip to content

Commit cd79aba

Browse files
authored
Mock results for LLM calls in test suite (#57)
* mock responses for llm calls Signed-off-by: Mandana Vaziri <[email protected]> * removing secrets from build file Signed-off-by: Mandana Vaziri <[email protected]> --------- Signed-off-by: Mandana Vaziri <[email protected]>
1 parent 3346553 commit cd79aba

File tree

12 files changed

+50
-26
lines changed

12 files changed

+50
-26
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ jobs:
3939
- name: pre-commit checks
4040
run: pre-commit run -a
4141
- name: run tests
42-
env:
43-
WATSONX_PROJECT_ID: ${{ secrets.WATSONX_PROJECT_ID }}
44-
WATSONX_KEY: ${{ secrets.WATSONX_KEY }}
45-
WATSONX_API: ${{ secrets.WATSONX_API }}
46-
WATSONX_APIKEY: ${{ secrets.WATSONX_APIKEY }}
47-
WATSONX_URL: ${{ secrets.WATSONX_URL }}
4842
run: py.test -v --capture=tee-sys tests
4943

5044
viewer:

examples/hello/test.pdl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
description: Hello world with model chaining
2+
document:
3+
- model: "foo"
4+
parameters:
5+
foo:
6+
data: "{{ translateText(sentence2) }}"
7+
raw: true

tests/data/line/hello14.pdl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ document:
77
stop:
88
- '!'
99
include_stop_sequence: true
10+
mock_response: " World!"
1011
- def: translate
1112
function:
1213
sentence: str
@@ -19,6 +20,7 @@ document:
1920
stop:
2021
- '!'
2122
include_stop_sequence: true
23+
mock_response: "Bonjour le monde!"
2224
- call: translate
2325
spec: str
2426
args:

tests/data/line/hello16.pdl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ document:
2525
stop:
2626
- '}'
2727
include_stop_sequence: true
28+
mock_response: '{"bob": 20, "carol": 30}'

tests/data/line/hello24.pdl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ document:
77
stop:
88
- '!'
99
include_stop_sequence: true
10+
mock_response: " World!"
1011
- def: translate
1112
function:
1213
sentence: str
@@ -15,6 +16,8 @@ document:
1516
return:
1617
- "\nTranslate the sentence '{{ sentence }}' to {{ language }}\n"
1718
- model: watsonx/ibm/granite-34b-code-instruct
19+
parameters:
20+
mock_response: " World!"
1821
- call: translate
1922
spec: str
2023
args:

tests/data/line/hello26.pdl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,12 @@ document:
2222
decoding_method: greedy
2323
stop:
2424
- '}'
25-
include_stop_sequence: true
25+
include_stop_sequence: true
26+
mock_response:
27+
|
28+
Here is the code:
29+
```json
30+
{
31+
"bob": "20",
32+
"carol": "30"
33+
}

tests/data/line/hello3.pdl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ document:
99
decoding_method: greedy
1010
stop:
1111
- '!'
12-
include_stop_sequence: true
12+
include_stop_sequence: true
13+
mock_response: " World!"

tests/test_defs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"parameters": {
1414
"stop": ["!"],
1515
"include_stop_sequence": False,
16+
"mock_response": " World",
1617
},
1718
}
1819
]

tests/test_line_table.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ def test_line13(capsys):
173173
"errors": [
174174
"",
175175
"Hello, World!Bonjour le monde!",
176-
"tests/data/line/hello14.pdl:22 - Type errors in result of function call to translate",
177-
"tests/data/line/hello14.pdl:15 - Bonjour le monde! should be of type <class 'int'>",
176+
"tests/data/line/hello14.pdl:24 - Type errors in result of function call to translate",
177+
"tests/data/line/hello14.pdl:16 - Bonjour le monde! should be of type <class 'int'>",
178178
],
179179
}
180180

@@ -311,13 +311,13 @@ def test_line23(capsys):
311311
"errors": [
312312
"",
313313
"Hello, World!",
314-
"tests/data/line/hello24.pdl:21 - 'GEN1' is undefined",
315-
"tests/data/line/hello24.pdl:22 - 'GEN2' is undefined",
316-
"tests/data/line/hello24.pdl:20 - Type errors during function call to translate",
314+
"tests/data/line/hello24.pdl:24 - 'GEN1' is undefined",
315+
"tests/data/line/hello24.pdl:25 - 'GEN2' is undefined",
316+
"tests/data/line/hello24.pdl:23 - Type errors during function call to translate",
317317
"tests/data/line/hello24.pdl:21 - None should be of type <class 'str'>",
318-
"tests/data/line/hello24.pdl:22 - None should be of type <class 'str'>",
319-
"tests/data/line/hello24.pdl:18 - Type errors during spec checking",
320-
"tests/data/line/hello24.pdl:18 - None should be of type <class 'str'>",
318+
"tests/data/line/hello24.pdl:25 - None should be of type <class 'str'>",
319+
"tests/data/line/hello24.pdl:21 - Type errors during spec checking",
320+
"tests/data/line/hello24.pdl:24 - None should be of type <class 'str'>",
321321
],
322322
}
323323

@@ -336,9 +336,9 @@ def test_line24(capsys):
336336
],
337337
}
338338

339-
340-
def test_line25(capsys):
341-
do_test(line25, capsys)
339+
# Leaving this out for now, since we can't mock the model result
340+
# def test_line25(capsys):
341+
# do_test(line25, capsys)
342342

343343

344344
line26 = {

tests/test_model.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"decoding_method": "greedy",
1212
"stop_sequences": ["!"],
1313
"include_stop_sequence": False,
14+
"mock_response": " World",
1415
},
1516
},
1617
"!\n",
@@ -38,6 +39,7 @@ def test_model():
3839
"decoding_method": "greedy",
3940
"stop": ["!"],
4041
"include_stop_sequence": False,
42+
"mock_response": " World",
4143
},
4244
}
4345
],
@@ -56,6 +58,7 @@ def test_model():
5658
"stop_sequences": ["."],
5759
"include_stop_sequence": True,
5860
"roles": {"user": {"pre_message": "", "post_message": ""}},
61+
"mock_response": 'World is a fictional character in the popular science fiction television series "The X-Files',
5962
},
6063
},
6164
],
@@ -98,6 +101,7 @@ def test_model_chain():
98101
"decoding_method": "greedy",
99102
"stop_sequences": ["Question"],
100103
"include_stop_sequence": False,
104+
"mock_response": "Armonk",
101105
},
102106
}
103107
],
@@ -121,6 +125,7 @@ def test_multi_shot():
121125
"model": "watsonx/ibm/granite-34b-code-instruct",
122126
"parameters": {
123127
"stop_sequences": ["."],
128+
"mock_response": '\nI have a question about the use of the word "in" in the sentence: "The cake was baked in the oven.',
124129
},
125130
},
126131
],
@@ -144,9 +149,7 @@ def test_data_missing_parameters():
144149
"Hello,",
145150
{
146151
"model": "{{ model }}",
147-
"parameters": {
148-
"stop_sequences": ["!"],
149-
},
152+
"parameters": {"stop_sequences": ["!"], "mock_response": " World!"},
150153
},
151154
],
152155
}
@@ -166,9 +169,7 @@ def test_model_parameter():
166169
"Hello,",
167170
{
168171
"model": "watsonx/ibm/{{ model }}",
169-
"parameters": {
170-
"stop_sequences": ["!"],
171-
},
172+
"parameters": {"stop_sequences": ["!"], "mock_response": " World!"},
172173
},
173174
],
174175
}

0 commit comments

Comments
 (0)