From b41674980d802eeafdbd2ac232713b0622644451 Mon Sep 17 00:00:00 2001 From: Louis Mandel Date: Mon, 9 Sep 2024 16:37:31 -0400 Subject: [PATCH] Update examples --- README.md | 8 ++--- docs/README.md | 10 +++---- examples/arith/Arith-simple.pdl | 4 +-- examples/code/code-defs.pdl | 2 +- examples/code/code-eval.pdl | 4 +-- examples/code/code-json.pdl | 4 +-- examples/code/code.pdl | 2 +- examples/demo/1-gen-data.pdl | 2 +- examples/demo/2-teacher.pdl | 2 +- examples/granite/multi_round_chat.pdl | 4 +-- examples/granite/single_round_chat.pdl | 2 +- examples/gsm8k/math-patterns.pdl | 6 ++-- examples/hello/hello-parser-json.pdl | 2 +- examples/input/input_test.pdl | 2 +- examples/prompt_library/demos/CoT.pdl | 2 +- examples/prompt_library/demos/PoT.pdl | 2 +- examples/prompt_library/demos/RAG.pdl | 2 +- examples/prompt_library/demos/ReAct.pdl | 4 +-- examples/prompt_library/demos/ReWOO.pdl | 2 +- examples/prompt_library/demos/Verifier.pdl | 4 +-- .../prompt_library/demos/Verifier_json.pdl | 6 ++-- examples/prompt_library/demos/gsm8k/CoT.pdl | 2 +- examples/prompt_library/demos/gsm8k/ReAct.pdl | 4 +-- examples/teacher/teacher.pdl | 2 +- examples/tutorial/conditionals_loops.pdl | 4 +-- examples/tutorial/data.yaml | 29 ++++++++++--------- examples/tutorial/data_block.pdl | 4 +-- examples/tutorial/example1.txt | 13 +++++++++ examples/tutorial/example2.txt | 12 ++++++++ examples/tutorial/gen-data.pdl | 2 +- examples/tutorial/ground_truth.txt | 3 ++ examples/tutorial/input_file.pdl | 2 +- examples/tutorial/input_file_json.pdl | 2 +- pdl/pdl.py | 2 +- 34 files changed, 94 insertions(+), 63 deletions(-) create mode 100644 examples/tutorial/example1.txt create mode 100644 examples/tutorial/example2.txt create mode 100644 examples/tutorial/ground_truth.txt diff --git a/README.md b/README.md index 276e4c77..c7763188 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 - | @@ -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 diff --git a/docs/README.md b/docs/README.md index dd608ade..8e6a784e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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 @@ -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" @@ -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 diff --git a/examples/arith/Arith-simple.pdl b/examples/arith/Arith-simple.pdl index 88fafb35..9c75594d 100644 --- a/examples/arith/Arith-simple.pdl +++ b/examples/arith/Arith-simple.pdl @@ -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. diff --git a/examples/code/code-defs.pdl b/examples/code/code-defs.pdl index bc3e6f61..fa3e3044 100644 --- a/examples/code/code-defs.pdl +++ b/examples/code/code-defs.pdl @@ -1,7 +1,7 @@ description: Code explanation example defs: CODE: - read: examples/code/data.yaml + read: ./data.yaml parser: yaml def: CODE EXPLANATION: diff --git a/examples/code/code-eval.pdl b/examples/code/code-eval.pdl index 001ab68a..8af063c5 100644 --- a/examples/code/code-eval.pdl +++ b/examples/code/code-eval.pdl @@ -1,6 +1,6 @@ description: Code explanation example document: -- read: examples/code/data.yaml +- read: ./data.yaml parser: yaml def: CODE show_result: False @@ -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 - | diff --git a/examples/code/code-json.pdl b/examples/code/code-json.pdl index 62e31a94..26a238d1 100644 --- a/examples/code/code-json.pdl +++ b/examples/code/code-json.pdl @@ -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 diff --git a/examples/code/code.pdl b/examples/code/code.pdl index 62eb0ec1..e5a7170b 100644 --- a/examples/code/code.pdl +++ b/examples/code/code.pdl @@ -1,6 +1,6 @@ description: Code explanation example document: -- read: examples/code/data.yaml +- read: ./data.yaml parser: yaml def: CODE show_result: False diff --git a/examples/demo/1-gen-data.pdl b/examples/demo/1-gen-data.pdl index 73d6124c..c945fcb1 100644 --- a/examples/demo/1-gen-data.pdl +++ b/examples/demo/1-gen-data.pdl @@ -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: diff --git a/examples/demo/2-teacher.pdl b/examples/demo/2-teacher.pdl index 43b2cf19..13ab2991 100644 --- a/examples/demo/2-teacher.pdl +++ b/examples/demo/2-teacher.pdl @@ -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 diff --git a/examples/granite/multi_round_chat.pdl b/examples/granite/multi_round_chat.pdl index ba09c350..c8265fdb 100644 --- a/examples/granite/multi_round_chat.pdl +++ b/examples/granite/multi_round_chat.pdl @@ -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]} diff --git a/examples/granite/single_round_chat.pdl b/examples/granite/single_round_chat.pdl index 822fcb32..5fa38f57 100644 --- a/examples/granite/single_round_chat.pdl +++ b/examples/granite/single_round_chat.pdl @@ -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 }} diff --git a/examples/gsm8k/math-patterns.pdl b/examples/gsm8k/math-patterns.pdl index 65f3e9ad..7ee0e902 100644 --- a/examples/gsm8k/math-patterns.pdl +++ b/examples/gsm8k/math-patterns.pdl @@ -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 diff --git a/examples/hello/hello-parser-json.pdl b/examples/hello/hello-parser-json.pdl index 6858dc3c..5aba4f07 100644 --- a/examples/hello/hello-parser-json.pdl +++ b/examples/hello/hello-parser-json.pdl @@ -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: diff --git a/examples/input/input_test.pdl b/examples/input/input_test.pdl index bc1f8946..b3de5211 100644 --- a/examples/input/input_test.pdl +++ b/examples/input/input_test.pdl @@ -1,6 +1,6 @@ description: Hello world! defs: - file: examples/input/data.tx + file: ./data.tx document: - read: "{{ file }}" def: HELLO diff --git a/examples/prompt_library/demos/CoT.pdl b/examples/prompt_library/demos/CoT.pdl index 6d1dc047..540726cc 100644 --- a/examples/prompt_library/demos/CoT.pdl +++ b/examples/prompt_library/demos/CoT.pdl @@ -1,6 +1,6 @@ description: Demo of CoT template document: - - include: examples/prompt_library/CoT.pdl + - include: ../CoT.pdl - call: fewshot_cot args: examples: diff --git a/examples/prompt_library/demos/PoT.pdl b/examples/prompt_library/demos/PoT.pdl index ddf6d1c9..df290415 100644 --- a/examples/prompt_library/demos/PoT.pdl +++ b/examples/prompt_library/demos/PoT.pdl @@ -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: diff --git a/examples/prompt_library/demos/RAG.pdl b/examples/prompt_library/demos/RAG.pdl index 0f91c334..6692e30d 100644 --- a/examples/prompt_library/demos/RAG.pdl +++ b/examples/prompt_library/demos/RAG.pdl @@ -1,6 +1,6 @@ description: Demo of RAG template document: - - include: examples/prompt_library/RAG.pdl + - include: ../RAG.pdl - call: corpus args: corpus: diff --git a/examples/prompt_library/demos/ReAct.pdl b/examples/prompt_library/demos/ReAct.pdl index 494919f6..52db2a9e 100644 --- a/examples/prompt_library/demos/ReAct.pdl +++ b/examples/prompt_library/demos/ReAct.pdl @@ -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 diff --git a/examples/prompt_library/demos/ReWOO.pdl b/examples/prompt_library/demos/ReWOO.pdl index 6528e6f6..f0520d7d 100644 --- a/examples/prompt_library/demos/ReWOO.pdl +++ b/examples/prompt_library/demos/ReWOO.pdl @@ -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 diff --git a/examples/prompt_library/demos/Verifier.pdl b/examples/prompt_library/demos/Verifier.pdl index 53ca38b9..c68b0a92 100644 --- a/examples/prompt_library/demos/Verifier.pdl +++ b/examples/prompt_library/demos/Verifier.pdl @@ -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 diff --git a/examples/prompt_library/demos/Verifier_json.pdl b/examples/prompt_library/demos/Verifier_json.pdl index 1ecd30b0..7e9e2e98 100644 --- a/examples/prompt_library/demos/Verifier_json.pdl +++ b/examples/prompt_library/demos/Verifier_json.pdl @@ -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 diff --git a/examples/prompt_library/demos/gsm8k/CoT.pdl b/examples/prompt_library/demos/gsm8k/CoT.pdl index a2225c62..ab3f6f11 100644 --- a/examples/prompt_library/demos/gsm8k/CoT.pdl +++ b/examples/prompt_library/demos/gsm8k/CoT.pdl @@ -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: diff --git a/examples/prompt_library/demos/gsm8k/ReAct.pdl b/examples/prompt_library/demos/gsm8k/ReAct.pdl index 9c66e3bb..1819e180 100644 --- a/examples/prompt_library/demos/gsm8k/ReAct.pdl +++ b/examples/prompt_library/demos/gsm8k/ReAct.pdl @@ -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?" diff --git a/examples/teacher/teacher.pdl b/examples/teacher/teacher.pdl index 43b2cf19..13ab2991 100644 --- a/examples/teacher/teacher.pdl +++ b/examples/teacher/teacher.pdl @@ -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 diff --git a/examples/tutorial/conditionals_loops.pdl b/examples/tutorial/conditionals_loops.pdl index 64b9380c..9af34b4d 100644 --- a/examples/tutorial/conditionals_loops.pdl +++ b/examples/tutorial/conditionals_loops.pdl @@ -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 diff --git a/examples/tutorial/data.yaml b/examples/tutorial/data.yaml index c8a6d75f..5d92f743 100644 --- a/examples/tutorial/data.yaml +++ b/examples/tutorial/data.yaml @@ -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 \ No newline at end of file +source_code: + | + @SuppressWarnings("unchecked") + public static Map deserializeOffsetMap(String lastSourceOffset) throws IOException { + Map 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 diff --git a/examples/tutorial/data_block.pdl b/examples/tutorial/data_block.pdl index 7f822465..971479a7 100644 --- a/examples/tutorial/data_block.pdl +++ b/examples/tutorial/data_block.pdl @@ -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 diff --git a/examples/tutorial/example1.txt b/examples/tutorial/example1.txt new file mode 100644 index 00000000..acc9b2b7 --- /dev/null +++ b/examples/tutorial/example1.txt @@ -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. + diff --git a/examples/tutorial/example2.txt b/examples/tutorial/example2.txt new file mode 100644 index 00000000..95dfb7a8 --- /dev/null +++ b/examples/tutorial/example2.txt @@ -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. diff --git a/examples/tutorial/gen-data.pdl b/examples/tutorial/gen-data.pdl index 1e3a1487..101501d1 100644 --- a/examples/tutorial/gen-data.pdl +++ b/examples/tutorial/gen-data.pdl @@ -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: diff --git a/examples/tutorial/ground_truth.txt b/examples/tutorial/ground_truth.txt new file mode 100644 index 00000000..5054ac95 --- /dev/null +++ b/examples/tutorial/ground_truth.txt @@ -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. diff --git a/examples/tutorial/input_file.pdl b/examples/tutorial/input_file.pdl index b70c0c39..296d2c85 100644 --- a/examples/tutorial/input_file.pdl +++ b/examples/tutorial/input_file.pdl @@ -1,4 +1,4 @@ description: PDL code with input block document: -- read: examples/input/data.txt +- read: ./data.txt def: HELLO \ No newline at end of file diff --git a/examples/tutorial/input_file_json.pdl b/examples/tutorial/input_file_json.pdl index de668b99..ab0946ee 100644 --- a/examples/tutorial/input_file_json.pdl +++ b/examples/tutorial/input_file_json.pdl @@ -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 diff --git a/pdl/pdl.py b/pdl/pdl.py index 2a647327..d1f15379 100644 --- a/pdl/pdl.py +++ b/pdl/pdl.py @@ -210,7 +210,7 @@ def main(): pdl_interpreter.generate( pdl_file, args.log, - InterpreterState(**config, cwd=pdl_file), + InterpreterState(**config, cwd=pdl_file.parent), initial_scope, trace_file, )