Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mandel committed Sep 9, 2024
1 parent 3f7f164 commit b416749
Show file tree
Hide file tree
Showing 34 changed files with 94 additions and 63 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ Notice that in PDL variables are used to templatize any entity in the document,
```yaml
description: Code explanation example
document:
- read: examples/code/data.yaml
- read: ./data.yaml
parser: yaml
def: CODE
show_result: False
Expand All @@ -248,7 +248,7 @@ document:
Explain the following code:
```
{{ CODE.source_code }}```
- read: examples/code/ground_truth.txt
- read: ./ground_truth.txt
def: TRUTH
show_result: False
- |
Expand Down Expand Up @@ -304,11 +304,11 @@ Finally, we can output JSON data as a result of this program, as follows:
```yaml
description: Code explanation example
document:
- read: examples/code/data.yaml
- read: ./data.yaml
parser: yaml
def: CODE
show_result: False
- read: examples/code/ground_truth.txt
- read: ./ground_truth.txt
def: TRUTH
show_result: False
- model: ibm/granite-34b-code-instruct
Expand Down
10 changes: 5 additions & 5 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ In PDL, this would be expressed as follows (see [file](https://github.com/IBM/pr
```yaml
description: Code explanation example
document:
- read: examples/code/data.json
- read: ./data.json
parser: json
def: CODE
show_result: False
Expand Down Expand Up @@ -212,11 +212,11 @@ Notice that in PDL variables are used to templatize any entity in the document,
```yaml
description: Code explanation example
document:
- read: examples/code/data.json
- read: ./data.json
parser: json
def: CODE
show_result: False
- read: examples/code/ground_truth.txt
- read: ./ground_truth.txt
def: TRUTH
show_result: False
- "\n{{ CODE.source_code }}\n"
Expand Down Expand Up @@ -289,11 +289,11 @@ Finally, we can output JSON data as a result of this program, as follows:
```yaml
description: Code explanation example
document:
- read: examples/code/data.json
- read: ./data.json
parser: json
def: CODE
show_result: False
- read: examples/code/ground_truth.txt
- read: ./ground_truth.txt
def: TRUTH
show_result: False
- model: ibm/granite-20b-code-instruct-v2
Expand Down
4 changes: 2 additions & 2 deletions examples/arith/Arith-simple.pdl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
description: Math Problems
document:
- read: examples/arith/example1.txt
- read: examples/arith/example2.txt
- read: ./example1.txt
- read: ./example2.txt
- "\n"
- |
Question: Noah charges $10 for a large box and $5 for a small box.
Expand Down
2 changes: 1 addition & 1 deletion examples/code/code-defs.pdl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
description: Code explanation example
defs:
CODE:
read: examples/code/data.yaml
read: ./data.yaml
parser: yaml
def: CODE
EXPLANATION:
Expand Down
4 changes: 2 additions & 2 deletions examples/code/code-eval.pdl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
description: Code explanation example
document:
- read: examples/code/data.yaml
- read: ./data.yaml
parser: yaml
def: CODE
show_result: False
Expand All @@ -18,7 +18,7 @@ document:
Explain the following code:
```
{{ CODE.source_code }}```
- read: examples/code/ground_truth.txt
- read: ./ground_truth.txt
def: TRUTH
show_result: False
- |
Expand Down
4 changes: 2 additions & 2 deletions examples/code/code-json.pdl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
description: Code explanation example
document:
- read: examples/code/data.yaml
- read: ./data.yaml
parser: yaml
def: CODE
show_result: False
- read: examples/code/ground_truth.txt
- read: ./ground_truth.txt
def: TRUTH
show_result: False
- model: ibm/granite-34b-code-instruct
Expand Down
2 changes: 1 addition & 1 deletion examples/code/code.pdl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
description: Code explanation example
document:
- read: examples/code/data.yaml
- read: ./data.yaml
parser: yaml
def: CODE
show_result: False
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/1-gen-data.pdl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
description: Creating JSON Data
defs:
data:
read: examples/demo/data.yaml
read: ./data.yaml
parser: yaml
spec: { questions: [str], answers: [obj] }
document:
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/2-teacher.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ defs:
document:
- "----- Loading seed examples -----\n\n"
- def: seed_examples
read: examples/teacher/qna.yaml
read: ./qna.yaml
parser: yaml
- "\n\n----- Generating questions -----\n\n"
- def: generated_questions
Expand Down
4 changes: 2 additions & 2 deletions examples/granite/multi_round_chat.pdl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
description: Granite Multi-Round Chat
document:
- include: examples/granite/granite_defs.pdl
- read: examples/granite/multi-prompts.json
- include: ./granite_defs.pdl
- read: ./multi-prompts.json
parser: json
def: prompts
spec: {prompts: [str]}
Expand Down
2 changes: 1 addition & 1 deletion examples/granite/single_round_chat.pdl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
description: Granite Single-Round Chat
document:
- include: examples/granite/granite_defs.pdl
- include: ./granite_defs.pdl
- |
{{ SYSTEM_CONTENT_CHAT }}
{{ USER_TAG }}
Expand Down
6 changes: 3 additions & 3 deletions examples/gsm8k/math-patterns.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ defs:
# cluster by similarity, or classify e.g. 5 classes that don't work

document:
- include: examples/prompt_library/ReWOO.pdl
- include: examples/prompt_library/ReAct.pdl
- include: examples/prompt_library/CoT.pdl
- include: ../prompt_library/ReWOO.pdl
- include: ../prompt_library/ReAct.pdl
- include: ../prompt_library/CoT.pdl
- def: filtered_tools
call: filter_tools_by_name
show_result: false
Expand Down
2 changes: 1 addition & 1 deletion examples/hello/hello-parser-json.pdl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
description: Creating JSON Data
defs:
data:
read: examples/hello/hello21_data.yaml
read: ./hello21_data.yaml
parser: yaml
spec: { "questions": ["str"], "answers": ["obj"] }
document:
Expand Down
2 changes: 1 addition & 1 deletion examples/input/input_test.pdl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
description: Hello world!
defs:
file: examples/input/data.tx
file: ./data.tx
document:
- read: "{{ file }}"
def: HELLO
Expand Down
2 changes: 1 addition & 1 deletion examples/prompt_library/demos/CoT.pdl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
description: Demo of CoT template
document:
- include: examples/prompt_library/CoT.pdl
- include: ../CoT.pdl
- call: fewshot_cot
args:
examples:
Expand Down
2 changes: 1 addition & 1 deletion examples/prompt_library/demos/PoT.pdl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
description: Demo of PoT template
document:
- include: examples/prompt_library/PoT.pdl
- include: ../PoT.pdl
- def: ANSWER
call: program_of_thought
args:
Expand Down
2 changes: 1 addition & 1 deletion examples/prompt_library/demos/RAG.pdl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
description: Demo of RAG template
document:
- include: examples/prompt_library/RAG.pdl
- include: ../RAG.pdl
- call: corpus
args:
corpus:
Expand Down
4 changes: 2 additions & 2 deletions examples/prompt_library/demos/ReAct.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ defs:
available_tools:
data: ["Search"]
document:
- include: examples/prompt_library/tools.pdl
- include: examples/prompt_library/ReAct.pdl
- include: ../tools.pdl
- include: ../ReAct.pdl
- def: filtered_tools
call: filter_tools_by_name
show_result: false
Expand Down
2 changes: 1 addition & 1 deletion examples/prompt_library/demos/ReWOO.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defs:
available_tools:
data: ["Search"]
document:
- include: examples/prompt_library/ReWOO.pdl
- include: ../ReWOO.pdl
# - def: filtered_tools
# call: filter_tools_by_name
# show_result: false
Expand Down
4 changes: 2 additions & 2 deletions examples/prompt_library/demos/Verifier.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ defs:
available_tools:
data: ["Search"]
document:
- include: examples/prompt_library/ReAct.pdl
- include: examples/granite/granite_defs.pdl
- include: ../ReAct.pdl
- include: ../../granite/granite_defs.pdl
- def: filtered_tools
call: filter_tools_by_name
show_result: false
Expand Down
6 changes: 3 additions & 3 deletions examples/prompt_library/demos/Verifier_json.pdl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
document:
- include: examples/prompt_library/tools.pdl
- include: examples/prompt_library/ReAct.pdl
- include: examples/granite/granite_defs.pdl
- include: ../tools.pdl
- include: ../ReAct.pdl
- include: ../../granite/granite_defs.pdl
- def: filtered_tools
call: filter_tools_by_name
show_result: false
Expand Down
2 changes: 1 addition & 1 deletion examples/prompt_library/demos/gsm8k/CoT.pdl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
description: Demo of CoT template
document:
- include: examples/prompt_library/CoT.pdl
- include: ../CoT.pdl
- call: chain_of_thought
args:
examples:
Expand Down
4 changes: 2 additions & 2 deletions examples/prompt_library/demos/gsm8k/ReAct.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ defs:
- thought: He sold $1200 this month.
- action: Finish[$1200]
document:
- include: examples/prompt_library/tools.pdl
- include: examples/prompt_library/ReAct.pdl
- include: ../tools.pdl
- include: ../ReAct.pdl
- call: react
args:
question: "Jake earns thrice what Jacob does. If Jacob earns $6 per hour, how much does Jake earn in 5 days working 8 hours a day?"
Expand Down
2 changes: 1 addition & 1 deletion examples/teacher/teacher.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ defs:
document:
- "----- Loading seed examples -----\n\n"
- def: seed_examples
read: examples/teacher/qna.yaml
read: ./qna.yaml
parser: yaml
- "\n\n----- Generating questions -----\n\n"
- def: generated_questions
Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial/conditionals_loops.pdl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
description: Arithmetic Expressions
document:
- read: examples/arith/example1.txt
- read: examples/arith/example2.txt
- read: ./example1.txt
- read: ./example2.txt
- repeat:
- "\nQuestion: "
- def: QUESTION
Expand Down
29 changes: 16 additions & 13 deletions examples/tutorial/data.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
questions:
- >
Question: Write a YAML object with 2 fields 'a' and 'b' of type int and set to 0.
- >
Question: Write a YAML object with 3 fields 'number' and 'street' and 'town' set to '10', 'Miller Road', 'Armonk' respectively.
answers:
- a: 0
b: 0

- number: 10
street: miller Road
town: armonk
source_code:
|
@SuppressWarnings("unchecked")
public static Map<String, String> deserializeOffsetMap(String lastSourceOffset) throws IOException {
Map<String, String> offsetMap;
if (lastSourceOffset == null || lastSourceOffset.isEmpty()) {
offsetMap = new HashMap<>();
} else {
offsetMap = JSON_MAPPER.readValue(lastSourceOffset, Map.class);
}
return offsetMap;
}
repo_info:
repo: streamsets/datacollector
path: stagesupport/src/main/java/com/.../OffsetUtil.java
function_name: OffsetUtil.deserializeOffsetMap
4 changes: 2 additions & 2 deletions examples/tutorial/data_block.pdl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
description: Code explanation example
document:
- read: examples/code/data.json
- read: ./data.json
parser: json
def: CODE
show_result: False
- read: examples/code/ground_truth.txt
- read: ./ground_truth.txt
def: TRUTH
show_result: False
- model: ibm/granite-20b-code-instruct-v2
Expand Down
13 changes: 13 additions & 0 deletions examples/tutorial/example1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Question: Noah charges $60 for a large painting and $30 for a small painting.
Last month he sold eight large paintings and four small paintings.
If he sold twice as much this month, how much is his sales for this month?

Answer: Let's think step by step.
He sold 8 large paintings and 4 small paintings last month.
He sold twice as many this month.
8 large paintings x $60 = << 8*60= 480 >> 480
4 small paintings x $30 = << 4*30= 120 >> 120
So he sold << 480+120= 600 >> 600 paintings last month.
Therefore he sold << 600*2= 1200 >> this month.
The answer is $1200.

12 changes: 12 additions & 0 deletions examples/tutorial/example2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Question: Noah charges $10 for a small vase and $30 for a large vases
Last month he sold five large vases and three small vases.
If he sold three times as much this month, how much is his sales for this month?

Answer: Let's think step by step.
He sold 5 large vases and 3 small vases last month.
He sold three times as many this month.
5 large vases x $30 = << 5*30= 150 >> 150
3 small vases x $10 = << 3*10= 30 >> 30
So he sold << 150+30= 180 >> 180 vases last month.
Therefore he sold << 180*3= 540 >> this month.
The answer is $540.
2 changes: 1 addition & 1 deletion examples/tutorial/gen-data.pdl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
description: Creating JSON Data
defs:
data:
read: examples/demo/data.yaml
read: ../demo/data.yaml
parser: yaml
spec: { questions: [str], answers: [obj] }
document:
Expand Down
3 changes: 3 additions & 0 deletions examples/tutorial/ground_truth.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The function `deserializeOffsetMap` takes a string as input and returns a map. It first checks if the input string is null or empty. If it is, it creates a new empty map and returns it. Otherwise, it uses the Jackson library to parse the input string into a map and returns it.

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.
2 changes: 1 addition & 1 deletion examples/tutorial/input_file.pdl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
description: PDL code with input block
document:
- read: examples/input/data.txt
- read: ./data.txt
def: HELLO
2 changes: 1 addition & 1 deletion examples/tutorial/input_file_json.pdl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
description: Input block example with json input
document:
- read: examples/tutorial/input.json
- read: ./input.json
parser: json
def: PERSON
show_result: false
Expand Down
Loading

0 comments on commit b416749

Please sign in to comment.