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
@@ -23,7 +23,7 @@ PDL provides the following features:
23
23
24
24
The PDL interpreter takes a PDL program as input and generates data by executing its instructions (calling out to models, code, etc...).
25
25
26
-
See below for a quick reference, followed by [installation notes](#interpreter_installation) and an [overview](#overview) of the language. A more detailed description of the language features can be found in this [tutorial](https://ibm.github.io/prompt-declaration-language/tutorial).
26
+
See below for a quick reference, followed by [installation notes](#interpreter-installation) and an [overview](#overview) of the language. A more detailed description of the language features can be found in this [tutorial](https://ibm.github.io/prompt-declaration-language/tutorial).
27
27
28
28
29
29
## Quick Reference
@@ -194,7 +194,7 @@ The same example on Replicate:
@@ -215,24 +215,9 @@ See the [tutorial](https://ibm.github.io/prompt-declaration-language/tutorial) f
215
215
Consider now an example from AI for code, where we want to build a prompt template for code explanation. We have a JSON file as input
216
216
containing the source code and some information regarding the repository where it came from.
217
217
218
-
For example, given the data in this JSON [file](https://github.com/IBM/prompt-declaration-language/blob/main/examples/code/data.yaml):
218
+
For example, given the data in this JSON [file](https://github.com/IBM/prompt-declaration-language/blob/main/examples/examples/tutorial/programs/code/data.yaml):
219
219
```yaml
220
-
source_code:
221
-
|
222
-
@SuppressWarnings("unchecked")
223
-
public static Map<String, String> deserializeOffsetMap(String lastSourceOffset) throws IOException {
224
-
Map<String, String> offsetMap;
225
-
if (lastSourceOffset == null || lastSourceOffset.isEmpty()) {
we would like to express the following prompt and submit it to an LLM:
@@ -259,28 +244,10 @@ public static Map<String, String> deserializeOffsetMap(String lastSourceOffset)
259
244
}
260
245
```
261
246
262
-
In PDL, this would be expressed as follows (see [file](https://github.com/IBM/prompt-declaration-language/blob/main/examples/code/code.pdl)):
247
+
In PDL, this would be expressed as follows (see [file](https://github.com/IBM/prompt-declaration-language/blob/main/examples/tutorial/programs/code/code.pdl)):
263
248
264
249
```yaml
265
-
description: Code explanation example
266
-
defs:
267
-
CODE:
268
-
read: ./data.yaml
269
-
parser: yaml
270
-
text:
271
-
- "\n${ CODE.source_code }\n"
272
-
- model: ollama/granite-code:8b
273
-
input: |
274
-
Here is some info about the location of the function in the repo.
In this program we first define some variables using the `defs` construct. Here `CODE` is defined to be a new variable, holding the result of the `read` block that follows.
@@ -310,48 +277,10 @@ public static Map<String, String> deserializeOffsetMap(String lastSourceOffset)
310
277
The code is a Java method that takes a string `lastSourceOffset` as input and returns a `Map<String, String>`. The method uses the Jackson library to deserialize the JSON-formatted string into a map. If the input string is null or empty, an empty HashMap is returned. Otherwise, the string is deserialized into a Map using the `JSON_MAPPER.readValue()` method.
311
278
```
312
279
313
-
Notice that in PDL variables are used to templatize any entity in the document, not just textual prompts to LLMs. We can add a block to this document to evaluate the quality of the output using a similarity metric with respect to our [ground truth](https://github.com/IBM/prompt-declaration-language/blob/main/examples/code/ground_truth.txt). See [file](https://github.com/IBM/prompt-declaration-language/blob/main/examples/code/code-eval.pdl):
280
+
Notice that in PDL variables are used to templatize any entity in the document, not just textual prompts to LLMs. We can add a block to this document to evaluate the quality of the output using a similarity metric with respect to our [ground truth](https://github.com/IBM/prompt-declaration-language/blob/main/examples/tutorial/programs/code/ground_truth.txt). See [file](https://github.com/IBM/prompt-declaration-language/blob/main/examples/tutorial/programs/code/code-eval.pdl):
314
281
315
282
```yaml
316
-
description: Code explanation example
317
-
defs:
318
-
CODE:
319
-
read: ./data.yaml
320
-
parser: yaml
321
-
TRUTH:
322
-
read: ./ground_truth.txt
323
-
text:
324
-
- "\n${ CODE.source_code }\n"
325
-
- model: ollama/granite-code:8b
326
-
def: EXPLANATION
327
-
input: |
328
-
Here is some info about the location of the function in the repo.
329
-
repo:
330
-
${ CODE.repo_info.repo }
331
-
path: ${ CODE.repo_info.path }
332
-
Function_name: ${ CODE.repo_info.function_name }
333
-
334
-
335
-
Explain the following code:
336
-
```
337
-
${ CODE.source_code }```
338
-
- |
339
-
340
-
341
-
EVALUATION:
342
-
The similarity (Levenshtein) between this answer and the ground truth is:
343
-
- def: EVAL
344
-
lang: python
345
-
code: |
346
-
import textdistance
347
-
expl = """
348
-
${ EXPLANATION }
349
-
"""
350
-
truth = """
351
-
${ TRUTH }
352
-
"""
353
-
# (In PDL, set `result` to the output you wish for your code block.)
354
-
result = textdistance.levenshtein.normalized_similarity(expl, truth)
This program has an input block that reads the ground truth from filename `examples/code/ground_truth.txt` and assigns its contents to variable `TRUTH`. It also assigns the output of the model to the variable `EXPLANATION`, using a `def` construct. In PDL, any block can have a `def` to capture the result of that block in a variable. The last block is a call to Python code, which is included after the `code` field. Notice how code is included here simply as data. We collate fragments of Python with outputs obtained from previous blocks. This is one of the powerful features of PDL: the ability to specify the execution of code that is not known ahead of time. We can use LLMs to generate code that is later executed in the same programming model. This is made possible because PDL treats code as data, like any another part of the document.
@@ -385,55 +314,10 @@ PDL allows rapid prototyping of prompts by allowing the user to change prompts a
385
314
Finally, we can output JSON data as a result of this program, as follows:
386
315
387
316
```yaml
388
-
description: Code explanation example
389
-
defs:
390
-
CODE:
391
-
read: ./data.yaml
392
-
parser: yaml
393
-
TRUTH:
394
-
read: ./ground_truth.txt
395
-
text:
396
-
- model: ollama/granite-code:8b
397
-
def: EXPLANATION
398
-
contribute: []
399
-
input:
400
-
|
401
-
Here is some info about the location of the function in the repo.
402
-
repo:
403
-
${ CODE.repo_info.repo }
404
-
path: ${ CODE.repo_info.path }
405
-
Function_name: ${ CODE.repo_info.function_name }
406
-
407
-
408
-
Explain the following code:
409
-
```
410
-
${ CODE.source_code }```
411
-
parameters:
412
-
temperature: 0
413
-
- def: EVAL
414
-
contribute: []
415
-
lang: python
416
-
code:
417
-
|
418
-
import textdistance
419
-
expl = """
420
-
${ EXPLANATION }
421
-
"""
422
-
truth = """
423
-
${ TRUTH }
424
-
"""
425
-
# (In PDL, set `result` to the output you wish for your code block.)
426
-
result = textdistance.levenshtein.normalized_similarity(expl, truth)
427
-
- data:
428
-
input: ${ CODE }
429
-
output: ${ EXPLANATION }
430
-
metric: ${ EVAL }
431
-
432
-
```
433
-
434
-
The data block takes various variables and combines their values into a JSON object with fields `input`, `output`, and `metric`. We mute the output of all the other blocks with `contribute` set to `[]`. The `contribute` construct can be used to specify how the result of a block is contributed to the background context.
435
-
Setting it to `[]` means no contribution is made from this block to the background context. By default, the result of every block is contributed to the context. For the blocks in the program above, we use a `def` construct to save the intermediate result of each block.
The data block takes various variables and combines their values into a JSON object with fields `input`, `output`, and `metric`.
437
321
The output of this program is the corresponding serialized JSON object, with the appropriate treatment of quotation marks. Similarly PDL can read jsonl files and create jsonl files by piping to a file.
Copy file name to clipboardExpand all lines: docs/tutorial.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -374,10 +374,10 @@ In this program, we first define a query about the weather in some location (ass
374
374
375
375
## Data Block
376
376
377
-
PDL offers the ability to create JSON data as illustrated by the following example (described in detail in the [Overview](https://ibm.github.io/prompt-declaration-language/#overview) section). The `data` block can gather previously defined variables into a JSON structure. This feature is useful for data generation. Programs such as this one can be generalized to read jsonl files to generate data en masse by piping into another jsonl file ([file](https://github.com/IBM/prompt-declaration-language/blob/main/examples/tutorial/programs/code-json.pdl)).
377
+
PDL offers the ability to create JSON data as illustrated by the following example (described in detail in the [Overview](https://ibm.github.io/prompt-declaration-language/#overview) section). The `data` block can gather previously defined variables into a JSON structure. This feature is useful for data generation. Programs such as this one can be generalized to read jsonl files to generate data en masse by piping into another jsonl file ([file](https://github.com/IBM/prompt-declaration-language/blob/main/examples/tutorial/programs/code/code-json.pdl)).
Notice that in the `data` block the values are interpreted as Jinja expressions. If values need to be PDL programs to be interpreted, then you need to use
0 commit comments