Skip to content

Commit 060f5ad

Browse files
authored
remove prompt library (#104)
Signed-off-by: Mandana Vaziri <[email protected]>
1 parent c608250 commit 060f5ad

20 files changed

+2
-1478
lines changed

README.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ The PDL interpreter (`pdl/pdl.py`) takes a PDL program as input and renders it i
2121

2222
See below for installation notes, followed by 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).
2323

24-
## Demo Video
25-
26-
https://github.com/user-attachments/assets/2629bf1e-bc54-4c45-b598-47914ab05a45
27-
2824

2925
## Interpreter Installation
3026

@@ -56,7 +52,7 @@ To run the interpreter:
5652
pdl-local <path/to/example.yaml>
5753
```
5854

59-
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, see [prompt-library](https://github.com/IBM/prompt-declaration-language/blob/main/examples/prompt_library) for a library of ready-to-use prompting patterns.
55+
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.
6056

6157
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.
6258

docs/README.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ The PDL interpreter (`pdl/pdl.py`) takes a PDL program as input and renders it i
2626

2727
See below for installation notes, followed by 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).
2828

29-
## Demo Video
30-
31-
<iframe src=https://github.com/user-attachments/assets/2629bf1e-bc54-4c45-b598-47914ab05a45 width="800" height="550" frameborder="0" allowfullscreen webkitallowfullscreen msallowfullscreen></iframe>
32-
3329

3430
## Interpreter Installation
3531

@@ -61,7 +57,7 @@ To run the interpreter:
6157
pdl-local <path/to/example.yaml>
6258
```
6359

64-
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, see [prompt-library](https://github.com/IBM/prompt-declaration-language/blob/main/examples/prompt_library) for a library of ready-to-use prompting patterns.
60+
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.
6561

6662
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.
6763

docs/tutorial.md

-225
Original file line numberDiff line numberDiff line change
@@ -739,231 +739,6 @@ The interpreter prints out a log by default in the file `log.txt`. This log cont
739739
To change the log filename, you can pass it to the interpreter as follows:
740740
741741
742-
## Prompt Library: ReAct, ReWOO, CoT, PoT
743-
744-
Some of the most common prompt patterns/techniques have been implemented as PDL functions. A demo of the ReAct template:
745-
746-
<iframe src=https://github.com/user-attachments/assets/2629bf1e-bc54-4c45-b598-47914ab05a45 width="800" height="550" frameborder="0" allowfullscreen webkitallowfullscreen msallowfullscreen></iframe>
747-
748-
### Chain of Thought (Wei et al., 2022)
749-
750-
The most simple pattern is CoT (Chain of Thought). An example for arithmetic reasoning:
751-
752-
```
753-
text:
754-
- include: examples/prompt_library/CoT.pdl
755-
- call: fewshot_cot
756-
args:
757-
examples:
758-
- question: |-
759-
Noah charges $60 for a large painting and $30 for a small painting.
760-
Last month he sold eight large paintings and four small paintings.
761-
If he sold twice as much this month, how much is his sales for this month?
762-
reasoning: |-
763-
He sold 8 large paintings and 4 small paintings last month.
764-
He sold twice as many this month.
765-
8 large paintings x $60 = << 8*60= 480 >> 480
766-
4 small paintings x $30 = << 4*30= 120 >> 120
767-
So he sold << 480+120= 600 >> 600 paintings last month.
768-
Therefore he sold << 600*2= 1200 >> this month.
769-
answer: $1200
770-
- question: |-
771-
Noah charges $30 for a large vases and $10 for a small vases.
772-
Last month he sold five large vases and three small vases.
773-
If he sold three times as much this month, how much is his sales for this month?
774-
reasoning: |-
775-
He sold 5 large vases and 3 small vases last month.
776-
He sold three times as many this month.
777-
5 large vases x $30 = << 5*30= 150 >> 150
778-
3 small vases x $10 = << 3*10= 30 >> 30
779-
So he sold << 150+30= 180 >> 180 vases last month.
780-
Therefore he sold << 180*3= 540 >> this month.
781-
answer: $540
782-
- |-
783-
Question: Bobby gave Alice 5 apples. Alice has 6 apples. How many apples did she have before?
784-
785-
Answer: Let's think step by step.
786-
- model: "ibm/granite-34b-code-instruct"
787-
platform: bam
788-
```
789-
790-
This simple template constructs fewshot examples, which should be followed by the query/question and a model call. The output up to the model call (and thus the input to the model) would look as follows:
791-
```
792-
Question: Noah charges $60 for a large painting and $30 for a small painting.
793-
Last month he sold eight large paintings and four small paintings.
794-
If he sold twice as much this month, how much is his sales for this month?
795-
796-
Answer: Let's think step by step. He sold 8 large paintings and 4 small paintings last month.
797-
He sold twice as many this month.
798-
8 large paintings x $60 = << 8*60= 480 >> 480
799-
4 small paintings x $30 = << 4*30= 120 >> 120
800-
So he sold << 480+120= 600 >> 600 paintings last month.
801-
Therefore he sold << 600*2= 1200 >> this month.
802-
The answer is $1200.
803-
804-
Question: Noah charges $30 for a large vases and $10 for a small vases.
805-
Last month he sold five large vases and three small vases.
806-
If he sold three times as much this month, how much is his sales for this month?
807-
808-
Answer: Let's think step by step. He sold 5 large vases and 3 small vases last month.
809-
He sold three times as many this month.
810-
5 large vases x $30 = << 5*30= 150 >> 150
811-
3 small vases x $10 = << 3*10= 30 >> 30
812-
So he sold << 150+30= 180 >> 180 vases last month.
813-
Therefore he sold << 180*3= 540 >> this month.
814-
The answer is $540.
815-
816-
Question: Bobby gave Alice 5 apples. Alice has 6 apples. How many apples did she have before?
817-
818-
Answer: Let's think step by step.
819-
```
820-
821-
### Program of Thought (Chen, 2022)
822-
823-
The PoT (Program of Thought) template includes the static fewshot prompt from (Chen, 2022). Essentially, the model is prompted to generate Python code to solve its problem, which is then executed.
824-
825-
```
826-
text:
827-
- include: examples/prompt_library/PoT.pdl
828-
- def: ANSWER
829-
call: program_of_thought
830-
args:
831-
question: Ketty saves 20000 dollars to the bank. After three years, the sum with compound interest rate is 1000 dollars more than the sum with simple interest rate. What is the interest rate of the bank?
832-
model: ibm/granite-34b-code-instruct
833-
- "\nAnswer: ${ ANSWER }"
834-
```
835-
836-
### ReAct (Yao, 2023)
837-
838-
The ReAct agent pattern is essentially a question, followed by a series of thoughts, actions, and observations, collectively called the trajectory. The input question is usually followed by a thought like `I need to search for x`. This is then followed by an action `Search[x]`, and the output of this tool cool is the observation. Finally, the agent ends the trajectory with the `Finish[answer]` action.
839-
840-
This pattern is provided by `examples/prompt_library/ReAct.pdl`. It describes the tools, renders their examples, renders any user provided trajectories (e.g., multiple tool use), and handles the core loop until `Finish` is reached.
841-
842-
The first building block is the `react_block` function. This function renders a trajectory, which consist of a list of single-item maps, into text. For example:
843-
844-
```
845-
text:
846-
- include: examples/prompt_library/ReAct.pdl
847-
- call: react_block
848-
args:
849-
trajectory:
850-
- question: "What is the elevation range for the area that the eastern sector of the Colorado orogeny extends into?"
851-
- thought: "I need to search Colorado orogeny, find the area that the eastern sector of the Colorado ..."
852-
- action: "Search[Colorado orogeny]"
853-
- observation: "The Colorado orogeny was an episode of mountain building (an orogeny) ..."
854-
- thought: "High Plains rise in elevation from around 1,800 to 7,000 ft, so the answer is 1,800 to 7,000 ft."
855-
- action: "Finish[1,800 to 7,000 ft]"
856-
```
857-
858-
Renders to:
859-
```
860-
Question: What is the elevation range for the area that the eastern sector of the Colorado orogeny extends into?
861-
Tho: I need to search Colorado orogeny, find the area that the eastern sector of the Colorado ...
862-
Act: Search[Colorado orogeny]
863-
Obs: The Colorado orogeny was an episode of mountain building (an orogeny) ...
864-
Tho: High Plains rise in elevation from around 1,800 to 7,000 ft, so the answer is 1,800 to 7,000 ft.
865-
Act: Finish[1,800 to 7,000 ft]
866-
```
867-
868-
To initiate a ReAct agent, the `react` function is used. For example:
869-
```
870-
text:
871-
- include: examples/prompt_library/ReAct.pdl
872-
- call: react
873-
args:
874-
question: "When did the Battle of White Plains take place?"
875-
model: meta-llama/llama-3-70b-instruct
876-
tools: ${ default_tools }
877-
trajectories: []
878-
```
879-
880-
The output of the `react` function is currently a JSON object with one key, `answer`, containing the final (`Finish[..]`) answer.
881-
882-
The `default_tools` variable is provided by the ReAct include. **Critically**, it currently only offers `Search` and `get_current_weather`. In most cases, one will want to define their own tools. Tools and their metadata must be defined, as the `react` function uses this information to describe tools to the model, and to execute model tool usage, if the action is included in the list of tool metadata. Tools are defined as follows:
883-
```
884-
Search:
885-
function:
886-
subject: str
887-
return:
888-
- "[Document]\n"
889-
- lan: python
890-
code: |
891-
import wikipedia
892-
try:
893-
result = wikipedia.summary(subject)
894-
except wikipedia.WikipediaException as e:
895-
result = str(e)
896-
- "[End]\n"
897-
898-
default_tools:
899-
data:
900-
- name: Search
901-
description: Search Wikipedia for a summary
902-
parameters:
903-
- name: query
904-
type: string
905-
description: The topic of interest
906-
examples:
907-
- - question: "What is the elevation range for the area that the eastern sector of the Colorado orogeny extends into?"
908-
- thought: "I need to search Colorado orogeny, find the area that the eastern sector of the Colorado ..."
909-
- action: "Search[Colorado orogeny]"
910-
- observation: "The Colorado orogeny was an episode of mountain building (an orogeny) ..."
911-
- thought: "High Plains rise in elevation from around 1,800 to 7,000 ft, so the answer is 1,800 to 7,000 ft."
912-
- action: "Finish[1,800 to 7,000 ft]"
913-
```
914-
915-
The tool `name` is the most important, as this must exactly match a defined PDL function. In this example, `Search` is defined right above the tool (metadata) definition. Note that all PDL tool functions in this template accept one parameter only, a string, which must be split by your function, if multiple parameters are expected. Next, the tool must be described, and its parameters defined. This is used to describe expected input(s) to the model. The parameters are a _list_, and include types and a description. Finally, a list of example trajectories should be defined to show the model how to use the tool. These trajectories follow the `react_block` pattern described above.
916-
917-
Finally, you can also add your own trajectories, for example to demonstrate use of multiple tools in one trajectory:
918-
```
919-
text:
920-
- include: examples/prompt_library/ReAct.pdl
921-
- call: react
922-
args:
923-
question: "When did the Battle of White Plains take place?"
924-
model: meta-llama/llama-3-70b-instruct
925-
tools: ${ default_tools }
926-
trajectories:
927-
- - question: "What is the minimum elevation for the area that the eastern sector of the Colorado orogeny extends into, in meters?"
928-
- thought: "I need to search Colorado orogeny, find the area that the eastern sector of the Colorado ..."
929-
- action: "Search[Colorado orogeny]"
930-
- observation: "The Colorado orogeny was an episode of mountain building (an orogeny) ..."
931-
- thought: "High Plains rise in elevation from around 1,800 to 7,000 ft, I need to convert this to meters."
932-
- action: "Calculator[1,800*0.3048]"
933-
- observation: "548.64"
934-
- thought: "The answer is 548.64 meters"
935-
- action: "Finish[548.64]"
936-
```
937-
938-
### ReWOO (Xu, 2023)
939-
940-
ReWOO (Reasoning without observation) is very similar to ReAct, but is faster and uses less tokens by having the model generate a trajectory where tool use can be _composed_ by variable reference. In practice, this means the model generates a trajectory in one generation, the PDL program parses this plan and executes tools as needed, and provides all the evidence (tool output) to the model in one request. This is in contrast to ReAct, where each step results in a whole new request to the model API.
941-
942-
The ReWOO function shares many similarities to the ReAct function described above. An example with a trajectory showing multiple tool use (note that these tools are not all actually defined):
943-
944-
```
945-
text:
946-
- include: examples/prompt_library/ReWOO.pdl
947-
- call: rewoo
948-
args:
949-
task: "When did the Battle of White Plains take place?"
950-
model: ibm/granite-34b-code-instruct
951-
tools: ${ default_tools }
952-
trajectories:
953-
- - question: Thomas, Toby, and Rebecca worked a total of 157 hours in one week. Thomas worked x hours. Toby worked 10 hours less than twice what Thomas worked, and Rebecca worked 8 hours less than Toby. How many hours did Rebecca work?
954-
- thought: Given Thomas worked x hours, translate the problem into algebraic expressions and solve with Wolfram Alpha.
955-
- action: WolframAlpha[Solve x + (2x - 10) + ((2x - 10) - 8) = 157]
956-
- thought: Find out the number of hours Thomas worked.
957-
- action: "LLM[What is x, given #E1]"
958-
- thought: Calculate the number of hours Rebecca worked.
959-
- action: "Calculator[(2 * #E2 - 10) - 8]"
960-
show_plans: true
961-
```
962-
963-
964-
The tool definitions are the same as for ReAct, and so are the trajectories. However, one difference is `show_plans`, which renders the parsed plans (e.g., the function calls), mostly as a debugging feature.
965-
966-
967742
## Live Document Visualizer
968743
969744
PDL has a Live Document visualizer to help in program understanding given an execution trace.

examples/gsm8k/math-patterns.pdl

-32
This file was deleted.

examples/prompt_library/CoT.pdl

-77
This file was deleted.

0 commit comments

Comments
 (0)