You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/tutorial.md
+39-37
Original file line number
Diff line number
Diff line change
@@ -480,7 +480,6 @@ text:
480
480
parameters:
481
481
decoding_method: sample
482
482
max_new_tokens: 512
483
-
as: text
484
483
role: user
485
484
```
486
485
@@ -557,13 +556,11 @@ text:
557
556
code: result = ${ EXPR }
558
557
- ' >>'
559
558
until: ${ "The answer is" in REASON_OR_CALC }
560
-
as: text
561
559
- "\n\n"
562
-
as: text
563
560
num_iterations: 3
564
561
```
565
562
566
-
The first two blocks read math problem examples and include them in the document. These will be our few-shot examples. The next block is a repetion as indicated by the fields: `repeat` and the accompanying `num_iterations`. The field `repeat` can contain any document (string or block or list of strings and blocks), the `num_iterations` indicates how many times to repeat.
563
+
The first two blocks read math problem examples and include them in the document. These will be our few-shot examples. The next block is a repetition as indicated by the fields: `repeat` and the accompanying `num_iterations`. The field `repeat` can contain any document (string or block or list of strings and blocks), the `num_iterations` indicates how many times to repeat.
567
564
568
565
In the body of the `repeat` block, the program first asks granite to generate a question and add it to the document. Next we print `Answer: Let's think step by step.\n`. The following block is a repeat-until: the text in `repeat` is repeated until the condition in the `until` field becomes true. Here the condition states that we stop the iteration when variable `REASON_OR_CALC` contains `<<`. That variable is defined in the first block of the repeat-until -- we prompt a granite model and stop at the character `<<`.
569
566
@@ -578,66 +575,72 @@ Similarly, the `read` block has an annotation `as: text`. This means that the re
578
575
## For Loops
579
576
580
577
PDL also offers `for` loops over lists.
581
-
The following [example](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/for.pdl) creates a list as a result of iteration.
578
+
The following [example](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/for.pdl) stringifies and outputs each number.
582
579
583
580
```
584
581
description: for loop
585
-
text:
586
-
- for:
587
-
i: [1, 2, 3, 4]
588
-
repeat:
589
-
${ i }
582
+
for:
583
+
i: [1, 2, 3, 4]
584
+
repeat:
585
+
${ i }
590
586
```
591
587
592
-
This program outputs the following list:
588
+
This program outputs:
593
589
```
594
-
[1, 2, 3, 4]
590
+
1234
595
591
```
596
592
597
-
To stringify and output each number on a line, we would write:
593
+
To output a number of each line, we can specify which string to use to join the results.
598
594
```
599
595
description: for loop
600
-
text:
601
-
- for:
602
-
i: [1, 2, 3, 4]
603
-
repeat:
604
-
text:
605
-
- ${ i }
606
-
- "\n"
607
-
as: text
596
+
for:
597
+
i: [1, 2, 3, 4]
598
+
repeat:
599
+
${ i }
600
+
join:
601
+
with: "\n"
608
602
```
609
603
610
-
which outputs:
611
-
612
604
```
613
605
1
614
606
2
615
607
3
616
608
4
609
+
```
610
+
617
611
612
+
To creates an array as a result of iteration, we would write:
613
+
```
614
+
description: for loop
615
+
for:
616
+
i: [1, 2, 3, 4]
617
+
repeat:
618
+
- ${ i }
619
+
join:
620
+
as: array
618
621
```
619
622
623
+
which outputs the following list:
624
+
```
625
+
[1, 2, 3, 4]
626
+
```
627
+
628
+
620
629
621
630
The `for` loop constructs also allows iterating over 2 or more lists of the same length simultaneously:
622
631
623
632
```
624
633
description: for loop
625
634
defs:
626
-
numbers: {
635
+
numbers:
627
636
data: [1, 2, 3, 4]
628
-
}
629
-
names: {
637
+
names:
630
638
data: ["Bob", "Carol", "David", "Ernest"]
631
-
}
632
-
633
-
text:
634
-
- for:
635
-
number: ${ numbers }
636
-
name: ${ names }
637
-
repeat:
638
-
text:
639
-
"${ name }'s number is ${ number }\n"
640
-
as: text
639
+
for:
640
+
number: ${ numbers }
641
+
name: ${ names }
642
+
repeat:
643
+
"${ name }'s number is ${ number }\n"
641
644
```
642
645
643
646
This results in the following output:
@@ -675,7 +678,6 @@ text:
675
678
- |
676
679
${ question }
677
680
${ answer }
678
-
as: text
679
681
- >
680
682
Question: Create a JSON object with fields 'name' and 'age'
681
683
and set them appropriately. Write the age in letters.
0 commit comments