Skip to content

Commit ceb2f52

Browse files
authored
Merge pull request #259 from esnible/example-comments
Add comments to examples to make them more obvious
2 parents 2cc85da + 7235368 commit ceb2f52

16 files changed

+47
-13
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ text:
148148
lang: python
149149
code: |
150150
import random
151+
# (In PDL, set `result` to the output you wish for your code block.)
151152
result = random.randint(1, 20)
152153
- "\nthe result is (${ N })\n"
153154
```

docs/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ text:
326326
truth = """
327327
${ TRUTH }
328328
"""
329+
# (In PDL, set `result` to the output you wish for your code block.)
329330
result = textdistance.levenshtein.normalized_similarity(expl, truth)
330331
331332
```
@@ -406,6 +407,7 @@ text:
406407
truth = """
407408
${ TRUTH }
408409
"""
410+
# (In PDL, set `result` to the output you wish for your code block.)
409411
result = textdistance.levenshtein.normalized_similarity(expl, truth)
410412
- data:
411413
input: ${ CODE }

docs/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Yes, I did. How can I assist you today?
135135
## Function Definition
136136

137137
PDL also supports function definitions to make it easier to reuse code.
138-
Suppose we want to define a translation function that takes a string and calls a falcon model for the translation. This would be written in PDL as follows ([file](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/function_definition.pdl)):
138+
Suppose we want to define a translation function that takes a string and calls a Granite model for the translation. This would be written in PDL as follows ([file](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/function_definition.pdl)):
139139

140140

141141
```yaml

examples/callback/repair_prompt.pdl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ lastOf:
1919
spec: {thought: str, code_line: str}
2020
code: |
2121
import repair_main
22+
# (In PDL, set `result` to the output you wish for your code block.)
2223
result = repair_main.parse_output(raw_output)
2324

2425
- spec: {before: str, after: str}

examples/chatbot/chatbot.pdl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
description: chatbot
22
text:
3+
# Allow the user to type any question, implicitly adding the question to the context.
34
- read:
45
message: "What is your query?\n"
5-
contribute: [context]
66
- repeat:
77
text:
8+
# Send context to Granite model hosted at replicate.com
89
- model: replicate/ibm-granite/granite-3.0-8b-instruct
10+
# Allow the user to type 'yes', 'no', or anything else, storing
11+
# the input into a variable named `eval`. The input is also implicitly
12+
# added to the context.
913
- read:
1014
def: eval
1115
message: "\nIs this a good answer[yes/no]?\n"
12-
contribute: [context]
16+
- "\n"
17+
# If the user only typed "no", prompt the user for input to add to the context.
1318
- if: ${ eval == 'no' }
1419
then:
1520
text:
1621
- read:
1722
message: "Why not?\n"
18-
contribute: []
23+
# If the user typed only "yes", finish the `repeat` and end the program
1924
until: ${ eval == 'yes'}
20-
21-
22-

examples/code/code-eval.pdl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
description: Code explanation example
22
defs:
3+
# The variable `CODE` shall be the contents of the parsed YAML file
34
CODE:
45
read: ./data.yaml
56
parser: yaml
7+
# The variable `TRUTH` shall be the text of the file
68
TRUTH:
79
read: ./ground_truth.txt
810
text:
11+
# Print the source code to the console
912
- "\n${ CODE.source_code }\n"
13+
# Use replicate.com to invoke a Granite model with a prompt. Output AND
14+
# set the variable `EXPLANATION` to the output.
1015
- model: replicate/ibm-granite/granite-3.0-8b-instruct
1116
def: EXPLANATION
1217
input: |
@@ -21,14 +26,17 @@ text:
2126
```
2227
${ CODE.source_code }```
2328
parameters:
29+
# Use no LLM creativity. (Note that 0 is the default; this line has no effect)
2430
temperature: 0
2531
- |
2632

2733

2834
EVALUATION:
2935
The similarity (Levenshtein) between this answer and the ground truth is:
36+
# We aren't only defining `EVAL`, we are also executing it.
3037
- def: EVAL
3138
lang: python
39+
# (Use `pip install textdistance` if needed to install the textdistance package)
3240
code: |
3341
import textdistance
3442
expl = """
@@ -37,4 +45,5 @@ text:
3745
truth = """
3846
${ TRUTH }
3947
"""
48+
# (In PDL, set `result` to the output you wish for your code block.)
4049
result = textdistance.levenshtein.normalized_similarity(expl, truth)

examples/code/code-json.pdl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ text:
3535
truth = """
3636
${ TRUTH }
3737
"""
38+
# (In PDL, set `result` to the output you wish for your code block.)
3839
result = textdistance.levenshtein.normalized_similarity(expl, truth)
3940
- data:
4041
input: ${ CODE }

examples/code/code.pdl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
description: Code explanation example
22
defs:
3+
# Read data.yaml as YAML and store it in a variable `CODE`
34
CODE:
45
read: ./data.yaml
56
parser: yaml
67
text:
8+
# Output the `source_code:` of the YAML to the console
79
- "\n${ CODE.source_code }\n"
10+
# Use replicate.com to invoke a Granite model with a prompt
811
- model: replicate/ibm-granite/granite-3.0-8b-instruct
912
input: |
1013
Here is some info about the location of the function in the repo.
@@ -18,4 +21,5 @@ text:
1821
```
1922
${ CODE.source_code }```
2023
parameters:
24+
# Use no LLM creativity. (Note that 0 is the default; this line has no effect)
2125
temperature: 0

examples/fibonacci/fib.pdl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
description: Fibonacci
44

55
text:
6-
# Use IBM Granite to author a program that computes the Nth Fibonacci number
6+
# Use IBM Granite to author a program that computes the Nth Fibonacci number,
7+
# storing the generated program into the variable `CODE`.
78
- def: CODE
89
model: replicate/ibm-granite/granite-3.0-8b-instruct
910
input: "Write a Python function to compute the Fibonacci sequence. Do not include a doc string.\n\n"
@@ -17,6 +18,7 @@ text:
1718
lang: python
1819
code: |
1920
import random
21+
# (In PDL, set `result` to the output you wish for your code block.)
2022
result = random.randint(1, 20)
2123

2224
- "\nNow computing fibonacci(${ N })\n"

examples/granite/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ pdl -f ./prompt.json single_round_chat.pdl
55
```
66

77
```
8-
pdl -f ./multi-prompts.json multi_round_chat.pdl
8+
pdl multi_round_chat.pdl
99
```

0 commit comments

Comments
 (0)