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: README.md
+30-16
Original file line number
Diff line number
Diff line change
@@ -2,16 +2,14 @@
2
2
3
3
LLMs will continue to change the way we build software systems. They are not only useful as coding assistants, providing snipets of code, explanations, and code transformations, but they can also help replace components that could only previously be achieved with rule-based systems. Whether LLMs are used as coding assistants or software components, reliability remains an important concern. LLMs have a textual interface and the structure of useful prompts is not captured formally. Programming frameworks do not enforce or validate such structures since they are not specified in a machine-consumable way. The purpose of the Prompt Declaration Language (PDL) is to allow developers to specify the structure of prompts and to enforce it, while providing a unified programming framework for composing LLMs with rule-based systems.
4
4
5
-
PDL is based on the premise that interactions between users, LLMs and rule-based systems form a *document*. Consider for example the interactions between a user and a chatbot. At each interaction, the exchanges form a document that gets longer and longer. Similarly, chaining models together or using tools for specific tasks result in outputs that together form a document. PDL allows users to specify the shape and contents of such documents in a declarative way (in YAML or JSON), and is agnostic of any programming language. Because of its document-oriented nature, it can be used to easily express a variety of data generation tasks (inference, data synthesis, data generation for model training, etc...). Moreover, PDL programs themselves are structured data (YAML) as opposed to traditional code, so they make good targets for LLM generation as well.
6
-
5
+
PDL is based on the premise that interactions between users, LLMs and rule-based systems form a *document*. Consider for example the interactions between a user and a chatbot. At each interaction, the exchanges form a document that gets longer and longer. Similarly, chaining models together or using tools for specific tasks result in outputs that together form a document. PDL allows users to specify the shape and contents of such documents in a declarative way (in YAML), and is agnostic of any programming language. Because of its document-oriented nature, it can be used to easily express a variety of data generation tasks (inference, data synthesis, data generation for model training, etc...).
7
6
8
7
PDL provides the following features:
9
8
- Ability to use any LLM locally or remotely via [LiteLLM](https://www.litellm.ai/), including [IBM's Watsonx](https://www.ibm.com/watsonx)
10
-
- Ability to templatize not only prompts for one LLM call, but also composition of LLMs with tools (code and APIs). Templates can encompass tasks of larger granularity than a single LLM call (unlike many prompt programming languages)
9
+
- Ability to templatize not only prompts for one LLM call, but also composition of LLMs with tools (code and APIs). Templates can encompass tasks of larger granularity than a single LLM call
11
10
- Control structures: variable definitions and use, conditionals, loops, functions
12
-
- Ability to read from files, including JSON data
13
-
- Ability to call out to code. At the moment only Python is supported, but this could be any other programming language in principle
14
-
- Ability to call out to REST APIs with Python code
11
+
- Ability to read from files and stdin, including JSON data
12
+
- Ability to call out to code and call REST APIs (Python)
15
13
- Type checking input and output of model calls
16
14
- Python SDK
17
15
- Support for chat APIs and chat templates
@@ -24,21 +22,21 @@ See below for installation notes, followed by an [overview](#overview) of the la
24
22
25
23
## Interpreter Installation
26
24
27
-
The interpreter has been tested with Python version **3.12**.
25
+
The interpreter has been tested with Python version **3.11 and 3.12**.
28
26
29
27
To install the requirements for `pdl`, execute the command:
30
28
31
29
```
32
-
pip3 install prompt-declaration-language
30
+
pip install prompt-declaration-language
33
31
```
34
32
35
33
To install the dependencies for development of PDL and execute all the example, execute the command:
In order to run the examples that use foundation models hosted on [Watsonx](https://www.ibm.com/watsonx) via LiteLLM, you need a WatsonX account (a free plan is available) and set up the following environment variables:
43
41
-`WATSONX_URL`, the API url (set to `https://{region}.ml.cloud.ibm.com`) of your WatsonX instance
44
42
-`WATSONX_APIKEY`, the API key (see information on [key creation](https://cloud.ibm.com/docs/account?topic=account-userapikey&interface=ui#create_user_key))
@@ -49,12 +47,28 @@ For more information, see [documentation](https://docs.litellm.ai/docs/providers
49
47
To run the interpreter:
50
48
51
49
```
52
-
pdl <path/to/example.yaml>
50
+
pdl <path/to/example.pdl>
53
51
```
54
52
55
53
The folder `examples` contains many examples of PDL programs. Several of these examples have been adapted from the LMQL [paper](https://arxiv.org/abs/2212.06094) by Beurer-Kellner et al. The examples cover a variety of prompting patterns such as CoT, RAG, ReAct, and tool use.
56
54
57
-
We highly recommend using VSCode to edit PDL YAML files. This project has been configured so that every YAML file is associated with the PDL grammar JSONSchema (see [settings](https://github.com/IBM/prompt-declaration-language/blob/main/.vscode/settings.json) and [schema](https://github.com/IBM/prompt-declaration-language/blob/main/pdl-schema.json)). This enables the editor to display error messages when the yaml deviates from the PDL syntax and grammar. It also provides code completion. You can set up your own VSCode PDL projects similarly using this settings and schema files. The PDL interpreter also provides similar error messages.
55
+
We highly recommend using VSCode to edit PDL YAML files. This project has been configured so that every YAML file is associated with the PDL grammar JSONSchema (see [settings](https://github.com/IBM/prompt-declaration-language/blob/main/.vscode/settings.json) and [schema](https://github.com/IBM/prompt-declaration-language/blob/main/pdl-schema.json)). This enables the editor to display error messages when the yaml deviates from the PDL syntax and grammar. It also provides code completion. You can set up your own VSCode PDL projects similarly using the following `./vscode/settings.json` file:
The interpreter executes Python code specified in PDL code blocks. To sandbox the interpreter for safe execution,
69
+
you can use the `--sandbox` flag which runs the interpreter in a docker container. Without this flag, the interpreter
70
+
and all code is executed locally. To use the `--sandbox` flag, you need to have a docker daemon running, such as
71
+
[Rancher Desktop](https://rancherdesktop.io).
58
72
59
73
The interpreter prints out a log by default in the file `log.txt`. This log contains the details of inputs and outputs to every block in the program. It is useful to examine this file when the program is behaving differently than expected. The log displays the exact prompts submitted to models by LiteLLM (after applying chat templates), which can be
60
74
useful for debugging.
@@ -233,7 +247,7 @@ The function `deserializeOffsetMap` takes a string as input and returns a map. I
233
247
The `@SuppressWarnings("unchecked")` annotation is used to suppress the warning that the type of the parsed map is not checked. This is because the Jackson library is used to parse the input string into a map, but the specific type of the map is not known at compile time. Therefore, the warning is suppressed to avoid potential issues.
234
248
```
235
249
236
-
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.yaml):
250
+
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):
237
251
238
252
```yaml
239
253
description: Code explanation example
@@ -368,7 +382,7 @@ PDL has a Live Document visualizer to help in program understanding given an exe
368
382
To produce an execution trace consumable by the Live Document, you can run the interpreter with the `--trace` argument:
369
383
370
384
```
371
-
pdl <my-example> --trace
385
+
pdl --trace <file.json> <my-example>
372
386
```
373
387
374
388
This produces an additional file named `my-example_trace.json` that can be uploaded to the [Live Document](https://ibm.github.io/prompt-declaration-language/viewer/) visualizer tool. Clicking on different parts of the Live Document will show the PDL code that produced that part
@@ -379,7 +393,7 @@ This is similar to a spreadsheet for tabular data, where data is in the forefron
379
393
380
394
## Additional Notes
381
395
382
-
When using Granite models on Watsonx, we use the following defaults for model parameters:
396
+
When using Granite models on Watsonx, we use the following defaults for model parameters (except `granite-20b-code-instruct-r1.1`):
Copy file name to clipboardexpand all lines: docs/README.md
+30-16
Original file line number
Diff line number
Diff line change
@@ -7,16 +7,14 @@ hide:
7
7
8
8
LLMs will continue to change the way we build software systems. They are not only useful as coding assistants, providing snipets of code, explanations, and code transformations, but they can also help replace components that could only previously be achieved with rule-based systems. Whether LLMs are used as coding assistants or software components, reliability remains an important concern. LLMs have a textual interface and the structure of useful prompts is not captured formally. Programming frameworks do not enforce or validate such structures since they are not specified in a machine-consumable way. The purpose of the Prompt Declaration Language (PDL) is to allow developers to specify the structure of prompts and to enforce it, while providing a unified programming framework for composing LLMs with rule-based systems.
9
9
10
-
PDL is based on the premise that interactions between users, LLMs and rule-based systems form a *document*. Consider for example the interactions between a user and a chatbot. At each interaction, the exchanges form a document that gets longer and longer. Similarly, chaining models together or using tools for specific tasks result in outputs that together form a document. PDL allows users to specify the shape and contents of such documents in a declarative way (in YAML or JSON), and is agnostic of any programming language. Because of its document-oriented nature, it can be used to easily express a variety of data generation tasks (inference, data synthesis, data generation for model training, etc...). Moreover, PDL programs themselves are structured data (YAML) as opposed to traditional code, so they make good targets for LLM generation as well.
11
-
10
+
PDL is based on the premise that interactions between users, LLMs and rule-based systems form a *document*. Consider for example the interactions between a user and a chatbot. At each interaction, the exchanges form a document that gets longer and longer. Similarly, chaining models together or using tools for specific tasks result in outputs that together form a document. PDL allows users to specify the shape and contents of such documents in a declarative way (in YAML), and is agnostic of any programming language. Because of its document-oriented nature, it can be used to easily express a variety of data generation tasks (inference, data synthesis, data generation for model training, etc...).
12
11
13
12
PDL provides the following features:
14
13
- Ability to use any LLM locally or remotely via [LiteLLM](https://www.litellm.ai/), including [IBM's Watsonx](https://www.ibm.com/watsonx)
15
-
- Ability to templatize not only prompts for one LLM call, but also composition of LLMs with tools (code and APIs). Templates can encompass tasks of larger granularity than a single LLM call (unlike many prompt programming languages)
14
+
- Ability to templatize not only prompts for one LLM call, but also composition of LLMs with tools (code and APIs). Templates can encompass tasks of larger granularity than a single LLM call
16
15
- Control structures: variable definitions and use, conditionals, loops, functions
17
-
- Ability to read from files, including JSON data
18
-
- Ability to call out to code. At the moment only Python is supported, but this could be any other programming language in principle
19
-
- Ability to call out to REST APIs with Python code
16
+
- Ability to read from files and stdin, including JSON data
17
+
- Ability to call out to code and call REST APIs (Python)
20
18
- Type checking input and output of model calls
21
19
- Python SDK
22
20
- Support for chat APIs and chat templates
@@ -29,21 +27,21 @@ See below for installation notes, followed by an [overview](#overview) of the la
29
27
30
28
## Interpreter Installation
31
29
32
-
The interpreter has been tested with Python version **3.12**.
30
+
The interpreter has been tested with Python version **3.11 and 3.12**.
33
31
34
32
To install the requirements for `pdl`, execute the command:
35
33
36
34
```
37
-
pip3 install prompt-declaration-language
35
+
pip install prompt-declaration-language
38
36
```
39
37
40
38
To install the dependencies for development of PDL and execute all the example, execute the command:
In order to run the examples that use foundation models hosted on [Watsonx](https://www.ibm.com/watsonx) via LiteLLM, you need a WatsonX account (a free plan is available) and set up the following environment variables:
48
46
-`WATSONX_URL`, the API url (set to `https://{region}.ml.cloud.ibm.com`) of your WatsonX instance
49
47
-`WATSONX_APIKEY`, the API key (see information on [key creation](https://cloud.ibm.com/docs/account?topic=account-userapikey&interface=ui#create_user_key))
@@ -54,12 +52,28 @@ For more information, see [documentation](https://docs.litellm.ai/docs/providers
54
52
To run the interpreter:
55
53
56
54
```
57
-
pdl <path/to/example.yaml>
55
+
pdl <path/to/example.pdl>
58
56
```
59
57
60
58
The folder `examples` contains many examples of PDL programs. Several of these examples have been adapted from the LMQL [paper](https://arxiv.org/abs/2212.06094) by Beurer-Kellner et al. The examples cover a variety of prompting patterns such as CoT, RAG, ReAct, and tool use.
61
59
62
-
We highly recommend using VSCode to edit PDL YAML files. This project has been configured so that every YAML file is associated with the PDL grammar JSONSchema (see [settings](https://github.com/IBM/prompt-declaration-language/blob/main/.vscode/settings.json) and [schema](https://github.com/IBM/prompt-declaration-language/blob/main/pdl-schema.json)). This enables the editor to display error messages when the yaml deviates from the PDL syntax and grammar. It also provides code completion. You can set up your own VSCode PDL projects similarly using this settings and schema files. The PDL interpreter also provides similar error messages.
60
+
We highly recommend using VSCode to edit PDL YAML files. This project has been configured so that every YAML file is associated with the PDL grammar JSONSchema (see [settings](https://github.com/IBM/prompt-declaration-language/blob/main/.vscode/settings.json) and [schema](https://github.com/IBM/prompt-declaration-language/blob/main/pdl-schema.json)). This enables the editor to display error messages when the yaml deviates from the PDL syntax and grammar. It also provides code completion. You can set up your own VSCode PDL projects similarly using the following `./vscode/settings.json` file:
The interpreter executes Python code specified in PDL code blocks. To sandbox the interpreter for safe execution,
74
+
you can use the `--sandbox` flag which runs the interpreter in a docker container. Without this flag, the interpreter
75
+
and all code is executed locally. To use the `--sandbox` flag, you need to have a docker daemon running, such as
76
+
[Rancher Desktop](https://rancherdesktop.io).
63
77
64
78
The interpreter prints out a log by default in the file `log.txt`. This log contains the details of inputs and outputs to every block in the program. It is useful to examine this file when the program is behaving differently than expected. The log displays the exact prompts submitted to models by LiteLLM (after applying chat templates), which can be
65
79
useful for debugging.
@@ -238,7 +252,7 @@ The function `deserializeOffsetMap` takes a string as input and returns a map. I
238
252
The `@SuppressWarnings("unchecked")` annotation is used to suppress the warning that the type of the parsed map is not checked. This is because the Jackson library is used to parse the input string into a map, but the specific type of the map is not known at compile time. Therefore, the warning is suppressed to avoid potential issues.
239
253
```
240
254
241
-
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.yaml):
255
+
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):
242
256
243
257
```yaml
244
258
description: Code explanation example
@@ -373,7 +387,7 @@ PDL has a Live Document visualizer to help in program understanding given an exe
373
387
To produce an execution trace consumable by the Live Document, you can run the interpreter with the `--trace` argument:
374
388
375
389
```
376
-
pdl <my-example> --trace
390
+
pdl --trace <file.json> <my-example>
377
391
```
378
392
379
393
This produces an additional file named `my-example_trace.json` that can be uploaded to the [Live Document](https://ibm.github.io/prompt-declaration-language/viewer/) visualizer tool. Clicking on different parts of the Live Document will show the PDL code that produced that part
@@ -384,7 +398,7 @@ This is similar to a spreadsheet for tabular data, where data is in the forefron
384
398
385
399
## Additional Notes
386
400
387
-
When using Granite models on Watsonx, we use the following defaults for model parameters:
401
+
When using Granite models on Watsonx, we use the following defaults for model parameters (except `granite-20b-code-instruct-r1.1`):
0 commit comments