Skip to content

Commit 3f62823

Browse files
authored
Remove implicit lastOf (#167)
1 parent 7e6227f commit 3f62823

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+865
-8015
lines changed

examples/callback/repair_prompt.pdl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
- text: |
2-
Given the following code:
3-
```python
4-
${code_line}
5-
```
6-
and the following error:
7-
${error_msg}
8-
Please repair the code!
9-
contribute: [context]
1+
lastOf:
2+
- |
3+
Given the following code:
4+
```python
5+
${code_line}
6+
```
7+
and the following error:
8+
${error_msg}
9+
Please repair the code!
1010

1111
- def: raw_output
1212
model: replicate/ibm-granite/granite-3.0-8b-instruct

examples/cldk/cldk-assistant.pdl

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,13 @@ text:
3838
text:
3939
- model: replicate/ibm-granite/granite-3.0-8b-instruct
4040
def: PDL
41-
input:
42-
- |
41+
input: |
4342
Question: What are all the classes?
4443
Answer:
4544
```
4645
text:
4746
- lang: python
48-
code:
49-
- |
47+
code:|
5048
classes = PDL_SESSION.cldk_state.get_classes().keys()
5149
result = ", ".join(classes)
5250
```
@@ -56,8 +54,7 @@ text:
5654
```
5755
text:
5856
- lang: python
59-
code:
60-
- |
57+
code: |
6158
constructors = PDL_SESSION.cldk_state.get_constructors("org.ibm.App")
6259
result = ", ".join(constructors)
6360
```
@@ -67,8 +64,7 @@ text:
6764
```
6865
text:
6966
- lang: python
70-
code:
71-
- |
67+
code: |
7268
fields = PDL_SESSION.cldk_state.get_fields("org.ibm.App")
7369
names = sum([f.variables for f in fields], [])
7470
result = ", ".join(names)
@@ -79,8 +75,7 @@ text:
7975
```
8076
text:
8177
- lang: python
82-
code:
83-
- |
78+
code: |
8479
methods = PDL_SESSION.cldk_state.get_methods_in_class("org.ibm.App")
8580
result = ", ".join(methods)
8681
```
@@ -90,8 +85,7 @@ text:
9085
```
9186
text:
9287
- lang: python
93-
code:
94-
- |
88+
code: |
9589
graph = PDL_SESSION.cldk_state.get_class_call_graph("org.ibm.App", method_name=None)
9690
result = graph
9791
```
@@ -101,8 +95,7 @@ text:
10195
```
10296
text:
10397
- lang: python
104-
code:
105-
- |
98+
code: |
10699
method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)")
107100
result = method.code
108101
```
@@ -112,8 +105,7 @@ text:
112105
```
113106
text:
114107
- lang: python
115-
code:
116-
- |
108+
code: |
117109
method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)")
118110
result = method
119111
- "\n\nGenerate a summary of method Foo\n\n"
@@ -125,8 +117,7 @@ text:
125117
```
126118
text:
127119
- lang: python
128-
code:
129-
- |
120+
code: |
130121
method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)")
131122
result = method
132123
- "\n\nGenerate a different comment for method Foo(string)\n\n"
@@ -151,8 +142,3 @@ text:
151142
result = exec_str(pdl)
152143

153144
until: ${ query == 'quit' }
154-
155-
156-
157-
158-

examples/code/code.pdl

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@ defs:
66
text:
77
- "\n${ CODE.source_code }\n"
88
- model: replicate/ibm-granite/granite-3.0-8b-instruct
9-
input:
10-
- |
11-
Here is some info about the location of the function in the repo.
12-
repo:
13-
${ CODE.repo_info.repo }
14-
path: ${ CODE.repo_info.path }
15-
Function_name: ${ CODE.repo_info.function_name }
9+
input: |
10+
Here is some info about the location of the function in the repo.
11+
repo:
12+
${ CODE.repo_info.repo }
13+
path: ${ CODE.repo_info.path }
14+
Function_name: ${ CODE.repo_info.function_name }
1615

17-
18-
Explain the following code:
19-
```
20-
${ CODE.source_code }```
16+
17+
Explain the following code:
18+
```
19+
${ CODE.source_code }```
2120
parameters:
2221
temperature: 0

examples/demo/1-gen-data.pdl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ text:
1414
- for:
1515
question: ${ data.questions }
1616
answer: ${ data.answers }
17-
repeat:
18-
- |
19-
${ question }
20-
${ answer }
17+
repeat: |
18+
${ question }
19+
${ answer }
2120
- >
2221
Question: Create a JSON object with fields 'name' and 'age'
2322
and set them appropriately. Write the age in letters.

examples/demo/2-teacher.pdl

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ defs:
4646
icl_answer: str
4747
spec: [{icl_question: str, icl_answer: str, question: str}]
4848
return:
49-
- defs:
49+
defs:
5050
prompt_data:
5151
call: question_template_freeform
5252
spec: { introduction: str, principles: str, examples: str, generation: str, max_new_tokens: int }
@@ -73,7 +73,7 @@ defs:
7373
parser:
7474
regex: '### Question [0-9]+:\s*([^#\n]+)'
7575
mode: findall
76-
- for:
76+
for:
7777
question: ${teacher_output}
7878
repeat:
7979
data:
@@ -89,7 +89,7 @@ defs:
8989
seed_examples: [{question: str, answer: str}]
9090
spec: [{icl_question: str, icl_answer: str, question: str}]
9191
return:
92-
- defs:
92+
defs:
9393
list_of_lists:
9494
for:
9595
example: ${seed_examples}
@@ -102,7 +102,7 @@ defs:
102102
icl_answer: ${example.answer}
103103
join:
104104
as: array
105-
- lang: python
105+
lang: python
106106
code: | # flatten list_of_lists into simple list
107107
result = [q for qs in ${list_of_lists} for q in qs]
108108

@@ -137,7 +137,7 @@ defs:
137137
question: str
138138
spec: float
139139
return:
140-
- defs:
140+
defs:
141141
prompt_data:
142142
call: filter_questions_template
143143
spec: {introduction: str, principles: str, generation: str, max_new_tokens: int}
@@ -164,25 +164,26 @@ defs:
164164
# regex: "Rating.*\\[\\[(?P<rating>\\d+\\.?\\d*)\\]\\]"
165165
regex: 'Rating.*\[\[(?P<rating>\d+\.?\d*)\]\]'
166166
mode: search
167-
- ${ teacher_output.rating | float }
167+
data: ${ teacher_output.rating | float }
168168

169169
filter_questions:
170170
function:
171171
task_description: str
172172
questions: [{icl_question: str, icl_answer: str, question: str}]
173173
spec: [{icl_question: str, icl_answer: str, question: str}]
174174
return:
175-
- defs:
175+
defs:
176176
list_of_pairs:
177177
for:
178178
question: ${questions}
179179
repeat:
180-
- def: filter_output
181-
call: filter_questions_inner
182-
args:
183-
task_description: ${task_description}
184-
question: ${question.question}
185-
- data:
180+
defs:
181+
filter_output:
182+
call: filter_questions_inner
183+
args:
184+
task_description: ${task_description}
185+
question: ${question.question}
186+
data:
186187
question: ${question}
187188
keep: ${filter_output}
188189
join:
@@ -191,7 +192,7 @@ defs:
191192
lang: python
192193
code: | # keep only if "keep" column is non-zero
193194
result = [p["question"] for p in ${ list_of_pairs } if p["keep"]]
194-
- ${filtered}
195+
data: ${filtered}
195196

196197

197198
answer_template:
@@ -230,7 +231,7 @@ defs:
230231
question: {icl_question: str, icl_answer: str, question: str}
231232
spec: {question: str, answer: str}
232233
return:
233-
- defs:
234+
defs:
234235
prompt_data:
235236
call: answer_template
236237
spec: {introduction: str, principles: str, examples: str, generation: str, max_new_tokens: int, additional_stop_tokens: [str]}
@@ -262,7 +263,7 @@ defs:
262263
result = result[result.find("[Response]") + len("[Response]"):]
263264
if "[Question]" in result:
264265
result = result[:result.find("[Question]")]
265-
- data:
266+
data:
266267
question: ${question.question}
267268
answer: ${parsed_answer}
268269

@@ -271,7 +272,7 @@ defs:
271272
questions: [{icl_question: str, icl_answer: str, question: str}]
272273
spec: [{question: str, answer: str}]
273274
return:
274-
- defs:
275+
defs:
275276
all_results:
276277
spec: [{question: str, answer: str}]
277278
for:
@@ -282,7 +283,7 @@ defs:
282283
question: ${question}
283284
join:
284285
as: array
285-
- lang: python
286+
lang: python
286287
spec: [{question: str, answer: str}]
287288
code: | # keep only if answer non-empty
288289
result = [r for r in ${all_results} if len(r["answer"]) > 0]
@@ -319,7 +320,7 @@ defs:
319320
answer: str
320321
spec: float
321322
return:
322-
- defs:
323+
defs:
323324
prompt_data:
324325
call: filter_qa_template
325326
spec: {introduction: str, principles: str, generation: str, max_new_tokens: int}
@@ -345,25 +346,26 @@ defs:
345346
spec: { "rating": str }
346347
regex: 'Rating.*\[\[(?P<rating>\d+\.?\d*)\]\]'
347348
mode: search
348-
- ${ (teacher_output.rating if teacher_output.rating is not none else 0.0) | float}
349+
data: ${ (teacher_output.rating if teacher_output.rating is not none else 0.0) | float}
349350

350351
filter_question_answer_pair:
351352
function:
352353
qa_pairs: [{question: str, answer: str}]
353354
spec: [{question: str, answer: str}]
354355
return:
355-
- defs:
356+
defs:
356357
ratings:
357358
for:
358359
qa_pair: ${qa_pairs}
359360
repeat:
360-
- def: filter_output
361-
call: filter_question_answer_pair_inner
362-
spec: float
363-
args:
364-
question: ${qa_pair.question}
365-
answer: ${qa_pair.answer}
366-
- data:
361+
defs:
362+
filter_output:
363+
call: filter_question_answer_pair_inner
364+
spec: float
365+
args:
366+
question: ${qa_pair.question}
367+
answer: ${qa_pair.answer}
368+
data:
367369
qa_pair: ${qa_pair}
368370
rating: ${filter_output}
369371
join:
@@ -373,7 +375,7 @@ defs:
373375
spec: [{question: str, answer: str}]
374376
code: | # keep only if rating is at least two
375377
result = [p["qa_pair"] for p in ${ratings} if p["rating"] >= 2]
376-
- ${filtered}
378+
data: ${filtered}
377379

378380

379381
text:

examples/hello/hello-data.pdl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ text:
44
- def: stutter
55
function:
66
return:
7-
- ${ something }
7+
${ something }
88
- "Hello World!\n"
99
- call: stutter
1010
- "\n"

examples/hello/hello-parser-json.pdl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ text:
1313
- for:
1414
question: ${ data.questions }
1515
answer: ${ data.answers }
16-
repeat:
17-
- |
16+
repeat: |
1817
${ question }
1918
${ answer }
2019
- >

examples/rag/rag.pdl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ text:
3434
- for:
3535
prompt: ${ RETRIEVED.prompt }
3636
code: ${ RETRIEVED.code }
37-
repeat:
38-
- |
37+
repeat: |
3938

4039
Q: ${ prompt }
4140
A: ```${ code }```

examples/react/demo.pdl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ text:
6767
result = str(e)
6868
- "\n"
6969
else:
70-
- if: ${ action.name == "Calc" }
71-
then:
72-
text:
73-
- "\nObs: "
74-
- lang: python
75-
code: result = ${ action.arguments.expr }
76-
- "\n"
70+
if: ${ action.name == "Calc" }
71+
then:
72+
text:
73+
- "\nObs: "
74+
- lang: python
75+
code: result = ${ action.arguments.expr }
76+
- "\n"
7777
until: ${ action.name != "Search" }
7878

0 commit comments

Comments
 (0)