Skip to content

Commit 6133ecc

Browse files
committed
Address feedback 1
Signed-off-by: Claudio Spiess <[email protected]>
1 parent 344f6f4 commit 6133ecc

File tree

6 files changed

+302
-417
lines changed

6 files changed

+302
-417
lines changed

examples/optimizer/evalplus.pdl

Lines changed: 60 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,41 @@ defs:
99
trajectory: ${ trajectory }
1010
repeat:
1111
text:
12-
- def: type
13-
text: ${ trajectory.keys()|first }
14-
contribute: []
15-
- if: ${ type == 'task'}
16-
then: |
17-
Task:
18-
${ trajectory[type]|trim }
19-
- if: ${ type == 'thought'}
20-
then:
21-
text:
22-
- "\n"
23-
- |
24-
Assistant:
25-
<thought>${ trajectory[type]|trim }</thought>
26-
- if: ${ type == 'action'}
27-
then: |
28-
<execute>
29-
${ trajectory[type]|trim }
30-
</execute>
31-
- if: ${ type == 'observation'}
32-
then:
33-
text:
34-
- "\n"
35-
- |
36-
Observation:
37-
${ trajectory[type]|trim }
38-
- if: ${ type == 'solution'}
39-
then: |-
40-
<solution>
41-
${ trajectory[type]|trim }
42-
</solution>
43-
- if: ${ type not in ['question', 'task', 'thought', 'action', 'observation', 'solution'] }
44-
then: "${ type }: ${ trajectory[type]|trim }"
12+
- defs:
13+
type:
14+
text: ${ trajectory.keys()|first }
15+
match: ${ type }
16+
with:
17+
- case: task
18+
then: |
19+
Task:
20+
${ trajectory[type]|trim }
21+
- case: thought
22+
then:
23+
text:
24+
- "\n"
25+
- |
26+
Assistant:
27+
<thought>${ trajectory[type]|trim }</thought>
28+
- case: action
29+
then: |
30+
<execute>
31+
${ trajectory[type]|trim }
32+
</execute>
33+
- case: observation
34+
then:
35+
text:
36+
- "\n"
37+
- |
38+
Observation:
39+
${ trajectory[type]|trim }
40+
- case: solution
41+
then: |-
42+
<solution>
43+
${ trajectory[type]|trim }
44+
</solution>
45+
- if: ${ type not in ['question'] }
46+
then: "${ type }: ${ trajectory[type]|trim }"
4547
- "\n"
4648
react_demos:
4749
data:
@@ -79,9 +81,10 @@ defs:
7981
def similar_elements(test_tup1, test_tup2):
8082
res = tuple(set(test_tup1) & set(test_tup2))
8183
return res
82-
text:
84+
match: ${ prompt_pattern }
85+
with:
8386
# CoT
84-
- if: ${ prompt_pattern == 'cot' }
87+
- case: cot
8588
then:
8689
text:
8790
- for:
@@ -104,7 +107,7 @@ text:
104107
temperature: 0
105108

106109
# ReAct
107-
- if: ${ prompt_pattern == 'react' }
110+
- case: react
108111
then:
109112
text:
110113
# see https://github.com/xingyaoww/mint-bench/blob/main/mint/tasks/in_context_examples/mbpp/with_tool.txt for prompt
@@ -139,34 +142,32 @@ text:
139142
- repeat:
140143
text:
141144
- repeat:
145+
defs:
146+
iterations: ${ iterations+1 }
147+
def: THOUGHT
142148
text:
149+
- model: ${ model }
150+
def: THOUGHT_inner
151+
parameters:
152+
temperature: ${ temperature }
153+
stop:
154+
- </execute>
155+
- </solution>
156+
- <|endoftext|>
157+
max_tokens: 1024
158+
include_stop_sequences: true
143159
- defs:
144-
iterations: ${ iterations+1 }
145-
- def: THOUGHT
146-
text:
147-
- model: ${ model }
148-
def: THOUGHT_inner
149-
parameters:
150-
temperature: ${ temperature }
151-
stop:
152-
- </execute>
153-
- </solution>
154-
- <|endoftext|>
155-
max_tokens: 1024
156-
include_stop_sequences: true
157-
- def: thought_trim
158-
contribute: []
159-
text: ${ THOUGHT_inner|trim|trim('\n') }
160-
until: ${ thought_trim.endswith('</solution>') or (thought_trim).endswith('</execute>') or iterations>max_iterations }
161-
- if: ${ (thought_trim).endswith('</execute>') }
160+
thought_trim: ${ THOUGHT_inner|trim|trim('\n') }
161+
until: ${ thought_trim.endswith('</solution>') or thought_trim.endswith('</execute>') or iterations>max_iterations }
162+
- if: ${ thought_trim.endswith('</execute>') }
162163
then:
163164
text:
164165
- "\n\nObservation:\n"
165-
- def: observation
166-
contribute: []
167-
lang: ipython
168-
code: |
169-
${ thought_trim.split('<execute>')[-1].strip('</execute>\n\n').lstrip('```python').strip('`') or thought_trim }
166+
- defs:
167+
observation:
168+
lang: ipython
169+
code: |
170+
${ thought_trim.split('<execute>')[-1].strip('</execute>\n\n').lstrip('```python').strip('`') or thought_trim }
170171
- "${ (observation|trim|trim('\n')) if observation is not none else '[Executed Successfully with No Output]' }"
171172
- |-
172173

examples/optimizer/fever.pdl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ defs:
2525
task: |-
2626
Task: On June 2017, the following claim was made: ${ claim }
2727
Q: Was this claim true or false?
28-
text:
28+
match: ${ prompt_pattern }
29+
with:
2930
# CoT
30-
- if: ${ prompt_pattern == 'cot' }
31+
- case: cot
3132
then:
3233
call: ${ cot.chain_of_thought }
3334
args:
@@ -36,7 +37,7 @@ text:
3637
model: "${ model }"
3738

3839
# ReAct
39-
- if: ${ prompt_pattern == 'react' }
40+
- case: react
4041
then:
4142
text:
4243
call: ${ react.react }
@@ -48,7 +49,7 @@ text:
4849
trajectories: ${ demonstrations }
4950

5051
# ReWOO
51-
- if: ${ prompt_pattern == 'rewoo' }
52+
- case: rewoo
5253
then:
5354
text:
5455
call: ${ rewoo.rewoo }
@@ -58,4 +59,4 @@ text:
5859
tool_schema: ${ search_tools }
5960
tools: ${ tools.tools }
6061
trajectories: ${ demonstrations }
61-
show_plans: false
62+
show_plans: false

examples/optimizer/gsm8k.pdl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ defs:
88
import: ../../contrib/prompt_library/ReWoo
99
tools:
1010
import: ../../contrib/prompt_library/tools
11-
text:
11+
match: ${ prompt_pattern }
12+
with:
1213
# CoT
13-
- if: "${ prompt_pattern == 'cot' }"
14+
- case: cot
1415
then:
1516
text:
1617
- "Answer the questions to the best of your abilities.\n\n"
@@ -24,7 +25,7 @@ text:
2425
- "\nThe answer is ${ ANSWER.answer|trim }"
2526

2627
# ReAct
27-
- if: ${ prompt_pattern == 'react' }
28+
- case: react
2829
then:
2930
text:
3031
call: ${ react.react }
@@ -36,7 +37,7 @@ text:
3637
trajectories: ${ demonstrations }
3738

3839
# ReWOO
39-
- if: ${ prompt_pattern == 'rewoo' }
40+
- case: rewoo
4041
then:
4142
text:
4243
call: ${ rewoo.rewoo }

src/pdl/optimize/mbpp_evaluator.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ def get_scope(self) -> ScopeType:
3030

3131
match self.candidate.get("prompt_pattern", None):
3232
case "cot":
33-
scope["prompt"] = self.example[
34-
"react_prompt"
35-
] # .strip('"""').strip().strip('"""').strip()
33+
scope["prompt"] = self.example["react_prompt"]
3634
scope["demonstrations"] = [
3735
{
3836
"question": q["react_prompt"],

0 commit comments

Comments
 (0)