Skip to content

Commit 64fa446

Browse files
committed
feat: rename join into reduce
Signed-off-by: Louis Mandel <[email protected]>
1 parent f48046b commit 64fa446

33 files changed

+151
-133
lines changed

contrib/prompt_library/CoT.pdl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ defs:
2424
question: ${ example.question }
2525
reasoning: ${ example.reasoning }
2626
answer: ${ example.answer }
27-
join:
27+
reduce:
2828
with: "\n\n"
2929

3030
chain_of_thought:

docs/tutorial.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ and asking `why not?` if the answer (stored in variable `eval`) is `no`. The loo
771771
Notice that the `repeat` and `then` blocks are followed by `text`. This is because of the semantics of lists in PDL. If we want to aggregate the result by stringifying every element in the list and collating them together, then we need the keyword `text` to precede a list. The number of iterations of a loop can be bounded by adding a `maxIterations` field.
772772

773773
The way that the result of each iteration is collated with other iterations can be customized in PDL using
774-
the `join` feature (see the following section).
774+
the `reduce` feature (see the following section).
775775

776776
Another simple example of using an `if` statement is [this](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/if.pdl).
777777

@@ -827,18 +827,18 @@ which outputs:
827827
4
828828
```
829829

830-
When `join` is not specified, the collation defaults to
830+
When `reduce` is not specified, the collation defaults to
831831

832832
```
833-
join:
833+
reduce:
834834
as: text
835835
with: ""
836836
```
837837

838838
meaning that result of each iteration is stringified and concatenated with that of other iterations. When using `with`,
839839
`as: text` can be elided.
840840

841-
Note that `join` can be added to any looping construct (`repeat`) not just `for` loops.
841+
Note that `reduce` can be added to any looping construct (`repeat`) not just `for` loops.
842842

843843
The `for` loop construct also allows iterating over 2 or more lists of the same length simultaneously:
844844

examples/demo/10-sdg.pdl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ defs:
8080
icl_question: ${icl_question}
8181
icl_answer: ${icl_answer}
8282
question: ${question}
83-
join:
83+
reduce:
8484
as: array
8585

8686
gen_questions_freeform:
@@ -100,7 +100,7 @@ defs:
100100
task_description: ${task_description}
101101
icl_question: ${example.question}
102102
icl_answer: ${example.answer}
103-
join:
103+
reduce:
104104
as: array
105105
lang: python
106106
code: | # flatten list_of_lists into simple list
@@ -186,7 +186,7 @@ defs:
186186
data:
187187
question: ${question}
188188
keep: ${filter_output}
189-
join:
189+
reduce:
190190
as: array
191191
filtered:
192192
lang: python
@@ -281,7 +281,7 @@ defs:
281281
call: ${gen_answers_inner}
282282
args:
283283
question: ${question}
284-
join:
284+
reduce:
285285
as: array
286286
lang: python
287287
spec: [{question: string, answer: string}]
@@ -368,7 +368,7 @@ defs:
368368
data:
369369
qa_pair: ${qa_pair}
370370
rating: ${filter_output}
371-
join:
371+
reduce:
372372
as: array
373373
filtered:
374374
lang: python

examples/demo/11-repeat.pdl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ repeat:
1313
- data:
1414
name: ${ name }
1515
number: ${ number }
16-
join:
16+
reduce:
1717
with: "\n"

examples/demo/7-chatbot-roles.pdl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ text:
1313
- model: ollama_chat/granite3.2:2b
1414
- "\n\n"
1515
until: ${ query == 'quit'}
16-
join:
16+
reduce:
1717
with: "\n\n"
1818
role: user

examples/demos/granite_io_hallucinations.pdl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ text:
5858
text:
5959
- "Hallucination Risk: ${ hallucination.risk }"
6060
- "\nSentence: ${ hallucination.response_text }"
61-
join:
61+
reduce:
6262
with: "\n"

examples/granite-io/granite_io_hallucinations.pdl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ text:
5858
text:
5959
- "Hallucination Risk: ${ hallucination.risk }"
6060
- "\nSentence: ${ hallucination.response_text }"
61-
join:
61+
reduce:
6262
with: "\n"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
defs:
2+
proc:
3+
lang: python
4+
code: |
5+
from granite_io_pdl.sequential_scaling import SequentialScalingInputOutputProcessor
6+
from granite_io.io.base import ChatCompletionInputs
7+
from granite_io.types import ChatCompletionResults
8+
import random
9+
10+
def validator(results: ChatCompletionResults):
11+
b = random.choice([True, False])
12+
print(f"======> {b}")
13+
return b
14+
15+
result = SequentialScalingInputOutputProcessor(model="granite3.2:2b", backend="openai", validator=validator)
16+
text:
17+
- |
18+
How to write a Rust program that reverse a list?
19+
- processor: ${ proc }

examples/gsm8k/gsm8.pdl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ text:
3535
input: |
3636
Question: ${ TEST.question }
3737
Answer:
38-
join:
38+
reduce:
3939
as: array
4040
contribute: []
4141
def: ALL_LLM_FULL_A
@@ -56,7 +56,7 @@ text:
5656
input: | # 'input' is the prompt
5757
Generate the final answer from the conclusion of this text as JSON with a single key named answer.
5858
${ LLM_FULL_ANSWER }
59-
join:
59+
reduce:
6060
as: array
6161
contribute: []
6262
def: SIMPLIFIED_LLM_ANSWERS

examples/gsm8k/gsm8k-plan-few-shots.pdl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ defs:
2222
demo: ${ demos }
2323
repeat:
2424
${ demo }
25-
join:
25+
reduce:
2626
with: "\n"
2727
- text:
2828
- "\nProblem:\n"
@@ -91,7 +91,7 @@ text:
9191
demos: ${ demos }
9292
maxIterations: ${ MAX_ITERATIONS }
9393
def: plans
94-
join:
94+
reduce:
9595
as: array
9696

9797
- for:
@@ -103,7 +103,7 @@ text:
103103
plan: ${ plan }
104104
maxIterations: ${ MAX_ITERATIONS }
105105
def: solutions
106-
join:
106+
reduce:
107107
as: array
108108

109109
- for:
@@ -115,7 +115,7 @@ text:
115115
solution: ${ solution }
116116
maxIterations: ${ MAX_ITERATIONS }
117117
def: results
118-
join:
118+
reduce:
119119
as: array
120120

121121
- for:
@@ -129,7 +129,7 @@ text:
129129
truth: ${ problem.answer }
130130
maxIterations: ${ MAX_ITERATIONS }
131131
def: stats
132-
join:
132+
reduce:
133133
as: array
134134

135135
- "\nAccuracy: ${ stats|sum / MAX_ITERATIONS * 100}% "

0 commit comments

Comments
 (0)