From bfa8e43f0137d7ac3cef4e09fc55e42f85f0e10a Mon Sep 17 00:00:00 2001 From: Mandana Vaziri Date: Sun, 6 Oct 2024 06:43:22 -0400 Subject: [PATCH 01/24] merge Signed-off-by: Mandana Vaziri --- examples/arith/Arith-simple.pdl | 37 +++ examples/arith/arith.pdl | 46 +++ examples/chatbot/chatbot.pdl | 8 +- examples/cldk/cldk-assistant.pdl | 169 ++++++++-- examples/code/code-eval.pdl | 3 +- examples/code/code-json.pdl | 3 +- examples/code/code.pdl | 3 +- examples/demo/1-gen-data.pdl | 5 +- examples/demo/2-teacher.pdl | 14 +- examples/demo/3-weather.pdl | 8 +- examples/demo/4-translator.pdl | 8 +- examples/demo/test.pdl | 6 - examples/earth/Earth.pdl | 15 + examples/fibonacci/fib.pdl | 6 +- examples/granite/multi_round_chat.pdl | 3 +- examples/granite/single_round_chat.pdl | 3 +- examples/gsm8k/gsmhard-bugs.pdl | 11 + examples/gsm8k/math-base.pdl | 10 + examples/gsm8k/math-jinja.pdl | 91 ++++++ examples/gsm8k/math-python.pdl | 30 ++ examples/gsm8k/math.pdl | 164 ++++++++++ examples/hello/hello-def-use.pdl | 5 +- examples/hello/hello-model-chaining.pdl | 14 +- examples/hello/hello-model-input.pdl | 5 +- examples/hello/hello-parser-json.pdl | 5 +- examples/hello/hello-parser-regex.pdl | 5 +- examples/hello/hello-roles-array.pdl | 3 +- examples/hello/hello-type.pdl | 10 +- examples/hello/hello.pdl | 5 +- examples/hello/test.pdl | 9 + examples/joke/Joke.pdl | 31 ++ examples/meta/pdl-gen.pdl | 316 +++++++++++++++++++ examples/notebooks/notebook.ipynb | 8 +- examples/notebooks/notebook_debug.ipynb | 5 +- examples/oddOneOut/OddOneOut.pdl | 40 +++ examples/rag/rag.pdl | 5 +- examples/react/multi-agent.pdl | 2 +- examples/react/react_call.pdl | 4 +- examples/react/react_fun.pdl | 7 +- examples/react/wikipedia.pdl | 10 +- examples/sdk/hello.pdl | 5 +- examples/sdk/hello_dict.py | 5 +- examples/talk/1-hello.pdl | 5 +- examples/talk/11-sdg.pdl | 15 +- examples/talk/2-model-chaining.pdl | 10 +- examples/talk/3-def-use.pdl | 7 +- examples/talk/4-function.pdl | 5 +- examples/talk/5-code-eval.pdl | 3 +- examples/talk/6-code-json.pdl | 3 +- examples/talk/7-chatbot-roles.pdl | 12 +- examples/talk/8-tools.pdl | 5 +- examples/talk/9-react.pdl | 11 +- examples/teacher/teacher.pdl | 15 +- examples/thing/Thing.pdl | 19 ++ examples/tools/calc.pdl | 5 +- examples/tutorial/calling_apis.pdl | 8 +- examples/tutorial/calling_llm.pdl | 5 +- examples/tutorial/calling_llm_with_input.pdl | 3 +- examples/tutorial/conditionals_loops.pdl | 2 +- examples/tutorial/data_block.pdl | 3 +- examples/tutorial/function_definition.pdl | 5 +- examples/tutorial/gen-data.pdl | 5 +- examples/tutorial/grouping_definitions.pdl | 5 +- examples/tutorial/include.pdl | 3 +- examples/tutorial/model_chaining.pdl | 10 +- examples/tutorial/muting_block_output.pdl | 5 +- examples/tutorial/variable_def_use.pdl | 5 +- examples/weather/weather.pdl | 8 +- 68 files changed, 1164 insertions(+), 160 deletions(-) create mode 100644 examples/arith/Arith-simple.pdl create mode 100644 examples/arith/arith.pdl delete mode 100644 examples/demo/test.pdl create mode 100644 examples/earth/Earth.pdl create mode 100644 examples/gsm8k/gsmhard-bugs.pdl create mode 100644 examples/gsm8k/math-base.pdl create mode 100644 examples/gsm8k/math-jinja.pdl create mode 100644 examples/gsm8k/math-python.pdl create mode 100644 examples/gsm8k/math.pdl create mode 100644 examples/hello/test.pdl create mode 100644 examples/joke/Joke.pdl create mode 100644 examples/meta/pdl-gen.pdl create mode 100644 examples/oddOneOut/OddOneOut.pdl create mode 100644 examples/thing/Thing.pdl diff --git a/examples/arith/Arith-simple.pdl b/examples/arith/Arith-simple.pdl new file mode 100644 index 000000000..6b04ce697 --- /dev/null +++ b/examples/arith/Arith-simple.pdl @@ -0,0 +1,37 @@ +description: Math Problems +text: +- read: ./example1.txt +- read: ./example2.txt +- "\n" +- | + Question: Noah charges $10 for a large box and $5 for a small box. + Last month he sold four large boxes and two small boxes. + If he sold half as much this month, how much is his sales for this month? +- repeat: + text: + - def: REASON_OR_CALC + model: ibm/granite-20b-code-instruct + platform: bam + parameters: + stop_sequences: + - '<<' + include_stop_sequence: true + - if: ${ REASON_OR_CALC.endswith("<<") } + then: + text: + - def: EXPR + model: ibm/granite-20b-code-instruct + platform: bam + parameters: + stop_sequences: + - '=' + - "\n" + - "Question" + include_stop_sequence: false + - '= ' + - def: RESULT + lang: python + code: result = ${ EXPR } + - ' >>' + until: ${ "The answer is" in REASON_OR_CALC } +- "\n" \ No newline at end of file diff --git a/examples/arith/arith.pdl b/examples/arith/arith.pdl new file mode 100644 index 000000000..cc6bd78c9 --- /dev/null +++ b/examples/arith/arith.pdl @@ -0,0 +1,46 @@ +description: Math Problems +text: +- read: example1.txt +- read: example2.txt +- repeat: + text: + - "\nQuestion: " + - def: QUESTION + model: ibm/granite-34b-code-instruct + platform: bam + parameters: + stop_sequences: + - Answer + - "?" + include_stop_sequence: true + - "\nAnswer: Let's think step by step.\n" + - repeat: + text: + - def: REASON_OR_CALC + model: ibm/granite-34b-code-instruct + platform: bam + parameters: + stop_sequences: + - '<<' + - "Question" + include_stop_sequence: true + - if: ${ REASON_OR_CALC.endswith("<<") } + then: + text: + - def: EXPR + model: ibm/granite-34b-code-instruct + platform: bam + parameters: + stop_sequences: + - '=' + - "\n" + - "Question" + include_stop_sequence: false + - '= ' + - def: RESULT + lang: python + code: result = ${ EXPR } + - ' >>' + until: ${ "The answer is" in REASON_OR_CALC } + - "\n\n" + num_iterations: 3 \ No newline at end of file diff --git a/examples/chatbot/chatbot.pdl b/examples/chatbot/chatbot.pdl index 60d20ef2a..54eb0c06b 100644 --- a/examples/chatbot/chatbot.pdl +++ b/examples/chatbot/chatbot.pdl @@ -2,10 +2,15 @@ description: chatbot text: - read: message: "What is your query?\n" +<<<<<<< HEAD contribute: [context] +======= + contribute: [] +>>>>>>> 808f1a1 (merge) - repeat: text: - - model: watsonx/ibm/granite-13b-chat-v2 + - model: ibm/granite-13b-chat-v2 + platform: bam - read: def: eval message: "\nIs this a good answer[yes/no]?\n" @@ -15,6 +20,7 @@ text: text: - read: message: "Why not?\n" + contribute: [] until: ${ eval == 'yes'} diff --git a/examples/cldk/cldk-assistant.pdl b/examples/cldk/cldk-assistant.pdl index 59524abea..46b94b8a7 100644 --- a/examples/cldk/cldk-assistant.pdl +++ b/examples/cldk/cldk-assistant.pdl @@ -14,11 +14,11 @@ text: from cldk import CLDK from cldk.models.java.models import * - # Initialize the Codellm-DevKit object with the project directory, language, and backend. + # Initialize the Codellm-DevKit object with the project directory, langguage, and backend. cldk = CLDK("java") cldk_state = cldk.analysis( project_path="${ project }", # Change this to the path of the project you want to analyze. - # language="java", # The language of the project. + # langguage="java", # The langguage of the project. # backend="codeanalyzer", # The backend to use for the analysis. # analysis_db="/tmp", # A temporary directory to store the analysis results. # sdg=True, # Generate the System Dependence Graph (SDG) for the project. @@ -42,7 +42,7 @@ text: Answer: ``` text: - - lang: python + - langg: python code: - | classes = PDL_SESSION.cldk_state.get_classes().keys() @@ -53,7 +53,7 @@ text: Answer: ``` text: - - lang: python + - langg: python code: - | constructors = PDL_SESSION.cldk_state.get_constructors("org.ibm.App") @@ -64,7 +64,7 @@ text: Answer: ``` text: - - lang: python + - langg: python code: - | fields = PDL_SESSION.cldk_state.get_fields("org.ibm.App") @@ -76,7 +76,7 @@ text: Answer: ``` text: - - lang: python + - langg: python code: - | methods = PDL_SESSION.cldk_state.get_methods_in_class("org.ibm.App") @@ -87,7 +87,7 @@ text: Answer: ``` text: - - lang: python + - langg: python code: - | graph = PDL_SESSION.cldk_state.get_class_call_graph("org.ibm.App", method_name=None) @@ -98,7 +98,7 @@ text: Answer: ``` text: - - lang: python + - langg: python code: - | method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") @@ -109,7 +109,7 @@ text: Answer: ``` text: - - lang: python + - langg: python code: - | method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") @@ -122,7 +122,7 @@ text: Answer: ``` text: - - lang: python + - langg: python code: - | method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") @@ -140,25 +140,140 @@ text: stop_sequence: ["Question"] include_stop_sequence: false - "\n\n***Executing the above PDL code:\n\n" - - lang: python + - langg: python contribute: [] - code: | - from pdl import pdl_ast, pdl_interpreter - from pdl.pdl_ast import Program - from pdl.pdl_interpreter import process_prog - from pdl.pdl_interpreter import InterpreterState - from pdl.pdl_interpreter import empty_scope - import re - import yaml - s = """'${ PDL }'""" - print(s) - pdl = s.split("```")[1] - obj = yaml.safe_load(pdl) - state = InterpreterState() - data = Program.model_validate(obj) - - result, _, _, _ = process_prog(state, empty_scope, data) + - "\n***Generating PDL code for your query:\n" + - if: ${ query != 'quit'} + then: + - model: ibm/granite-20b-code-instruct + platform: bam + def: PDL + input: + - | + Question: What are all the classes? + Answer: + ``` + text: + - lang: python + code: + - | + classes = PDL_SESSION.cldk_state.get_classes().keys() + result = ", ".join(classes) + ``` + + Question: What are all the constructors of class org.ibm.App? + Answer: + ``` + text: + - lang: python + code: + - | + constructors = PDL_SESSION.cldk_state.get_constructors("org.ibm.App") + result = ", ".join(constructors) + ``` + + Question: What are all the fields of class org.ibm.App? + Answer: + ``` + text: + - lang: python + code: + - | + fields = PDL_SESSION.cldk_state.get_fields("org.ibm.App") + names = sum([f.variables for f in fields], []) + result = ", ".join(names) + ``` + + Question: What are all the methods of class org.ibm.App? + Answer: + ``` + text: + - lang: python + code: + - | + methods = PDL_SESSION.cldk_state.get_methods_in_class("org.ibm.App") + result = ", ".join(methods) + ``` + + Question: Show me the call graph of class "org.ibm.App" + Answer: + ``` + text: + - lang: python + code: + - | + graph = PDL_SESSION.cldk_state.get_class_call_graph("org.ibm.App", method_name=None) + result = graph + ``` + + Question: What is the code of method Foo(string) of class org.ibm.App? + Answer: + ``` + text: + - lang: python + code: + - | + method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") + result = method.code + ``` + + Question: Generate a summary for method Foo(string) of class org.ibm.App + Answer: + ``` + text: + - lang: python + code: + - | + method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") + result = method + - "\n\nGenerate a summary of method Foo\n\n" + - model: meta-llama/llama-3-1-70b-instruct + platform: bam + ``` + + Question: Generate a different comment for method Foo(string) in class org.ibm.App? + Answer: + ``` + text: + - lang: python + code: + - | + method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") + result = method + - "\n\nGenerate a different comment for method Foo(string)\n\n" + - model: meta-llama/llama-3-1-70b-instruct + platform: bam + ``` + + If the query contains something about a field be sure to call a model. + + Question: ${ query } + + + parameters: + stop_sequences: ["Question"] + include_stop_sequence: false + - "\n\n***Executing the above PDL code:\n\n" + - lang: python + contribute: [result] + code: | + from pdl import pdl_ast, pdl_interpreter + from pdl.pdl_ast import Program + from pdl.pdl_interpreter import process_prog + from pdl.pdl_interpreter import InterpreterState + from pdl.pdl_interpreter import empty_scope + import re + import yaml + s = """'${ PDL }'""" + print(s) + pdl = s.split("```")[1] + obj = yaml.safe_load(pdl) + state = InterpreterState() + data = Program.model_validate(obj) + + result, _, _, _ = process_prog(state, empty_scope, data) until: ${ query == 'quit' } + as: text diff --git a/examples/code/code-eval.pdl b/examples/code/code-eval.pdl index 6d0a15c29..bf599568c 100644 --- a/examples/code/code-eval.pdl +++ b/examples/code/code-eval.pdl @@ -7,7 +7,8 @@ defs: read: ./ground_truth.txt text: - "\n${ CODE.source_code }\n" -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam def: EXPLANATION input: | Here is some info about the location of the function in the repo. diff --git a/examples/code/code-json.pdl b/examples/code/code-json.pdl index 915ff8f56..7d2d5cd5d 100644 --- a/examples/code/code-json.pdl +++ b/examples/code/code-json.pdl @@ -6,7 +6,8 @@ defs: TRUTH: read: ./ground_truth.txt text: -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam def: EXPLANATION contribute: [] input: diff --git a/examples/code/code.pdl b/examples/code/code.pdl index 1e0900f67..8d6ea7f57 100644 --- a/examples/code/code.pdl +++ b/examples/code/code.pdl @@ -5,7 +5,8 @@ defs: parser: yaml text: - "\n${ CODE.source_code }\n" -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam input: - | Here is some info about the location of the function in the repo. diff --git a/examples/demo/1-gen-data.pdl b/examples/demo/1-gen-data.pdl index 8cfd7851c..08e22363c 100644 --- a/examples/demo/1-gen-data.pdl +++ b/examples/demo/1-gen-data.pdl @@ -5,7 +5,8 @@ defs: parser: yaml spec: { questions: [str], answers: [obj] } text: - - model: watsonx/ibm/granite-20b-code-instruct + - model: ibm/granite-20b-code-instruct + platform: bam def: model_output spec: {name: str, age: int} input: @@ -22,7 +23,7 @@ text: and set them appropriately. Write the age in letters. parser: yaml parameters: - stop: + stop_sequences: - '}' include_stop_sequence: true \ No newline at end of file diff --git a/examples/demo/2-teacher.pdl b/examples/demo/2-teacher.pdl index 889602bd0..7cb787450 100644 --- a/examples/demo/2-teacher.pdl +++ b/examples/demo/2-teacher.pdl @@ -1,6 +1,6 @@ defs: teacher_sys_prompt: You are a very knowledgeable AI Assistant that will faithfully assist the user with their task. - teacher_model: watsonx/mistralai/mixtral-8x7b-instruct-v01 + teacher_model: mistralai/mixtral-8x7b-instruct-v01 teacher_template: function: sys_prompt: str @@ -65,9 +65,10 @@ defs: ${prompt_data.generation} teacher_output: model: ${teacher_model} + platform: bam input: ${teacher_input} parameters: - stop: ["${teacher_stop_token}"] + stop_sequences: ["${teacher_stop_token}"] include_stop_sequence: false max_new_tokens: ${prompt_data.max_new_tokens} parser: @@ -154,9 +155,10 @@ defs: ${prompt_data.generation} teacher_output: model: ${teacher_model} + platform: bam input: ${teacher_input} parameters: - stop: ["${teacher_stop_token}"] + stop_sequences: ["${teacher_stop_token}"] include_stop_sequence: false max_new_tokens: ${prompt_data.max_new_tokens} parser: @@ -249,9 +251,10 @@ defs: ${prompt_data.generation} teacher_output: model: ${teacher_model} + platform: bam input: ${teacher_input} parameters: - stop: ${ [teacher_stop_token] + prompt_data.additional_stop_tokens } + stop_sequences: ${ [teacher_stop_token] + prompt_data.additional_stop_tokens } include_stop_sequence: false max_new_tokens: ${prompt_data.max_new_tokens} parsed_answer: @@ -336,9 +339,10 @@ defs: ${prompt_data.generation} teacher_output: model: ${teacher_model} + platform: bam input: ${teacher_input} parameters: - stop: ["${teacher_stop_token}"] + stop_sequences: ["${teacher_stop_token}"] include_stop_sequence: false max_new_tokens: ${prompt_data.max_new_tokens} parser: diff --git a/examples/demo/3-weather.pdl b/examples/demo/3-weather.pdl index a7d59d005..414e7e815 100644 --- a/examples/demo/3-weather.pdl +++ b/examples/demo/3-weather.pdl @@ -4,7 +4,8 @@ text: def: QUERY message: "Ask a query: " contribute: [] -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam input: | Question: What is the weather in London? London @@ -14,7 +15,7 @@ text: Lagos Question: ${ QUERY } parameters: - stop: + stop_sequences: - Question - What - '!' @@ -30,7 +31,8 @@ text: parser: json contribute: [] -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam input: | Explain the weather from the following JSON: ${ WEATHER } diff --git a/examples/demo/4-translator.pdl b/examples/demo/4-translator.pdl index 8cd2d2a01..4c7aeced4 100644 --- a/examples/demo/4-translator.pdl +++ b/examples/demo/4-translator.pdl @@ -1,10 +1,11 @@ description: PDL program text: - What is APR? -- model: watsonx/ibm/granite-13b-chat-v2 +- model: ibm/granite-13b-chat-v2 + platform: bam parameters: max_new_tokens: 128 - stop: ["."] + stop_sequences: ["."] include_stop_sequence: true - repeat: text: @@ -15,5 +16,6 @@ text: then: text: - "\n\nTranslate the above to ${ language }" - - model: watsonx/ibm/granite-13b-chat-v2 + - model: ibm/granite-13b-chat-v2 + platform: bam until: ${ language == 'stop' } diff --git a/examples/demo/test.pdl b/examples/demo/test.pdl deleted file mode 100644 index 98e5ce3f2..000000000 --- a/examples/demo/test.pdl +++ /dev/null @@ -1,6 +0,0 @@ -description: Hello world calling a model -text: -- model: watsonx/ibm/granite-20b-multilingual - input: - Translate the word 'world' to French - \ No newline at end of file diff --git a/examples/earth/Earth.pdl b/examples/earth/Earth.pdl new file mode 100644 index 000000000..57719f32c --- /dev/null +++ b/examples/earth/Earth.pdl @@ -0,0 +1,15 @@ +description: Earth circumference question +text: +- 'What is the circumference of the earth? I believe the best person to answer this question is ' +- def: EXPERT + model: ibm/granite-34b-code-instruct + platform: bam + parameters: + stop_sequences: + - "." + include_stop_sequence: false +- '. Indeed, ' +- get: EXPERT +- ' addressed this question: ' +- model: ibm/granite-34b-code-instruct + platform: bam \ No newline at end of file diff --git a/examples/fibonacci/fib.pdl b/examples/fibonacci/fib.pdl index 1671f5504..bb9dd089f 100644 --- a/examples/fibonacci/fib.pdl +++ b/examples/fibonacci/fib.pdl @@ -1,7 +1,8 @@ description: Fibonacci text: - def: CODE - model: watsonx/ibm/granite-20b-code-instruct + model: ibm/granite-20b-code-instruct + platform: bam input: "Write a Python function to compute the Fibonacci sequence\n\n" - "\nFind a random number between 1 and 20\n" @@ -27,4 +28,5 @@ text: - 'The result is: ' - get: RESULT - "\n\nExplain what the above code does and what the result means\n\n" -- model: watsonx/ibm/granite-20b-code-instruct \ No newline at end of file +- model: ibm/granite-20b-code-instruct + platform: bam \ No newline at end of file diff --git a/examples/granite/multi_round_chat.pdl b/examples/granite/multi_round_chat.pdl index dcf93864f..d65b1514a 100644 --- a/examples/granite/multi_round_chat.pdl +++ b/examples/granite/multi_round_chat.pdl @@ -13,7 +13,8 @@ text: text: - | ${ prompt } - - model: watsonx/ibm/granite-13b-chat-v2 + - model: ibm/granite-13b-chat-v2 + platform: bam parameters: decoding_method: sample max_new_tokens: 512 diff --git a/examples/granite/single_round_chat.pdl b/examples/granite/single_round_chat.pdl index 5a5e1ee71..a1b4e2686 100644 --- a/examples/granite/single_round_chat.pdl +++ b/examples/granite/single_round_chat.pdl @@ -4,7 +4,8 @@ text: - role: system content: ${ SYSTEM_CONTENT_CHAT } - ${ PROMPT } -- model: watsonx/ibm/granite-13b-chat-v2 +- model: ibm/granite-13b-chat-v2 + platform: bam parameters: decoding_method: sample max_new_tokens: 512 diff --git a/examples/gsm8k/gsmhard-bugs.pdl b/examples/gsm8k/gsmhard-bugs.pdl new file mode 100644 index 000000000..a4daff720 --- /dev/null +++ b/examples/gsm8k/gsmhard-bugs.pdl @@ -0,0 +1,11 @@ +description: GSM Hard Bug Finder +text: +- ${ question } +- "\n" +- "Does the following code accurately solve this problem?\n\n" +- ${ code } +- model: meta-llama/llama-3-70b-instruct + platform: bam + parameters: + stop_sequences: ["def"] + include_stop_sequence: false \ No newline at end of file diff --git a/examples/gsm8k/math-base.pdl b/examples/gsm8k/math-base.pdl new file mode 100644 index 000000000..76fd03792 --- /dev/null +++ b/examples/gsm8k/math-base.pdl @@ -0,0 +1,10 @@ +description: math problem +text: + +- model: meta-llama/llama-3-70b-instruct + platform: bam + def: PDL + input: "Question: ${ question }" + parameters: + stop_sequences: ["Question"] + include_stop_sequence: false diff --git a/examples/gsm8k/math-jinja.pdl b/examples/gsm8k/math-jinja.pdl new file mode 100644 index 000000000..0ccccf17e --- /dev/null +++ b/examples/gsm8k/math-jinja.pdl @@ -0,0 +1,91 @@ +description: math problem +text: + +- model: meta-llama/llama-3-70b-instruct + def: PDL + input: + text: + - | + Question: A deep-sea monster rises from the waters once every hundred years to feast on a ship and sate its hunger. + Over three hundred years, it has consumed 847 people. Ships have been built larger over time, + so each new ship has twice as many people as the last ship. How many people were on the ship the + monster ate in the first hundred years? + + Answer: + ``` + description: my answer + text: + - Let's call the number of people on the first ship x. + - lang: python + def: equation + code: + - | + from sympy import * + x = symbols('x') + result = x + 2*x + 4*x + - "The equation is ${ equation } = 847.\n" + - "Solving for x, we get " + - lang: python + def: RESULT + code: + - | + from sympy import * + x = symbols('x') + result = solve(${ equation } - 847, x)[0] + - "\nThe answer is ${RESULT}." + - lang: python + def: FINAL + code: + - | + result = ${ RESULT } + - "\n#### " + - ${ FINAL } + ``` + Question: Roger has 5 tennis balls. He buys 2 more cans of tennis balls. + Each can has 3 tennis balls. How many tennis balls does he have now? + + Answer: + ``` + description: my answer + text: + - Roger started with 5 tennis balls + - def: tennis_balls + data: 5 + - "\n2 cans of 3 tennis balls each is\n" + - def: bought_balls + data: ${ 2 * 3 } + - "\ntennis balls. The answer is\n" + - def: RESULT + data: ${ tennis_balls + bought_balls } + - lang: python + def: FINAL + code: + - | + result = ${ RESULT } + - "\n#### " + - ${ FINAL } + ``` + + + + - "Question: ${ question }" + parameters: + stop_sequences: ["Question"] + include_stop_sequence: false +- lang: python + code: | + from pdl import pdl_ast, pdl_interpreter + from pdl.pdl_ast import Program + from pdl.pdl_interpreter import process_prog + from pdl.pdl_interpreter import InterpreterState + from pdl.pdl_interpreter import empty_scope + import re + import yaml + s = """'${ PDL }'""" + pdl = s.split("```")[1] + obj = yaml.safe_load(pdl) + state = InterpreterState() + data = Program.model_validate(obj) + + result, _, _, _ = process_prog(state, empty_scope, data) + def: RESULT diff --git a/examples/gsm8k/math-python.pdl b/examples/gsm8k/math-python.pdl new file mode 100644 index 000000000..cae793a19 --- /dev/null +++ b/examples/gsm8k/math-python.pdl @@ -0,0 +1,30 @@ +description: math problem +text: + +- model: meta-llama/llama-3-70b-instruct + platform: bam + def: PROGRAM + input: + text: + - | + + Question: Roger has 5 tennis balls. He buys 2 more cans of tennis balls. + Each can has 3 tennis balls. How many tennis balls does he have now? + + Answer: + ``` + # Roger started with 5 tennis balls + tennis_balls = 5 + # 2 cans of 3 tennis balls each is + bought_balls = 2 * 3 + # tennis balls. The answer is + result = tennis_balls + bought_balls + print("#### " + str(result)) + ``` + + + + - "Question: ${ question }" + parameters: + stop_sequences: ["Question"] + include_stop_sequence: false diff --git a/examples/gsm8k/math.pdl b/examples/gsm8k/math.pdl new file mode 100644 index 000000000..b2e52ee78 --- /dev/null +++ b/examples/gsm8k/math.pdl @@ -0,0 +1,164 @@ +description: math problem +text: + +- model: meta-llama/llama-3-70b-instruct + platform: bam + def: PDL + input: + text: + - | + Question: A deep-sea monster rises from the waters once every hundred years to feast on a ship and sate its hunger. + Over three hundred years, it has consumed 847 people. Ships have been built larger over time, + so each new ship has twice as many people as the last ship. How many people were on the ship the + monster ate in the first hundred years? + + Answer: + ``` + description: my answer + text: + - Let's call the number of people on the first ship x. + - lang: python + def: equation + code: + - | + from sympy import * + x = symbols('x') + result = x + 2*x + 4*x + - "The equation is ${ '${' } equation ${ '}' } = 847.\n" + - "Solving for x, we get " + - lang: python + def: RESULT + code: + - | + from sympy import * + x = symbols('x') + result = solve(${ '${' } equation ${ '}' } - 847, x)[0] + - "\nThe answer is ${ '${' } RESULT ${ '}' }." + - lang: python + def: FINAL + code: + - | + result = ${ '${' } RESULT ${ '}' } + - "\n#### " + - ${ '${' } FINAL ${ '}' }" + ``` + Question: Roger has 5 tennis balls. He buys 2 more cans of tennis balls. + Each can has 3 tennis balls. How many tennis balls does he have now? + + Answer: + ``` + description: my answer + text: + - Roger started with 5 tennis balls + - lang: python + def: tennis_balls + code: + - | + result = 5 + - "\n2 cans of 3 tennis balls each is\n" + - lang: python + def: bought_balls + code: + - | + result = 2 * 3 + - "\ntennis balls. The answer is\n" + - lang: python + def: RESULT + code: + - | + result = ${ '${' } tennis_balls ${ '}' } + ${ '${' } bought_balls ${ '}' } + - lang: python + def: FINAL + code: + - | + result = ${ '${' } RESULT ${ '}' } + - "\n#### " + - "${ '${' } FINAL ${ '}' }" + ``` + + Question: Betty is saving money for a new wallet which costs $100. Betty has only half of the money she needs. + Her parents decided to give her $15 for that purpose, + and her grandparents twice as much as her parents. How much more money does Betty need to buy the wallet? + + Answer: + ``` + description: my answer + text: + - Betty needs $100 for the wallet. + - lang: python + def: cost + code: + - | + result = 100 + - "Betty already has:\n" + - lang: python + def: betty_already_has + code: + - | + result = ${ '${' } cost ${ '}' } / 2 + - "\nHalf of the money she needs is\n" + - lang: python + def: half_cost + code: + - | + result = ${ '${' } cost ${ '}' } / 2 + - "\nBetty's parents gave her:\n" + - lang: python + def: money_from_parents + code: + - | + result = 15 + - "\nBetty's grandparents gave her:\n" + - lang: python + def: money_from_grandparents + code: + - | + result = ${ '${' } money_from_parents ${ '}' } * 2 + - "\nSo Betty has:\n" + - lang: python + def: money_betty_has + code: + - | + result = ${ '${' } betty_already_has ${ '}' } + ${ '${' } money_from_parents ${ '}' } + ${ '${' } money_from_grandparents ${ '}' } + - "\nTo buy the wallet, Betty needs\n" + - lang: python + def: money_needed + code: + - | + result = ${ '${' } cost ${ '}' } - ${ '${' } money_betty_has ${ '}' } + - "\nThe answer is ${ '${' } money_needed ${ '}' }." + - lang: python + def: FINAL + code: + - | + result = ${ '${' } money_needed ${ '}' } + - "\n#### " + - "${ '${' } FINAL ${ '}' }" + ``` + + + - "Question: ${ question }" + - If numbers are very large, do not modify them. + - Please pay attention when using the sympy library to import and use it correctly. + - The answer final line should be ${ '${' } FINAL ${ '}' }. + + parameters: + stop_sequences: ["Question"] + include_stop_sequence: false +- lang: python + code: | + from pdl import pdl_ast, pdl_interpreter + from pdl.pdl_ast import Program + from pdl.pdl_interpreter import process_prog + from pdl.pdl_interpreter import InterpreterState + from pdl.pdl_interpreter import empty_scope + import re + import yaml + s = """'${ PDL }'""" + pdl = s.split("```")[1] + obj = yaml.safe_load(pdl) + state = InterpreterState() + data = Program.model_validate(obj) + + result, _, _, _ = process_prog(state, empty_scope, data) + def: RESULT diff --git a/examples/hello/hello-def-use.pdl b/examples/hello/hello-def-use.pdl index 5d702d76a..174c48bfa 100644 --- a/examples/hello/hello-def-use.pdl +++ b/examples/hello/hello-def-use.pdl @@ -1,10 +1,11 @@ description: Hello world with variable use text: - Hello, -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam parameters: decoding_method: greedy - stop: + stop_sequences: - '!' include_stop_sequence: false def: NAME diff --git a/examples/hello/hello-model-chaining.pdl b/examples/hello/hello-model-chaining.pdl index 78fd0b335..d8c50f152 100644 --- a/examples/hello/hello-model-chaining.pdl +++ b/examples/hello/hello-model-chaining.pdl @@ -1,10 +1,11 @@ description: Hello world showing model chaining text: - Hello, -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam parameters: decoding_method: greedy - stop: + stop_sequences: - '!' include_stop_sequence: false def: NAME @@ -12,13 +13,10 @@ text: ! Who is${ NAME }? - "\n" -- model: watsonx/google/flan-t5-xl +- model: google/flan-t5-xl + platform: bam parameters: decoding_method: greedy - stop: + stop_sequences: - '.' include_stop_sequence: true - roles: - user: - pre_message: "" - post_message: "" diff --git a/examples/hello/hello-model-input.pdl b/examples/hello/hello-model-input.pdl index 22f2e910e..b77cef8c0 100644 --- a/examples/hello/hello-model-input.pdl +++ b/examples/hello/hello-model-input.pdl @@ -1,8 +1,9 @@ description: Hello world with model input text: -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam input: "Hello," parameters: - stop: + stop_sequences: - '!' include_stop_sequence: true diff --git a/examples/hello/hello-parser-json.pdl b/examples/hello/hello-parser-json.pdl index b6cbe8952..fa037212d 100644 --- a/examples/hello/hello-parser-json.pdl +++ b/examples/hello/hello-parser-json.pdl @@ -5,7 +5,8 @@ defs: parser: yaml spec: { "questions": ["str"], "answers": ["obj"] } text: - - model: watsonx/ibm/granite-34b-code-instruct + - model: ibm/granite-34b-code-instruct + platform: bam def: model_output spec: {"name": str, "age": int} input: @@ -23,7 +24,7 @@ text: parser: yaml parameters: decoding_method: greedy - stop: + stop_sequences: - '}' include_stop_sequence: true diff --git a/examples/hello/hello-parser-regex.pdl b/examples/hello/hello-parser-regex.pdl index f9a59a825..68e1e17ea 100644 --- a/examples/hello/hello-parser-regex.pdl +++ b/examples/hello/hello-parser-regex.pdl @@ -1,10 +1,11 @@ description: Hello world with parser using regex text: -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam input: "Hello," parameters: decoding_method: greedy - stop: + stop_sequences: - '!' include_stop_sequence: false spec: {"name": str} diff --git a/examples/hello/hello-roles-array.pdl b/examples/hello/hello-roles-array.pdl index 7fa6f9250..1450a389e 100644 --- a/examples/hello/hello-roles-array.pdl +++ b/examples/hello/hello-roles-array.pdl @@ -7,6 +7,7 @@ text: - role: user content: Write a Python function that implement merge sort. contribute: [] -- model: watsonx/ibm/granite-8b-code-instruct +- model: ibm/granite-8b-code-instruct + platform: bam input: ${ prompt } diff --git a/examples/hello/hello-type.pdl b/examples/hello/hello-type.pdl index 61f4d0d0a..65d28a5be 100644 --- a/examples/hello/hello-type.pdl +++ b/examples/hello/hello-type.pdl @@ -1,10 +1,11 @@ description: Hello world with type specification text: - Hello, -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam def: GEN parameters: - stop: + stop_sequences: - '!' include_stop_sequence: true - def: translate @@ -14,9 +15,10 @@ text: spec: int return: - "\nTranslate the sentence '${ sentence }' to ${ language }\n" - - model: watsonx/ibm/granite-20b-multilingual + - model: ibm/granite-20b-multilingual + platform: bam parameters: - stop: + stop_sequences: - "\n" include_stop_sequence: true diff --git a/examples/hello/hello.pdl b/examples/hello/hello.pdl index e687a7548..ac8930061 100644 --- a/examples/hello/hello.pdl +++ b/examples/hello/hello.pdl @@ -1,9 +1,10 @@ description: Hello world text: - Hello, -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam parameters: decoding_method: greedy - stop: + stop_sequences: - '!' include_stop_sequence: true \ No newline at end of file diff --git a/examples/hello/test.pdl b/examples/hello/test.pdl new file mode 100644 index 000000000..6bebd74b6 --- /dev/null +++ b/examples/hello/test.pdl @@ -0,0 +1,9 @@ +description: Hello world with iteration +text: +- Hello, world! +- "\n" +- repeat: + "This is your first PDL program\n" + + as: text + num_iterations: 3 diff --git a/examples/joke/Joke.pdl b/examples/joke/Joke.pdl new file mode 100644 index 000000000..c0908d581 --- /dev/null +++ b/examples/joke/Joke.pdl @@ -0,0 +1,31 @@ +description: Joke example +text: +- | + A list of good dad jokes. A indicates the punchline + Q: How does a penguin build its house? + A: Igloos it together. END + Q: Which knight invented King Arthur''s Round Table? + A: Sir Cumference. END +- repeat: + text: + - 'Q: ' + - def: JOKE + model: ibm/granite-20b-code-instruct + platform: bam + parameters: + decoding_method: sample + stop_sequences: + - '?' + - "\n" + include_stop_sequence: false + - "\nA: " + - model: ibm/granite-20b-code-instruct + platform: bam + parameters: + decoding_method: sample + stop_sequences: + - END + - "\n" + include_stop_sequence: true + - "\n" + num_iterations: 2 diff --git a/examples/meta/pdl-gen.pdl b/examples/meta/pdl-gen.pdl new file mode 100644 index 000000000..5605c1a25 --- /dev/null +++ b/examples/meta/pdl-gen.pdl @@ -0,0 +1,316 @@ +description: Teaching PDL +text: +- lang: python + code: + - | + print("Enter/Paste your content. Ctrl-D to save it.") + contents = [] + while True: + try: + line = input() + except EOFError: + break + contents.append(line + "\n") + result = ''.join(contents) + def: QUERY + contribute: [] +- model: ibm/granite-20b-code-instruct + platform: bam + parameters: + decoding_method: greedy + input: + text: + - |- + Question: Write the following prompts in PDL: + Hello world! + This is your first prompt descriptor! + + Answer: + ``` + description: Hello world! + text: + - "Hello, world!\n" + - "This is your first prompt descriptor!\n" + ``` + + Question: Turn the code into PDL: + contents = [] + while True: + try: + line = input() + except EOFError: + break + contents.append(line + "\n") + result = ''.join(contents) + + Answer: + ``` + description: Example of PDL code block + text: + - lang: python + code: + - | + contents = [] + while True: + try: + line = input() + except EOFError: + break + contents.append(line + "\n") + result = ''.join(contents) + ``` + + Question: Write a PDL script with the following text: + Hello world! + This is your first prompt descriptor! + + and with the following nested block that repeats 3 times: + This sentence repeats! + + Answer: + ``` + description: Hello world with a nested block + text: + - | + Hello, world! + This is your first prompt descriptor! + - text: + - | + This sentence repeats! + repeats: 3 + ``` + + Question: Write a PDL script with the following text: + Hello world! + This is your first prompt descriptor! + + and with the following nested block that repeats 4 times: + This sentence repeats! + + Answer: + ``` + description: Hello world with a nested block + text: + - | + Hello, world! + This is your first prompt descriptor! + - text: + - | + This sentence repeats! + repeats: 4 + ``` + + Question: Write a PDL script that makes a call to a granite model + + Answer: + ``` + description: PDL with model call + text: + - model: watsonx/ibm/granite-20b-code-instruct + parameters: + decoding_method: greedy + ``` + + Question: Write a PDL script that makes a call to a model with stop sequence '!' and stop sequences included + + Answer: + ``` + description: PDL with model call + text: + - model: watsonx/ibm/granite-20b-code-instruct + parameters: + decoding_method: greedy + stop_sequences: + - '!' + include_stop_sequence: true + ``` + + + Question: Write a PDL script that makes a call to a flan model + + Answer: + ``` + description: PDL with model call + text: + - model: "watsonx/google/flan-t5-xl" + parameters: + decoding_method: greedy + ``` + + Question: Write a PDL script that makes a call to a model with stop sequence '\n' and stop sequences not included + + Answer: + ``` + description: PDL with model call + text: + - model: watsonx/ibm/granite-20b-code-instruct + parameters: + decoding_method: greedy + stop_sequences: + - '\n' + include_stop_sequence: false + ``` + + Question: Write a PDL script with a block that has an assignment to variable NAME + + Answer: + ``` + description: PDL with model call + text: + - model: "watsonx/google/flan-t5-xl" + parameters: + decoding_method: greedy + def: NAME + ``` + + Question: Write a PDL program with a block that has show results false + + Answer: + ``` + description: PDL with model call + text: + - model: "watsonx/google/flan-t5-xl" + parameters: + decoding_method: greedy + contribute: [] + ``` + + Question: Write a PDL program with a block that does not show its results + + Answer: + ``` + description: Example of PDL code block + text: + - lang: python + code: + - | + contents = [] + while True: + try: + line = input() + except EOFError: + break + contents.append(line + "\n") + result = ''.join(contents) + contribute: [] + ``` + + Question: Write a PDL script with a block that has an assignment to variable QUERY + + Answer: + ``` + description: Example of PDL code block + text: + - lang: python + code: + - | + contents = [] + while True: + try: + line = input() + except EOFError: + break + contents.append(line + "\n") + result = ''.join(contents) + def: QUERY + ``` + + Question: Write a PDL program that calls into a model with the following few-shot examples: + "Hello Bob" + "Bye Bob" + + Answer: + ``` + description: PDL with model call + text: + - model: "watsonx/google/flan-t5-xl" + parameters: + decoding_method: greedy + input: + text: + - |- + Hello Bob + Bye Bob + ``` + + Question: Write a PDL script that calls into a model with some few-shot examples: + "The sound of music" + "OK Corral" + "The man without a name" + + Answer: + ``` + description: PDL with model call + text: + - model: "google/flan-t5-xl" + parameters: + decoding_method: greedy + input: + text: + - |- + The sound of music + OK Corral + The man without a name + ``` + + Question: Write a PDL program that calls into a model with the following few-shot examples followed by a query value: + "The wide world" + "Apples and oranges are fruit" + "one more prompt is here" + + Answer: + ``` + description: PDL with model call + text: + - model: "watsonx/google/flan-t5-xl" + parameters: + decoding_method: greedy + input: + text: + - |- + The wide world + Apples and oranges are fruit + one more prompt is here + - get: QUERY + ``` + + Question: Write a PDL program that calls into a model with the following examples followed by a location value: + "The singer sings a song" + "The dancer dances to a song" + "A bird sings a song too" + "But the birst does not dance" + + Answer: + ``` + description: PDL with model call + text: + - model: "watsonx/google/flan-t5-xl" + parameters: + decoding_method: greedy + input: + text: + - |- + The singer sings a song + The dancer dances to a song + A bird sings a song too + But the birst does not dance + - get: LOCATION + ``` + + Question: Write a PDL program that contains some Python code to prompt the user for a query. + + Answer: + ``` + description: Using a weather API and LLM to make a small weather app + text: + - lang: python + code: + - | + result = input("How can I help you?: ") + def: QUERY + ``` + + Question: + - get: QUERY + - "\n\n" + def: PDL diff --git a/examples/notebooks/notebook.ipynb b/examples/notebooks/notebook.ipynb index 9d8c5a411..6bcb698c2 100644 --- a/examples/notebooks/notebook.ipynb +++ b/examples/notebooks/notebook.ipynb @@ -38,9 +38,10 @@ "description: Model call\n", "text: \n", "- Hello,\n", - "- model: watsonx/ibm/granite-34b-code-instruct\n", + "- model: ibm/granite-34b-code-instruct\n", + " platform: bam\n", " parameters:\n", - " stop: [\"!\"]\n", + " stop_sequences: [\"!\"]\n", " include_stop_sequence: true" ] }, @@ -88,7 +89,8 @@ " read: ./ground_truth.txt\n", "text:\n", "- \"\\n${ CODE.source_code }\\n\"\n", - "- model: watsonx/ibm/granite-34b-code-instruct\n", + "- model: ibm/granite-34b-code-instruct\n", + " platform: bam\n", " def: EXPLANATION\n", " input: |\n", " Here is some info about the location of the function in the repo.\n", diff --git a/examples/notebooks/notebook_debug.ipynb b/examples/notebooks/notebook_debug.ipynb index e72b50d2d..bb913f60f 100644 --- a/examples/notebooks/notebook_debug.ipynb +++ b/examples/notebooks/notebook_debug.ipynb @@ -164,9 +164,10 @@ "description: Model call\n", "text: \n", "- Hello,\n", - "- model: watsonx/ibm/granite-34b-code-instruct\n", + "- model: ibm/granite-34b-code-instruct\n", + " platform: bam\n", " parameters:\n", - " stop: [\"!\"]\n", + " stop_sequences: [\"!\"]\n", " include_stop_sequence: true" ] }, diff --git a/examples/oddOneOut/OddOneOut.pdl b/examples/oddOneOut/OddOneOut.pdl new file mode 100644 index 000000000..af933a687 --- /dev/null +++ b/examples/oddOneOut/OddOneOut.pdl @@ -0,0 +1,40 @@ +description: Odd one out +text: +- "Pick the odd word out: skirt, dress, pen, jacket.\n" +- "skirt is clothing, dress is clothing, pen is an object, jacket is clothing.\n" +- "So the odd one is pen.\n\n" +- "Pick the odd word out: Spain, France, German, England, Singapore.\n" +- "Spain is a country, France is a country, German is a language, ...\n" +- "So the odd one is German.\n\n" +- repeat: + text: + - 'Pick the odd word out: ' + - def: OPTIONS + model: ibm/granite-20b-code-instruct + platform: bam + parameters: + decoding_method: greedy + stop_sequences: + - . + include_stop_sequence: false + - "\nNow the reasoning:\n" + - model: ibm/granite-20b-code-instruct + platform: bam + parameters: + decoding_method: greedy + stop_sequences: + - Pick the odd word + - "\n" + - So the odd one + - . + include_stop_sequence: false + - "\nNow the result:\n" + - model: ibm/granite-20b-code-instruct + platform: bam + parameters: + decoding_method: greedy + stop_sequences: + - Pick the odd word + include_stop_sequence: false + - "\n\n" + num_iterations: 2 diff --git a/examples/rag/rag.pdl b/examples/rag/rag.pdl index ea6e92462..d2083b335 100644 --- a/examples/rag/rag.pdl +++ b/examples/rag/rag.pdl @@ -43,6 +43,7 @@ text: Q: ${ TEST_PROMPT } A: ``` -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-20b-code-instruct-v2 + platform: bam parameters: - stop: ["```"] + stop_sequences: ["```"] diff --git a/examples/react/multi-agent.pdl b/examples/react/multi-agent.pdl index d30fc40aa..bd4434236 100644 --- a/examples/react/multi-agent.pdl +++ b/examples/react/multi-agent.pdl @@ -13,7 +13,7 @@ text: call: react args: question: ${ question } - model: watsonx/ibm/granite-34b-code-instruct + model: ibm/granite-34b-code-instruct - "\n" - if: ${ proposed.split('Act:') | last == verified.split('Act:') | last } then: diff --git a/examples/react/react_call.pdl b/examples/react/react_call.pdl index b310cbd78..cfa92fefa 100644 --- a/examples/react/react_call.pdl +++ b/examples/react/react_call.pdl @@ -4,4 +4,6 @@ text: - call: react args: question: How many years ago was the discoverer of the Hudson River born? - model: watsonx/ibm/granite-34b-code-instruct + model: ibm/granite-34b-code-instruct + + diff --git a/examples/react/react_fun.pdl b/examples/react/react_fun.pdl index 947e13ad0..d00b6f995 100644 --- a/examples/react/react_fun.pdl +++ b/examples/react/react_fun.pdl @@ -24,14 +24,16 @@ defs: text: - def: thought model: ${ model } + platform: bam parameters: - stop: + stop_sequences: - "Act:" include_stop_sequence: true - def: action model: ${ model } + platform: bam parameters: - stop: + stop_sequences: - "\n" parser: json spec: {name: str, arguments: obj} @@ -116,3 +118,4 @@ defs: question: ${ question } model: ${ model } + diff --git a/examples/react/wikipedia.pdl b/examples/react/wikipedia.pdl index 05061e84e..ab97327a0 100644 --- a/examples/react/wikipedia.pdl +++ b/examples/react/wikipedia.pdl @@ -22,15 +22,17 @@ text: - repeat: text: - def: thought - model: watsonx/ibm/granite-34b-code-instruct + model: ibm/granite-34b-code-instruct + platform: bam parameters: - stop: + stop_sequences: - "Act:" include_stop_sequence: true - def: action - model: watsonx/ibm/granite-34b-code-instruct + model: ibm/granite-34b-code-instruct + platform: bam parameters: - stop: + stop_sequences: - "\n" parser: json spec: {name: str, arguments: {topic: str}} diff --git a/examples/sdk/hello.pdl b/examples/sdk/hello.pdl index 4e93b0ef8..221c505d3 100644 --- a/examples/sdk/hello.pdl +++ b/examples/sdk/hello.pdl @@ -1,8 +1,9 @@ text: - Hello, -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam parameters: - stop: + stop_sequences: - '!' include_stop_sequence: true diff --git a/examples/sdk/hello_dict.py b/examples/sdk/hello_dict.py index d68ffd6db..a1ce9651e 100644 --- a/examples/sdk/hello_dict.py +++ b/examples/sdk/hello_dict.py @@ -4,8 +4,9 @@ "text": [ "Hello,", { - "model": "watsonx/ibm/granite-34b-code-instruct", - "parameters": {"stop": ["!"], "include_stop_sequence": True}, + "model": "ibm/granite-34b-code-instruct", + "platform": "bam", + "parameters": {"stop_sequences": ["!"], "include_stop_sequence": True}, }, ] } diff --git a/examples/talk/1-hello.pdl b/examples/talk/1-hello.pdl index 01ae84e44..0eaa32039 100644 --- a/examples/talk/1-hello.pdl +++ b/examples/talk/1-hello.pdl @@ -1,8 +1,9 @@ description: Model call text: - Hello, -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam parameters: - stop: ["!"] + stop_sequences: ["!"] include_stop_sequence: true diff --git a/examples/talk/11-sdg.pdl b/examples/talk/11-sdg.pdl index 7d946f96a..6ec636c25 100644 --- a/examples/talk/11-sdg.pdl +++ b/examples/talk/11-sdg.pdl @@ -1,7 +1,7 @@ description: Real-world Synthetic Data Generation (SDG) pipeline defs: teacher_sys_prompt: You are a very knowledgeable AI Assistant that will faithfully assist the user with their task. - teacher_model: watsonx/mistralai/mixtral-8x7b-instruct-v01 + teacher_model: mistralai/mixtral-8x7b-instruct-v01 teacher_template: function: sys_prompt: str @@ -66,9 +66,10 @@ defs: ${prompt_data.generation} teacher_output: model: ${teacher_model} + platform: bam input: ${teacher_input} parameters: - stop: ["${teacher_stop_token}"] + stop_sequences: ["${teacher_stop_token}"] include_stop_sequence: false max_new_tokens: ${prompt_data.max_new_tokens} parser: @@ -156,8 +157,9 @@ defs: teacher_output: model: ${teacher_model} input: ${teacher_input} + platform: bam parameters: - stop: ["${teacher_stop_token}"] + stop_sequences: ["${teacher_stop_token}"] include_stop_sequence: false max_new_tokens: ${prompt_data.max_new_tokens} parser: @@ -251,8 +253,9 @@ defs: teacher_output: model: ${teacher_model} input: ${teacher_input} + platform: bam parameters: - stop: ${ [teacher_stop_token] + prompt_data.additional_stop_tokens } + stop_sequences: ${ [teacher_stop_token] + prompt_data.additional_stop_tokens } include_stop_sequence: false max_new_tokens: ${prompt_data.max_new_tokens} parsed_answer: @@ -338,8 +341,9 @@ defs: teacher_output: model: ${teacher_model} input: ${teacher_input} + platform: bam parameters: - stop: ["${teacher_stop_token}"] + stop_sequences: ["${teacher_stop_token}"] include_stop_sequence: false max_new_tokens: ${prompt_data.max_new_tokens} parser: @@ -405,4 +409,3 @@ text: - call: filter_question_answer_pair args: qa_pairs: ${qa_pairs} - diff --git a/examples/talk/2-model-chaining.pdl b/examples/talk/2-model-chaining.pdl index 24279ec12..3d14d683e 100644 --- a/examples/talk/2-model-chaining.pdl +++ b/examples/talk/2-model-chaining.pdl @@ -1,12 +1,14 @@ description: Model chaining text: - Hello, -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam parameters: - stop: ["!"] + stop_sequences: ["!"] include_stop_sequence: true - "\nTranslate this to French\n" -- model: watsonx/ibm/granite-20b-multilingual +- model: ibm/granite-20b-multilang-lab-rc + platform: bam parameters: - stop: ["!"] + stop_sequences: ["!"] include_stop_sequence: true diff --git a/examples/talk/3-def-use.pdl b/examples/talk/3-def-use.pdl index 8032d4856..6bf378380 100644 --- a/examples/talk/3-def-use.pdl +++ b/examples/talk/3-def-use.pdl @@ -1,12 +1,13 @@ description: Variable def and use, model input text: - Hello, -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam def: name parameters: - stop: ["!"] + stop_sequences: ["!"] include_stop_sequence: false - "\n" -- model: watsonx/ibm/granite-20b-multilingual +- model: ibm/granite-20b-multilingual input: - "Translate the word ${ name | trim } to French\n" diff --git a/examples/talk/4-function.pdl b/examples/talk/4-function.pdl index 3a75fb2db..cb8c4161e 100644 --- a/examples/talk/4-function.pdl +++ b/examples/talk/4-function.pdl @@ -6,9 +6,10 @@ text: language: str return: - "\nTranslate the sentence '${ sentence }' to ${ language }.\n" - - model: watsonx/ibm/granite-20b-multilingual + - model: ibm/granite-20b-multilingual + platform: bam parameters: - stop: ["\n"] + stop_sequences: ["\n"] - call: translate args: sentence: I love Paris! diff --git a/examples/talk/5-code-eval.pdl b/examples/talk/5-code-eval.pdl index 6d0a15c29..bf599568c 100644 --- a/examples/talk/5-code-eval.pdl +++ b/examples/talk/5-code-eval.pdl @@ -7,7 +7,8 @@ defs: read: ./ground_truth.txt text: - "\n${ CODE.source_code }\n" -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam def: EXPLANATION input: | Here is some info about the location of the function in the repo. diff --git a/examples/talk/6-code-json.pdl b/examples/talk/6-code-json.pdl index 2b72fc495..5db15baea 100644 --- a/examples/talk/6-code-json.pdl +++ b/examples/talk/6-code-json.pdl @@ -6,7 +6,8 @@ defs: TRUTH: read: ./ground_truth.txt text: -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam def: EXPLANATION contribute: [] input: diff --git a/examples/talk/7-chatbot-roles.pdl b/examples/talk/7-chatbot-roles.pdl index f27439d44..5c46e54c8 100644 --- a/examples/talk/7-chatbot-roles.pdl +++ b/examples/talk/7-chatbot-roles.pdl @@ -6,10 +6,14 @@ text: text: ${ SYSTEM_CONTENT_CHAT } - "Type `quit` to exit this chatbot.\n" - repeat: - - read: - message: ">>> " - def: query - - model: watsonx/ibm/granite-13b-chat-v2 + text: + - read: + message: ">>> " + def: query + contribute: [context] + - model: ibm/granite-13b-chat-v2 + platform: bam + - "\n\n" until: ${ query == 'quit'} join: with: "\n\n" diff --git a/examples/talk/8-tools.pdl b/examples/talk/8-tools.pdl index d3deede91..9f48b933f 100644 --- a/examples/talk/8-tools.pdl +++ b/examples/talk/8-tools.pdl @@ -12,9 +12,10 @@ text: Out of 1400 participants, 400 passed the test. What percentage is that? Act: - def: action - model: watsonx/ibm/granite-8b-code-instruct + model: ibm/granite-8b-code-instruct + platform: bam parameters: - stop: ["\n"] + stop_sequences: ["\n"] parser: json spec: {name: str, arguments: {expr: str}} - if: ${ action.name == "Calc" } diff --git a/examples/talk/9-react.pdl b/examples/talk/9-react.pdl index 476ae6842..8e04288bc 100644 --- a/examples/talk/9-react.pdl +++ b/examples/talk/9-react.pdl @@ -23,18 +23,19 @@ text: - repeat: text: - def: thought - model: watsonx/ibm/granite-34b-code-instruct + model: ibm/granite-34b-code-instruct + platform: bam parameters: - stop: + stop_sequences: - "Act:" include_stop_sequence: true - def: action - model: watsonx/ibm/granite-34b-code-instruct + model: ibm/granite-34b-code-instruct + platform: bam parameters: - stop: + stop_sequences: - "\n" parser: json - spec: {name: str, arguments: {topic: str}} - def: observation if: '${ action.name == "Search" }' then: diff --git a/examples/teacher/teacher.pdl b/examples/teacher/teacher.pdl index d518b3a99..ae55d71b6 100644 --- a/examples/teacher/teacher.pdl +++ b/examples/teacher/teacher.pdl @@ -1,6 +1,6 @@ defs: teacher_sys_prompt: You are a very knowledgeable AI Assistant that will faithfully assist the user with their task. - teacher_model: watsonx/mistralai/mixtral-8x7b-instruct-v01 + teacher_model: mistralai/mixtral-8x7b-instruct-v01 teacher_template: function: sys_prompt: str @@ -65,9 +65,10 @@ defs: ${prompt_data.generation} teacher_output: model: ${teacher_model} + platform: bam input: ${teacher_input} parameters: - stop: ["${teacher_stop_token}"] + stop_sequences: ["${teacher_stop_token}"] include_stop_sequence: false max_new_tokens: ${prompt_data.max_new_tokens} parser: @@ -155,8 +156,9 @@ defs: teacher_output: model: ${teacher_model} input: ${teacher_input} + platform: bam parameters: - stop: ["${teacher_stop_token}"] + stop_sequences: ["${teacher_stop_token}"] include_stop_sequence: false max_new_tokens: ${prompt_data.max_new_tokens} parser: @@ -250,8 +252,9 @@ defs: teacher_output: model: ${teacher_model} input: ${teacher_input} + platform: bam parameters: - stop: ${ [teacher_stop_token] + prompt_data.additional_stop_tokens } + stop_sequences: ${ [teacher_stop_token] + prompt_data.additional_stop_tokens } include_stop_sequence: false max_new_tokens: ${prompt_data.max_new_tokens} parsed_answer: @@ -337,8 +340,9 @@ defs: teacher_output: model: ${teacher_model} input: ${teacher_input} + platform: bam parameters: - stop: ["${teacher_stop_token}"] + stop_sequences: ["${teacher_stop_token}"] include_stop_sequence: false max_new_tokens: ${prompt_data.max_new_tokens} parser: @@ -404,4 +408,3 @@ text: - call: filter_question_answer_pair args: qa_pairs: ${qa_pairs} -- "\n" diff --git a/examples/thing/Thing.pdl b/examples/thing/Thing.pdl new file mode 100644 index 000000000..b64b4396e --- /dev/null +++ b/examples/thing/Thing.pdl @@ -0,0 +1,19 @@ +description: Things not to forget +text: +- 'A list of things not to forget when ' +- "traveling:\n" +- repeat: + - model: ibm/granite-20b-code-instruct + platform: bam + parameters: + decoding_method: greedy + join: + with: "\n" + num_iterations: 2 +- 'The most important of these is ' +- def: ITEM + model: ibm/granite-20b-code-instruct + platform: bam + parameters: + decoding_method: greedy +- . diff --git a/examples/tools/calc.pdl b/examples/tools/calc.pdl index ffb90768d..bd14cc9b5 100644 --- a/examples/tools/calc.pdl +++ b/examples/tools/calc.pdl @@ -12,9 +12,10 @@ text: Out of 1400 participants, 400 passed the test. What percentage is that? Act: - def: action - model: watsonx/ibm/granite-8b-code-instruct + model: ibm/granite-8b-code-instruct + platform: bam parameters: - STOP_SEQUENCES: ["\n"] + stop_sequences: ["\n"] parser: json spec: {name: str, arguments: {expr: str}} - if: ${ action.name == "Calc" } diff --git a/examples/tutorial/calling_apis.pdl b/examples/tutorial/calling_apis.pdl index c3db1ff86..25cc6a432 100644 --- a/examples/tutorial/calling_apis.pdl +++ b/examples/tutorial/calling_apis.pdl @@ -4,7 +4,8 @@ text: def: QUERY message: "Ask a query: " contribute: [] -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam input: | Question: What is the weather in London? London @@ -14,7 +15,7 @@ text: Lagos Question: ${ QUERY } parameters: - stop: + stop_sequences: - Question - What - '!' @@ -30,7 +31,8 @@ text: parser: json contribute: [] -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam input: | Explain the weather from the following JSON: ${ WEATHER } diff --git a/examples/tutorial/calling_llm.pdl b/examples/tutorial/calling_llm.pdl index dcecd7c44..65f2352d6 100644 --- a/examples/tutorial/calling_llm.pdl +++ b/examples/tutorial/calling_llm.pdl @@ -1,9 +1,10 @@ description: Hello world calling a model text: - Hello, -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam parameters: decoding_method: greedy - stop: + stop_sequences: - '!' include_stop_sequence: true \ No newline at end of file diff --git a/examples/tutorial/calling_llm_with_input.pdl b/examples/tutorial/calling_llm_with_input.pdl index f9134b9ed..0074df3d6 100644 --- a/examples/tutorial/calling_llm_with_input.pdl +++ b/examples/tutorial/calling_llm_with_input.pdl @@ -1,6 +1,7 @@ description: Hello world calling a model text: - "Hello, " -- model: watsonx/ibm/granite-20b-multilingual +- model: ibm/granite-20b-multilingual + platform: bam input: Translate the word 'world' to French diff --git a/examples/tutorial/conditionals_loops.pdl b/examples/tutorial/conditionals_loops.pdl index 0ac35cbd5..a7e1e194c 100644 --- a/examples/tutorial/conditionals_loops.pdl +++ b/examples/tutorial/conditionals_loops.pdl @@ -15,4 +15,4 @@ text: text: - read: message: "Why not?\n" - until: ${ eval == 'yes'} \ No newline at end of file + until: ${ eval == 'yes'} diff --git a/examples/tutorial/data_block.pdl b/examples/tutorial/data_block.pdl index a81c2d267..54952be79 100644 --- a/examples/tutorial/data_block.pdl +++ b/examples/tutorial/data_block.pdl @@ -6,7 +6,8 @@ defs: TRUTH: read: ./ground_truth.txt lastOf: -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam def: EXPLANATION input: | diff --git a/examples/tutorial/function_definition.pdl b/examples/tutorial/function_definition.pdl index f104b6778..37f0b3628 100644 --- a/examples/tutorial/function_definition.pdl +++ b/examples/tutorial/function_definition.pdl @@ -6,9 +6,10 @@ text: language: str return: - "\nTranslate the sentence '${ sentence }' to ${ language }.\n" - - model: watsonx/ibm/granite-20b-multilingual + - model: ibm/granite-20b-multilingual + platform: bam parameters: - stop: ["\n"] + stop_sequences: ["\n"] - call: translate args: sentence: I love Paris! diff --git a/examples/tutorial/gen-data.pdl b/examples/tutorial/gen-data.pdl index 0d7a7c121..d34e9ddd5 100644 --- a/examples/tutorial/gen-data.pdl +++ b/examples/tutorial/gen-data.pdl @@ -5,7 +5,8 @@ defs: parser: yaml spec: { questions: [str], answers: [obj] } text: - - model: watsonx/ibm/granite-20b-code-instruct + - model: ibm/granite-20b-code-instruct + platform: bam def: model_output spec: {name: str, age: int} input: @@ -22,7 +23,7 @@ text: and set them appropriately. Write the age in letters. parser: yaml parameters: - stop: + stop_sequences: - '}' include_stop_sequence: true \ No newline at end of file diff --git a/examples/tutorial/grouping_definitions.pdl b/examples/tutorial/grouping_definitions.pdl index 49623a280..135dae3ed 100644 --- a/examples/tutorial/grouping_definitions.pdl +++ b/examples/tutorial/grouping_definitions.pdl @@ -6,9 +6,10 @@ defs: language: str return: - "\nTranslate the sentence '${ sentence }' to ${ language }.\n" - - model: watsonx/ibm/granite-20b-multilingual + - model: ibm/granite-20b-multilingual + platform: bam parameters: - stop: ["\n"] + stop_sequences: ["\n"] text: - call: translate args: diff --git a/examples/tutorial/include.pdl b/examples/tutorial/include.pdl index 733ccc080..80a40d99b 100644 --- a/examples/tutorial/include.pdl +++ b/examples/tutorial/include.pdl @@ -13,7 +13,8 @@ text: text: - | ${ prompt } - - model: watsonx/ibm/granite-13b-chat-v2 + - model: ibm/granite-13b-chat-v2 + platform: bam parameters: decoding_method: sample max_new_tokens: 512 diff --git a/examples/tutorial/model_chaining.pdl b/examples/tutorial/model_chaining.pdl index 24279ec12..3dfd12390 100644 --- a/examples/tutorial/model_chaining.pdl +++ b/examples/tutorial/model_chaining.pdl @@ -1,12 +1,14 @@ description: Model chaining text: - Hello, -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam parameters: - stop: ["!"] + stop_sequences: ["!"] include_stop_sequence: true - "\nTranslate this to French\n" -- model: watsonx/ibm/granite-20b-multilingual +- model: ibm/granite-20b-multilingual + platform: bam parameters: - stop: ["!"] + stop_sequences: ["!"] include_stop_sequence: true diff --git a/examples/tutorial/muting_block_output.pdl b/examples/tutorial/muting_block_output.pdl index 99a7ef4b2..f3b04f946 100644 --- a/examples/tutorial/muting_block_output.pdl +++ b/examples/tutorial/muting_block_output.pdl @@ -6,9 +6,10 @@ defs: language: str return: - "\nTranslate the sentence '${ sentence }' to ${ language }.\n" - - model: watsonx/ibm/granite-20b-multilingual + - model: ibm/granite-20b-multilingual + platform: bam parameters: - stop: ["\n"] + stop_sequences: ["\n"] text: - call: translate contribute: [] diff --git a/examples/tutorial/variable_def_use.pdl b/examples/tutorial/variable_def_use.pdl index 2ab30afdb..1e25018b4 100644 --- a/examples/tutorial/variable_def_use.pdl +++ b/examples/tutorial/variable_def_use.pdl @@ -1,11 +1,12 @@ description: Hello world with variable def and use text: - Hello, -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct def: GEN + platform: bam parameters: decoding_method: greedy - stop: + stop_sequences: - '!' include_stop_sequence: true - "\nGEN is equal to: ${ GEN }" \ No newline at end of file diff --git a/examples/weather/weather.pdl b/examples/weather/weather.pdl index d8f7f6ada..4d7c6917d 100644 --- a/examples/weather/weather.pdl +++ b/examples/weather/weather.pdl @@ -4,7 +4,8 @@ text: def: QUERY message: "Ask a query: " contribute: [] -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam input: | Question: What is the weather in London? London @@ -14,7 +15,7 @@ text: Lagos Question: ${ QUERY } parameters: - stop: + stop_sequences: - Question - What - '!' @@ -30,7 +31,8 @@ text: parser: json contribute: [] -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam input: | Explain the weather from the following JSON: ${ WEATHER } From 036584dc351979647c90913b81a1dc663da3f6cb Mon Sep 17 00:00:00 2001 From: Mandana Vaziri Date: Tue, 1 Oct 2024 16:07:05 -0400 Subject: [PATCH 02/24] updated bam branch Signed-off-by: Mandana Vaziri --- examples/cldk/cldk-assistant.pdl | 2 +- examples/hello/test.pdl | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/cldk/cldk-assistant.pdl b/examples/cldk/cldk-assistant.pdl index 46b94b8a7..2bb67cb37 100644 --- a/examples/cldk/cldk-assistant.pdl +++ b/examples/cldk/cldk-assistant.pdl @@ -273,7 +273,7 @@ text: result, _, _, _ = process_prog(state, empty_scope, data) until: ${ query == 'quit' } - as: text + diff --git a/examples/hello/test.pdl b/examples/hello/test.pdl index 6bebd74b6..1af38fdda 100644 --- a/examples/hello/test.pdl +++ b/examples/hello/test.pdl @@ -4,6 +4,4 @@ text: - "\n" - repeat: "This is your first PDL program\n" - - as: text num_iterations: 3 From 90ce0b548906f64f8a01f07533f7962b1e53d134 Mon Sep 17 00:00:00 2001 From: Mandana Vaziri Date: Tue, 1 Oct 2024 16:25:04 -0400 Subject: [PATCH 03/24] readme changes Signed-off-by: Mandana Vaziri --- README.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 69f3f531a..8fe245290 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,8 @@ you can use the `--sandbox` flag which runs the interpreter in a docker containe and all code is executed locally. To use the `--sandbox` flag, you need to have a docker daemon running, such as [Rancher Desktop](https://rancherdesktop.io). +Note that the `--sandbox` flag is currently not available to BAM users. + 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 useful for debugging. @@ -118,10 +120,11 @@ In PDL, we can write some YAML to create a prompt and call an LLM: description: Hello world text: - Hello, -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam parameters: decoding_method: greedy - stop: + stop_sequences: - '!' include_stop_sequence: true ``` @@ -210,7 +213,8 @@ defs: parser: yaml text: - "\n${ CODE.source_code }\n" -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam input: - | Here is some info about the location of the function in the repo. @@ -267,7 +271,8 @@ defs: read: ./ground_truth.txt text: - "\n${ CODE.source_code }\n" -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam def: EXPLANATION input: | Here is some info about the location of the function in the repo. @@ -339,7 +344,8 @@ defs: TRUTH: read: ./ground_truth.txt text: -- model: watsonx/ibm/granite-34b-code-instruct +- model: ibm/granite-34b-code-instruct + platform: bam def: EXPLANATION contribute: [] input: From 60b2668c15582ed73bd78c21eac626dc110526d2 Mon Sep 17 00:00:00 2001 From: Mandana Vaziri Date: Thu, 3 Oct 2024 21:43:39 -0400 Subject: [PATCH 04/24] examples Signed-off-by: Mandana Vaziri --- examples/arith/Arith-simple.pdl | 4 ++-- examples/arith/arith.pdl | 6 +++--- examples/code/code-eval.pdl | 2 +- examples/code/code-json.pdl | 2 +- examples/code/code.pdl | 2 +- examples/demo/1-gen-data.pdl | 2 +- examples/demo/3-weather.pdl | 5 +++-- examples/earth/Earth.pdl | 4 ++-- examples/fibonacci/fib.pdl | 4 ++-- examples/talk/1-hello.pdl | 2 +- 10 files changed, 17 insertions(+), 16 deletions(-) diff --git a/examples/arith/Arith-simple.pdl b/examples/arith/Arith-simple.pdl index 6b04ce697..45ce21baf 100644 --- a/examples/arith/Arith-simple.pdl +++ b/examples/arith/Arith-simple.pdl @@ -10,7 +10,7 @@ text: - repeat: text: - def: REASON_OR_CALC - model: ibm/granite-20b-code-instruct + model: ibm/granite-8b-instruct-preview-4k platform: bam parameters: stop_sequences: @@ -20,7 +20,7 @@ text: then: text: - def: EXPR - model: ibm/granite-20b-code-instruct + model: ibm/granite-8b-instruct-preview-4k platform: bam parameters: stop_sequences: diff --git a/examples/arith/arith.pdl b/examples/arith/arith.pdl index cc6bd78c9..6ed4eb6e6 100644 --- a/examples/arith/arith.pdl +++ b/examples/arith/arith.pdl @@ -6,7 +6,7 @@ text: text: - "\nQuestion: " - def: QUESTION - model: ibm/granite-34b-code-instruct + model: ibm/granite-8b-instruct-preview-4k platform: bam parameters: stop_sequences: @@ -17,7 +17,7 @@ text: - repeat: text: - def: REASON_OR_CALC - model: ibm/granite-34b-code-instruct + model: ibm/granite-8b-instruct-preview-4k platform: bam parameters: stop_sequences: @@ -28,7 +28,7 @@ text: then: text: - def: EXPR - model: ibm/granite-34b-code-instruct + model: ibm/granite-8b-instruct-preview-4k platform: bam parameters: stop_sequences: diff --git a/examples/code/code-eval.pdl b/examples/code/code-eval.pdl index bf599568c..55fbc9543 100644 --- a/examples/code/code-eval.pdl +++ b/examples/code/code-eval.pdl @@ -7,7 +7,7 @@ defs: read: ./ground_truth.txt text: - "\n${ CODE.source_code }\n" -- model: ibm/granite-34b-code-instruct +- model: ibm/granite-8b-instruct-preview-4k platform: bam def: EXPLANATION input: | diff --git a/examples/code/code-json.pdl b/examples/code/code-json.pdl index 7d2d5cd5d..c0eedecfd 100644 --- a/examples/code/code-json.pdl +++ b/examples/code/code-json.pdl @@ -6,7 +6,7 @@ defs: TRUTH: read: ./ground_truth.txt text: -- model: ibm/granite-34b-code-instruct +- model: ibm/granite-8b-instruct-preview-4k platform: bam def: EXPLANATION contribute: [] diff --git a/examples/code/code.pdl b/examples/code/code.pdl index 8d6ea7f57..632224902 100644 --- a/examples/code/code.pdl +++ b/examples/code/code.pdl @@ -5,7 +5,7 @@ defs: parser: yaml text: - "\n${ CODE.source_code }\n" -- model: ibm/granite-34b-code-instruct +- model: ibm/granite-8b-instruct-preview-4k platform: bam input: - | diff --git a/examples/demo/1-gen-data.pdl b/examples/demo/1-gen-data.pdl index 08e22363c..bca38bfc9 100644 --- a/examples/demo/1-gen-data.pdl +++ b/examples/demo/1-gen-data.pdl @@ -5,7 +5,7 @@ defs: parser: yaml spec: { questions: [str], answers: [obj] } text: - - model: ibm/granite-20b-code-instruct + - model: ibm/granite-8b-instruct-preview-4k platform: bam def: model_output spec: {name: str, age: int} diff --git a/examples/demo/3-weather.pdl b/examples/demo/3-weather.pdl index 414e7e815..d26327ff5 100644 --- a/examples/demo/3-weather.pdl +++ b/examples/demo/3-weather.pdl @@ -4,7 +4,7 @@ text: def: QUERY message: "Ask a query: " contribute: [] -- model: ibm/granite-34b-code-instruct +- model: ibm/granite-8b-instruct-preview-4k platform: bam input: | Question: What is the weather in London? @@ -19,6 +19,7 @@ text: - Question - What - '!' + - "\n" include_stop_sequence: false def: LOCATION contribute: [] @@ -31,7 +32,7 @@ text: parser: json contribute: [] -- model: ibm/granite-34b-code-instruct +- model: ibm/granite-8b-instruct-preview-4k platform: bam input: | Explain the weather from the following JSON: diff --git a/examples/earth/Earth.pdl b/examples/earth/Earth.pdl index 57719f32c..83c14c118 100644 --- a/examples/earth/Earth.pdl +++ b/examples/earth/Earth.pdl @@ -2,7 +2,7 @@ description: Earth circumference question text: - 'What is the circumference of the earth? I believe the best person to answer this question is ' - def: EXPERT - model: ibm/granite-34b-code-instruct + model: ibm/granite-8b-instruct-preview-4k platform: bam parameters: stop_sequences: @@ -11,5 +11,5 @@ text: - '. Indeed, ' - get: EXPERT - ' addressed this question: ' -- model: ibm/granite-34b-code-instruct +- model: ibm/granite-8b-instruct-preview-4k platform: bam \ No newline at end of file diff --git a/examples/fibonacci/fib.pdl b/examples/fibonacci/fib.pdl index bb9dd089f..fbb5ca442 100644 --- a/examples/fibonacci/fib.pdl +++ b/examples/fibonacci/fib.pdl @@ -1,7 +1,7 @@ description: Fibonacci text: - def: CODE - model: ibm/granite-20b-code-instruct + model: ibm/granite-8b-instruct-preview-4k platform: bam input: "Write a Python function to compute the Fibonacci sequence\n\n" @@ -28,5 +28,5 @@ text: - 'The result is: ' - get: RESULT - "\n\nExplain what the above code does and what the result means\n\n" -- model: ibm/granite-20b-code-instruct +- model: ibm/granite-8b-instruct-preview-4k platform: bam \ No newline at end of file diff --git a/examples/talk/1-hello.pdl b/examples/talk/1-hello.pdl index 0eaa32039..9ecb9fa27 100644 --- a/examples/talk/1-hello.pdl +++ b/examples/talk/1-hello.pdl @@ -1,7 +1,7 @@ description: Model call text: - Hello, -- model: ibm/granite-34b-code-instruct +- model: ibm/granite-8b-instruct-preview-4k platform: bam parameters: stop_sequences: ["!"] From 8f00a5efd9aa80021e3abb8b5b7e34e79454026c Mon Sep 17 00:00:00 2001 From: Mandana Vaziri Date: Sun, 6 Oct 2024 06:29:23 -0400 Subject: [PATCH 05/24] examples Signed-off-by: Mandana Vaziri --- examples/arith/Arith-simple.pdl | 6 ++--- examples/arith/arith.pdl | 46 --------------------------------- examples/arith/example1.txt | 13 ++++++++++ examples/arith/example2.txt | 12 +++++++++ 4 files changed, 28 insertions(+), 49 deletions(-) delete mode 100644 examples/arith/arith.pdl create mode 100644 examples/arith/example1.txt create mode 100644 examples/arith/example2.txt diff --git a/examples/arith/Arith-simple.pdl b/examples/arith/Arith-simple.pdl index 45ce21baf..ff30702bd 100644 --- a/examples/arith/Arith-simple.pdl +++ b/examples/arith/Arith-simple.pdl @@ -14,9 +14,9 @@ text: platform: bam parameters: stop_sequences: - - '<<' + - '{' include_stop_sequence: true - - if: ${ REASON_OR_CALC.endswith("<<") } + - if: ${ REASON_OR_CALC.endswith("{") } then: text: - def: EXPR @@ -32,6 +32,6 @@ text: - def: RESULT lang: python code: result = ${ EXPR } - - ' >>' + - '}' until: ${ "The answer is" in REASON_OR_CALC } - "\n" \ No newline at end of file diff --git a/examples/arith/arith.pdl b/examples/arith/arith.pdl deleted file mode 100644 index 6ed4eb6e6..000000000 --- a/examples/arith/arith.pdl +++ /dev/null @@ -1,46 +0,0 @@ -description: Math Problems -text: -- read: example1.txt -- read: example2.txt -- repeat: - text: - - "\nQuestion: " - - def: QUESTION - model: ibm/granite-8b-instruct-preview-4k - platform: bam - parameters: - stop_sequences: - - Answer - - "?" - include_stop_sequence: true - - "\nAnswer: Let's think step by step.\n" - - repeat: - text: - - def: REASON_OR_CALC - model: ibm/granite-8b-instruct-preview-4k - platform: bam - parameters: - stop_sequences: - - '<<' - - "Question" - include_stop_sequence: true - - if: ${ REASON_OR_CALC.endswith("<<") } - then: - text: - - def: EXPR - model: ibm/granite-8b-instruct-preview-4k - platform: bam - parameters: - stop_sequences: - - '=' - - "\n" - - "Question" - include_stop_sequence: false - - '= ' - - def: RESULT - lang: python - code: result = ${ EXPR } - - ' >>' - until: ${ "The answer is" in REASON_OR_CALC } - - "\n\n" - num_iterations: 3 \ No newline at end of file diff --git a/examples/arith/example1.txt b/examples/arith/example1.txt new file mode 100644 index 000000000..e0c08f857 --- /dev/null +++ b/examples/arith/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/arith/example2.txt b/examples/arith/example2.txt new file mode 100644 index 000000000..60d8ad10c --- /dev/null +++ b/examples/arith/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. From fec45637b3b3f51bb8550e7d100d0044e381c1c8 Mon Sep 17 00:00:00 2001 From: Mandana Vaziri Date: Mon, 7 Oct 2024 13:23:14 -0400 Subject: [PATCH 06/24] examples Signed-off-by: Mandana Vaziri --- examples/chatbot/chatbot.pdl | 9 +- examples/cldk/cldk-assistant.pdl | 173 ++++-------------------- examples/demo/3-weather.pdl | 7 +- examples/fibonacci/fib.pdl | 9 +- examples/hello/hello-data.pdl | 2 +- examples/hello/hello-model-chaining.pdl | 2 +- examples/hello/hello-model-input.pdl | 2 +- examples/hello/hello-parser-json.pdl | 2 +- examples/hello/hello-parser-regex.pdl | 2 +- examples/hello/hello-roles-array.pdl | 2 +- examples/hello/hello-type.pdl | 2 +- examples/hello/hello.pdl | 4 +- examples/joke/Joke.pdl | 4 +- examples/meta/pdl-gen.pdl | 2 +- examples/oddOneOut/OddOneOut.pdl | 26 ++-- examples/react/multi-agent.pdl | 5 +- examples/react/react_call.pdl | 2 +- examples/react/react_fun.pdl | 2 + examples/react/wikipedia.pdl | 8 +- examples/talk/1-hello.pdl | 2 +- examples/talk/10-multi-agent.pdl | 4 +- examples/talk/2-model-chaining.pdl | 4 +- examples/talk/3-def-use.pdl | 8 +- examples/talk/5-code-eval.pdl | 2 +- examples/talk/6-code-json.pdl | 2 +- examples/talk/8-tools.pdl | 5 + examples/talk/9-react.pdl | 18 +-- examples/talk/react_fun.pdl | 9 +- examples/thing/Thing.pdl | 4 +- examples/tools/calc.pdl | 8 +- examples/weather/weather.pdl | 15 +- 31 files changed, 123 insertions(+), 223 deletions(-) diff --git a/examples/chatbot/chatbot.pdl b/examples/chatbot/chatbot.pdl index 54eb0c06b..ba62ad3a7 100644 --- a/examples/chatbot/chatbot.pdl +++ b/examples/chatbot/chatbot.pdl @@ -2,15 +2,10 @@ description: chatbot text: - read: message: "What is your query?\n" -<<<<<<< HEAD contribute: [context] -======= - contribute: [] ->>>>>>> 808f1a1 (merge) - repeat: text: - - model: ibm/granite-13b-chat-v2 - platform: bam + - model: watsonx/ibm/granite-13b-chat-v2 - read: def: eval message: "\nIs this a good answer[yes/no]?\n" @@ -20,9 +15,7 @@ text: text: - read: message: "Why not?\n" - contribute: [] until: ${ eval == 'yes'} - diff --git a/examples/cldk/cldk-assistant.pdl b/examples/cldk/cldk-assistant.pdl index 2bb67cb37..351843557 100644 --- a/examples/cldk/cldk-assistant.pdl +++ b/examples/cldk/cldk-assistant.pdl @@ -14,11 +14,11 @@ text: from cldk import CLDK from cldk.models.java.models import * - # Initialize the Codellm-DevKit object with the project directory, langguage, and backend. + # Initialize the Codellm-DevKit object with the project directory, language, and backend. cldk = CLDK("java") cldk_state = cldk.analysis( project_path="${ project }", # Change this to the path of the project you want to analyze. - # langguage="java", # The langguage of the project. + # language="java", # The language of the project. # backend="codeanalyzer", # The backend to use for the analysis. # analysis_db="/tmp", # A temporary directory to store the analysis results. # sdg=True, # Generate the System Dependence Graph (SDG) for the project. @@ -42,7 +42,7 @@ text: Answer: ``` text: - - langg: python + - lang: python code: - | classes = PDL_SESSION.cldk_state.get_classes().keys() @@ -53,7 +53,7 @@ text: Answer: ``` text: - - langg: python + - lang: python code: - | constructors = PDL_SESSION.cldk_state.get_constructors("org.ibm.App") @@ -64,7 +64,7 @@ text: Answer: ``` text: - - langg: python + - lang: python code: - | fields = PDL_SESSION.cldk_state.get_fields("org.ibm.App") @@ -76,7 +76,7 @@ text: Answer: ``` text: - - langg: python + - lang: python code: - | methods = PDL_SESSION.cldk_state.get_methods_in_class("org.ibm.App") @@ -87,7 +87,7 @@ text: Answer: ``` text: - - langg: python + - lang: python code: - | graph = PDL_SESSION.cldk_state.get_class_call_graph("org.ibm.App", method_name=None) @@ -98,7 +98,7 @@ text: Answer: ``` text: - - langg: python + - lang: python code: - | method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") @@ -109,7 +109,7 @@ text: Answer: ``` text: - - langg: python + - lang: python code: - | method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") @@ -122,7 +122,7 @@ text: Answer: ``` text: - - langg: python + - lang: python code: - | method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") @@ -140,143 +140,26 @@ text: stop_sequence: ["Question"] include_stop_sequence: false - "\n\n***Executing the above PDL code:\n\n" - - langg: python + - lang: python contribute: [] - - "\n***Generating PDL code for your query:\n" - - if: ${ query != 'quit'} - then: - - model: ibm/granite-20b-code-instruct - platform: bam - def: PDL - input: - - | - Question: What are all the classes? - Answer: - ``` - text: - - lang: python - code: - - | - classes = PDL_SESSION.cldk_state.get_classes().keys() - result = ", ".join(classes) - ``` - - Question: What are all the constructors of class org.ibm.App? - Answer: - ``` - text: - - lang: python - code: - - | - constructors = PDL_SESSION.cldk_state.get_constructors("org.ibm.App") - result = ", ".join(constructors) - ``` - - Question: What are all the fields of class org.ibm.App? - Answer: - ``` - text: - - lang: python - code: - - | - fields = PDL_SESSION.cldk_state.get_fields("org.ibm.App") - names = sum([f.variables for f in fields], []) - result = ", ".join(names) - ``` - - Question: What are all the methods of class org.ibm.App? - Answer: - ``` - text: - - lang: python - code: - - | - methods = PDL_SESSION.cldk_state.get_methods_in_class("org.ibm.App") - result = ", ".join(methods) - ``` - - Question: Show me the call graph of class "org.ibm.App" - Answer: - ``` - text: - - lang: python - code: - - | - graph = PDL_SESSION.cldk_state.get_class_call_graph("org.ibm.App", method_name=None) - result = graph - ``` - - Question: What is the code of method Foo(string) of class org.ibm.App? - Answer: - ``` - text: - - lang: python - code: - - | - method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") - result = method.code - ``` - - Question: Generate a summary for method Foo(string) of class org.ibm.App - Answer: - ``` - text: - - lang: python - code: - - | - method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") - result = method - - "\n\nGenerate a summary of method Foo\n\n" - - model: meta-llama/llama-3-1-70b-instruct - platform: bam - ``` - - Question: Generate a different comment for method Foo(string) in class org.ibm.App? - Answer: - ``` - text: - - lang: python - code: - - | - method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") - result = method - - "\n\nGenerate a different comment for method Foo(string)\n\n" - - model: meta-llama/llama-3-1-70b-instruct - platform: bam - ``` - - If the query contains something about a field be sure to call a model. - - Question: ${ query } - - - parameters: - stop_sequences: ["Question"] - include_stop_sequence: false - - "\n\n***Executing the above PDL code:\n\n" - - lang: python - contribute: [result] - code: | - from pdl import pdl_ast, pdl_interpreter - from pdl.pdl_ast import Program - from pdl.pdl_interpreter import process_prog - from pdl.pdl_interpreter import InterpreterState - from pdl.pdl_interpreter import empty_scope - import re - import yaml - s = """'${ PDL }'""" - print(s) - pdl = s.split("```")[1] - obj = yaml.safe_load(pdl) - state = InterpreterState() - data = Program.model_validate(obj) - - result, _, _, _ = process_prog(state, empty_scope, data) + code: | + from pdl import pdl_ast, pdl_interpreter + from pdl.pdl_ast import Program + from pdl.pdl_interpreter import process_prog + from pdl.pdl_interpreter import InterpreterState + from pdl.pdl_interpreter import empty_scope + import re + import yaml + s = """'${ PDL }'""" + print(s) + pdl = s.split("```")[1] + obj = yaml.safe_load(pdl) + state = InterpreterState() + data = Program.model_validate(obj) + + result, _, _, _ = process_prog(state, empty_scope, data) until: ${ query == 'quit' } - - - - + \ No newline at end of file diff --git a/examples/demo/3-weather.pdl b/examples/demo/3-weather.pdl index d26327ff5..b49ecbbfa 100644 --- a/examples/demo/3-weather.pdl +++ b/examples/demo/3-weather.pdl @@ -7,12 +7,13 @@ text: - model: ibm/granite-8b-instruct-preview-4k platform: bam input: | + Extract the location from the question. Question: What is the weather in London? - London + Answer: London Question: What's the weather in Paris? - Paris + Answer: Paris Question: Tell me the weather in Lagos? - Lagos + Answer: Lagos Question: ${ QUERY } parameters: stop_sequences: diff --git a/examples/fibonacci/fib.pdl b/examples/fibonacci/fib.pdl index fbb5ca442..e80fdd52b 100644 --- a/examples/fibonacci/fib.pdl +++ b/examples/fibonacci/fib.pdl @@ -11,9 +11,7 @@ text: code: | import random result = random.randint(1, 20) -- "\nNow computing fib(" -- get: N -- ")\n" +- "\nNow computing fib(${ N })\n" - def: EXTRACTED lang: python code: | @@ -23,10 +21,9 @@ text: lang: python code: | ${ EXTRACTED } - result = fib(${ N }) + result = fibonacci(${ N }) contribute: [] -- 'The result is: ' -- get: RESULT +- 'The result is: ${ RESULT }' - "\n\nExplain what the above code does and what the result means\n\n" - model: ibm/granite-8b-instruct-preview-4k platform: bam \ No newline at end of file diff --git a/examples/hello/hello-data.pdl b/examples/hello/hello-data.pdl index 285e86bdd..86d744a9d 100644 --- a/examples/hello/hello-data.pdl +++ b/examples/hello/hello-data.pdl @@ -1,4 +1,4 @@ -# Call with pdl --data '"something": "ABC"' +# Call with pdl --data '"something": "ABC"' hello-data.pdl description: Hello world with data text: - def: stutter diff --git a/examples/hello/hello-model-chaining.pdl b/examples/hello/hello-model-chaining.pdl index d8c50f152..1f0b6d4b4 100644 --- a/examples/hello/hello-model-chaining.pdl +++ b/examples/hello/hello-model-chaining.pdl @@ -1,7 +1,7 @@ description: Hello world showing model chaining text: - Hello, -- model: ibm/granite-34b-code-instruct +- model: ibm/granite-8b-instruct-preview-4k platform: bam parameters: decoding_method: greedy diff --git a/examples/hello/hello-model-input.pdl b/examples/hello/hello-model-input.pdl index b77cef8c0..e107f189b 100644 --- a/examples/hello/hello-model-input.pdl +++ b/examples/hello/hello-model-input.pdl @@ -1,6 +1,6 @@ description: Hello world with model input text: -- model: ibm/granite-34b-code-instruct +- model: ibm/granite-8b-instruct-preview-4k platform: bam input: "Hello," parameters: diff --git a/examples/hello/hello-parser-json.pdl b/examples/hello/hello-parser-json.pdl index fa037212d..8a63c0eb6 100644 --- a/examples/hello/hello-parser-json.pdl +++ b/examples/hello/hello-parser-json.pdl @@ -5,7 +5,7 @@ defs: parser: yaml spec: { "questions": ["str"], "answers": ["obj"] } text: - - model: ibm/granite-34b-code-instruct + - model: ibm/granite-8b-instruct-preview-4k platform: bam def: model_output spec: {"name": str, "age": int} diff --git a/examples/hello/hello-parser-regex.pdl b/examples/hello/hello-parser-regex.pdl index 68e1e17ea..dc3219e7c 100644 --- a/examples/hello/hello-parser-regex.pdl +++ b/examples/hello/hello-parser-regex.pdl @@ -1,6 +1,6 @@ description: Hello world with parser using regex text: -- model: ibm/granite-34b-code-instruct +- model: ibm/granite-8b-instruct-preview-4k platform: bam input: "Hello," parameters: diff --git a/examples/hello/hello-roles-array.pdl b/examples/hello/hello-roles-array.pdl index 1450a389e..b456afa9b 100644 --- a/examples/hello/hello-roles-array.pdl +++ b/examples/hello/hello-roles-array.pdl @@ -7,7 +7,7 @@ text: - role: user content: Write a Python function that implement merge sort. contribute: [] -- model: ibm/granite-8b-code-instruct +- model: ibm/granite-8b-instruct-preview-4k platform: bam input: ${ prompt } diff --git a/examples/hello/hello-type.pdl b/examples/hello/hello-type.pdl index 65d28a5be..09ac31a8c 100644 --- a/examples/hello/hello-type.pdl +++ b/examples/hello/hello-type.pdl @@ -1,7 +1,7 @@ description: Hello world with type specification text: - Hello, -- model: ibm/granite-34b-code-instruct +- model: ibm/granite-8b-instruct-preview-4k platform: bam def: GEN parameters: diff --git a/examples/hello/hello.pdl b/examples/hello/hello.pdl index ac8930061..8bc00a4b3 100644 --- a/examples/hello/hello.pdl +++ b/examples/hello/hello.pdl @@ -1,7 +1,7 @@ description: Hello world text: -- Hello, -- model: ibm/granite-34b-code-instruct +- "Hello\n" +- model: ibm/granite-8b-instruct-preview-4k platform: bam parameters: decoding_method: greedy diff --git a/examples/joke/Joke.pdl b/examples/joke/Joke.pdl index c0908d581..db930ce00 100644 --- a/examples/joke/Joke.pdl +++ b/examples/joke/Joke.pdl @@ -10,7 +10,7 @@ text: text: - 'Q: ' - def: JOKE - model: ibm/granite-20b-code-instruct + model: ibm/granite-8b-instruct-preview-4k platform: bam parameters: decoding_method: sample @@ -19,7 +19,7 @@ text: - "\n" include_stop_sequence: false - "\nA: " - - model: ibm/granite-20b-code-instruct + - model: ibm/granite-8b-instruct-preview-4k platform: bam parameters: decoding_method: sample diff --git a/examples/meta/pdl-gen.pdl b/examples/meta/pdl-gen.pdl index 5605c1a25..6e60fc415 100644 --- a/examples/meta/pdl-gen.pdl +++ b/examples/meta/pdl-gen.pdl @@ -14,7 +14,7 @@ text: result = ''.join(contents) def: QUERY contribute: [] -- model: ibm/granite-20b-code-instruct +- model: ibm/granite-8b-instruct-preview-4k platform: bam parameters: decoding_method: greedy diff --git a/examples/oddOneOut/OddOneOut.pdl b/examples/oddOneOut/OddOneOut.pdl index af933a687..2cf80ad44 100644 --- a/examples/oddOneOut/OddOneOut.pdl +++ b/examples/oddOneOut/OddOneOut.pdl @@ -1,24 +1,26 @@ description: Odd one out text: -- "Pick the odd word out: skirt, dress, pen, jacket.\n" -- "skirt is clothing, dress is clothing, pen is an object, jacket is clothing.\n" -- "So the odd one is pen.\n\n" -- "Pick the odd word out: Spain, France, German, England, Singapore.\n" -- "Spain is a country, France is a country, German is a language, ...\n" -- "So the odd one is German.\n\n" +- "Question: Pick the odd word out:\n" +- "skirt, dress, pen, jacket.\n" +- "Reasoning: skirt is clothing, dress is clothing, pen is an object, jacket is clothing.\n" +- "Answer: So the odd one is pen.\n\n" +- "Question: Pick the odd word out:\n" +- "Spain, France, German, England, Singapore.\n" +- "Reasoning: Spain is a country, France is a country, German is a language, ...\n" +- "Answer: So the odd one is German.\n\n" - repeat: text: - - 'Pick the odd word out: ' + - "Question: Pick the odd word out:\n" - def: OPTIONS - model: ibm/granite-20b-code-instruct + model: ibm/granite-3b-instruct-preview platform: bam parameters: decoding_method: greedy stop_sequences: - . include_stop_sequence: false - - "\nNow the reasoning:\n" - - model: ibm/granite-20b-code-instruct + - "\nReasoning:\n" + - model: ibm/granite-3b-instruct-preview platform: bam parameters: decoding_method: greedy @@ -28,8 +30,8 @@ text: - So the odd one - . include_stop_sequence: false - - "\nNow the result:\n" - - model: ibm/granite-20b-code-instruct + - "\nResult:\n" + - model: ibm/granite-3b-instruct-preview platform: bam parameters: decoding_method: greedy diff --git a/examples/react/multi-agent.pdl b/examples/react/multi-agent.pdl index bd4434236..2dcfd35b2 100644 --- a/examples/react/multi-agent.pdl +++ b/examples/react/multi-agent.pdl @@ -6,14 +6,13 @@ text: call: react args: question: ${ question } - model: watsonx/ibm/granite-20b-code-instruct - + model: ibm/granite-20b-code-instruct - "\n\n----- Verifying answer... -----\n\n" - def: verified call: react args: question: ${ question } - model: ibm/granite-34b-code-instruct + model: ibm/granite-8b-instruct-preview-4k - "\n" - if: ${ proposed.split('Act:') | last == verified.split('Act:') | last } then: diff --git a/examples/react/react_call.pdl b/examples/react/react_call.pdl index cfa92fefa..540b3cb82 100644 --- a/examples/react/react_call.pdl +++ b/examples/react/react_call.pdl @@ -4,6 +4,6 @@ text: - call: react args: question: How many years ago was the discoverer of the Hudson River born? - model: ibm/granite-34b-code-instruct + model: ibm/granite-8b-instruct-preview-4k diff --git a/examples/react/react_fun.pdl b/examples/react/react_fun.pdl index d00b6f995..68677b2a2 100644 --- a/examples/react/react_fun.pdl +++ b/examples/react/react_fun.pdl @@ -52,6 +52,7 @@ defs: result = wikipedia.summary("${ action.arguments.topic }") except wikipedia.WikipediaException as e: result = str(e) + - "\n" else: - if: ${ action.name == "Calc" } then: @@ -59,6 +60,7 @@ defs: - "Obs: " - lang: python code: result = ${ action.arguments.expr } + - "\n" else: def: exit contribute: [] diff --git a/examples/react/wikipedia.pdl b/examples/react/wikipedia.pdl index ab97327a0..2356882ce 100644 --- a/examples/react/wikipedia.pdl +++ b/examples/react/wikipedia.pdl @@ -18,18 +18,20 @@ text: Tho: Professions of Elia Kazan are director, producer, screenwriter, and actor. So profession Nicholas Ray and Elia Kazan have in common is director, screenwriter, and actor. Act: {"name": "Finish", "arguments": {"topic": "director, screenwriter, actor"}} - When was the discoverer of the Hudson River born? + + + Find the year when the discoverer of the Hudson River was born? - repeat: text: - def: thought - model: ibm/granite-34b-code-instruct + model: ibm/granite-8b-instruct-preview-4k platform: bam parameters: stop_sequences: - "Act:" include_stop_sequence: true - def: action - model: ibm/granite-34b-code-instruct + model: ibm/granite-8b-instruct-preview-4k platform: bam parameters: stop_sequences: diff --git a/examples/talk/1-hello.pdl b/examples/talk/1-hello.pdl index 9ecb9fa27..cf2fab0a1 100644 --- a/examples/talk/1-hello.pdl +++ b/examples/talk/1-hello.pdl @@ -1,6 +1,6 @@ description: Model call text: -- Hello, +- "Hello\n" - model: ibm/granite-8b-instruct-preview-4k platform: bam parameters: diff --git a/examples/talk/10-multi-agent.pdl b/examples/talk/10-multi-agent.pdl index de878e1e3..80eecdc1e 100644 --- a/examples/talk/10-multi-agent.pdl +++ b/examples/talk/10-multi-agent.pdl @@ -6,14 +6,14 @@ text: call: react args: question: ${ question } - model: watsonx/ibm/granite-20b-code-instruct + model: ibm/granite-34b-code-instruct - "\n\n----- Verifying answer... -----\n\n" - def: verified call: react args: question: ${ question } - model: watsonx/ibm/granite-34b-code-instruct + model: ibm/granite-8b-instruct-preview-4k - "\n" - if: ${ proposed.split('Act:') | last == verified.split('Act:') | last } then: diff --git a/examples/talk/2-model-chaining.pdl b/examples/talk/2-model-chaining.pdl index 3d14d683e..f2967594c 100644 --- a/examples/talk/2-model-chaining.pdl +++ b/examples/talk/2-model-chaining.pdl @@ -1,7 +1,7 @@ description: Model chaining text: -- Hello, -- model: ibm/granite-34b-code-instruct +- "Hello\n" +- model: ibm/granite-8b-instruct-preview-4k platform: bam parameters: stop_sequences: ["!"] diff --git a/examples/talk/3-def-use.pdl b/examples/talk/3-def-use.pdl index 6bf378380..cba997fd3 100644 --- a/examples/talk/3-def-use.pdl +++ b/examples/talk/3-def-use.pdl @@ -1,7 +1,7 @@ description: Variable def and use, model input text: -- Hello, -- model: ibm/granite-34b-code-instruct +- "Hello,\n" +- model: ibm/granite-8b-instruct-preview-4k platform: bam def: name parameters: @@ -9,5 +9,9 @@ text: include_stop_sequence: false - "\n" - model: ibm/granite-20b-multilingual + platform: bam input: - "Translate the word ${ name | trim } to French\n" + parameters: + stop_sequences: + - "\n" diff --git a/examples/talk/5-code-eval.pdl b/examples/talk/5-code-eval.pdl index bf599568c..55fbc9543 100644 --- a/examples/talk/5-code-eval.pdl +++ b/examples/talk/5-code-eval.pdl @@ -7,7 +7,7 @@ defs: read: ./ground_truth.txt text: - "\n${ CODE.source_code }\n" -- model: ibm/granite-34b-code-instruct +- model: ibm/granite-8b-instruct-preview-4k platform: bam def: EXPLANATION input: | diff --git a/examples/talk/6-code-json.pdl b/examples/talk/6-code-json.pdl index 5db15baea..1b208dbe4 100644 --- a/examples/talk/6-code-json.pdl +++ b/examples/talk/6-code-json.pdl @@ -6,7 +6,7 @@ defs: TRUTH: read: ./ground_truth.txt text: -- model: ibm/granite-34b-code-instruct +- model: ibm/granite-8b-instruct-preview-4k platform: bam def: EXPLANATION contribute: [] diff --git a/examples/talk/8-tools.pdl b/examples/talk/8-tools.pdl index 9f48b933f..188745c71 100644 --- a/examples/talk/8-tools.pdl +++ b/examples/talk/8-tools.pdl @@ -5,6 +5,11 @@ text: Act: {"name": "Calc", "arguments": {"expr": "18 + 12 * 3"}} Obs: 54 + What is 9 + 12? + Act: {"name": "Calc", "arguments": {"expr": "9 + 12"}} + Obs: 23 + + A total of 252 qualifying matches were played, and 723 goals were scored. What was the average number of goals per match? Act: {"name": "Calc", "arguments": {"expr": "723 / 252"}} Obs: 2.869047619047619 diff --git a/examples/talk/9-react.pdl b/examples/talk/9-react.pdl index 8e04288bc..2356882ce 100644 --- a/examples/talk/9-react.pdl +++ b/examples/talk/9-react.pdl @@ -1,4 +1,3 @@ -description: react agentic flow text: - | What is the elevation range for the area that the eastern sector of the Colorado orogeny extends into? @@ -19,25 +18,28 @@ text: Tho: Professions of Elia Kazan are director, producer, screenwriter, and actor. So profession Nicholas Ray and Elia Kazan have in common is director, screenwriter, and actor. Act: {"name": "Finish", "arguments": {"topic": "director, screenwriter, actor"}} - When was the discoverer of the Hudson River born? + + + Find the year when the discoverer of the Hudson River was born? - repeat: text: - def: thought - model: ibm/granite-34b-code-instruct + model: ibm/granite-8b-instruct-preview-4k platform: bam parameters: - stop_sequences: + stop_sequences: - "Act:" include_stop_sequence: true - def: action - model: ibm/granite-34b-code-instruct + model: ibm/granite-8b-instruct-preview-4k platform: bam parameters: - stop_sequences: + stop_sequences: - "\n" parser: json + spec: {name: str, arguments: {topic: str}} - def: observation - if: '${ action.name == "Search" }' + if: ${ action.name == "Search" } then: text: - "Obs: " @@ -49,5 +51,5 @@ text: result = wikipedia.summary("${ action.arguments.topic }") except wikipedia.WikipediaException as e: result = str(e) - until: '${ action.name != "Search" }' + until: ${ action.name != "Search" } diff --git a/examples/talk/react_fun.pdl b/examples/talk/react_fun.pdl index 947e13ad0..68677b2a2 100644 --- a/examples/talk/react_fun.pdl +++ b/examples/talk/react_fun.pdl @@ -24,14 +24,16 @@ defs: text: - def: thought model: ${ model } + platform: bam parameters: - stop: + stop_sequences: - "Act:" include_stop_sequence: true - def: action model: ${ model } + platform: bam parameters: - stop: + stop_sequences: - "\n" parser: json spec: {name: str, arguments: obj} @@ -50,6 +52,7 @@ defs: result = wikipedia.summary("${ action.arguments.topic }") except wikipedia.WikipediaException as e: result = str(e) + - "\n" else: - if: ${ action.name == "Calc" } then: @@ -57,6 +60,7 @@ defs: - "Obs: " - lang: python code: result = ${ action.arguments.expr } + - "\n" else: def: exit contribute: [] @@ -116,3 +120,4 @@ defs: question: ${ question } model: ${ model } + diff --git a/examples/thing/Thing.pdl b/examples/thing/Thing.pdl index b64b4396e..0e65c1562 100644 --- a/examples/thing/Thing.pdl +++ b/examples/thing/Thing.pdl @@ -3,7 +3,7 @@ text: - 'A list of things not to forget when ' - "traveling:\n" - repeat: - - model: ibm/granite-20b-code-instruct + - model: ibm/granite-8b-instruct-preview-4k platform: bam parameters: decoding_method: greedy @@ -12,7 +12,7 @@ text: num_iterations: 2 - 'The most important of these is ' - def: ITEM - model: ibm/granite-20b-code-instruct + model: ibm/granite-8b-instruct-preview-4k platform: bam parameters: decoding_method: greedy diff --git a/examples/tools/calc.pdl b/examples/tools/calc.pdl index bd14cc9b5..188745c71 100644 --- a/examples/tools/calc.pdl +++ b/examples/tools/calc.pdl @@ -1,10 +1,15 @@ -description: Calculator tool use using Granite models via watsonx.ai. +description: tool use text: - |- What is 18 + 12 x 3? Act: {"name": "Calc", "arguments": {"expr": "18 + 12 * 3"}} Obs: 54 + What is 9 + 12? + Act: {"name": "Calc", "arguments": {"expr": "9 + 12"}} + Obs: 23 + + A total of 252 qualifying matches were played, and 723 goals were scored. What was the average number of goals per match? Act: {"name": "Calc", "arguments": {"expr": "723 / 252"}} Obs: 2.869047619047619 @@ -23,4 +28,3 @@ text: - "Obs: " - lang: python code: result = ${ action.arguments.expr } -- "\n" diff --git a/examples/weather/weather.pdl b/examples/weather/weather.pdl index 4d7c6917d..1fdd6d8de 100644 --- a/examples/weather/weather.pdl +++ b/examples/weather/weather.pdl @@ -4,21 +4,23 @@ text: def: QUERY message: "Ask a query: " contribute: [] -- model: ibm/granite-34b-code-instruct +- model: ibm/granite-8b-instruct-preview-4k platform: bam input: | + Extract the location from the question. Question: What is the weather in London? - London + Answer: London Question: What's the weather in Paris? - Paris + Answer: Paris Question: Tell me the weather in Lagos? - Lagos + Answer: Lagos Question: ${ QUERY } parameters: stop_sequences: - Question - What - '!' + - "\n" include_stop_sequence: false def: LOCATION contribute: [] @@ -31,10 +33,9 @@ text: parser: json contribute: [] -- model: ibm/granite-34b-code-instruct +- model: ibm/granite-8b-instruct-preview-4k platform: bam input: | Explain the weather from the following JSON: ${ WEATHER } - - + \ No newline at end of file From dd1d31e912a3f6f734b726f3ef73f2001e84b3ae Mon Sep 17 00:00:00 2001 From: Mandana Vaziri Date: Wed, 9 Oct 2024 19:50:26 -0400 Subject: [PATCH 07/24] demo notebook Signed-off-by: Mandana Vaziri --- examples/notebooks/demo.ipynb | 347 ++++++++++++++++++++++++++ examples/notebooks/demonstrations.txt | 28 +++ examples/react/demo.pdl | 73 ++++++ examples/react/demonstrations.txt | 27 ++ 4 files changed, 475 insertions(+) create mode 100644 examples/notebooks/demo.ipynb create mode 100644 examples/notebooks/demonstrations.txt create mode 100644 examples/react/demo.pdl create mode 100644 examples/react/demonstrations.txt diff --git a/examples/notebooks/demo.ipynb b/examples/notebooks/demo.ipynb new file mode 100644 index 000000000..3b7f6598b --- /dev/null +++ b/examples/notebooks/demo.ipynb @@ -0,0 +1,347 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "a29514fc-9383-490c-8a73-63c547c21d95", + "metadata": {}, + "source": [ + "# Prompt Declaration Language\n", + "\n", + "The Prompt Declaration Language (PDL) is a yaml-based declarative approach to prompt programming. PDL facilitates model chaining and tool use, enables type checking of the input and output of models, and is based on LiteLLM to support a variety of model providers. PDL has been used for: RAG, CoT, ReAct prompting patterns and is being used in the SWE Agent-102. PDL is [open-source](https://github.com/IBM/prompt-declaration-language) and works well with watsonx.ai and Granite models.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "e25a6874-54d9-4167-82ed-ab2f4fdc0a6f", + "metadata": {}, + "outputs": [], + "source": [ + "%load_ext pdl.pdl_notebook_ext" + ] + }, + { + "cell_type": "markdown", + "id": "0f4a750b-5765-4e2a-9dc1-9c9af2eab940", + "metadata": {}, + "source": [ + "## Model call\n", + "\n", + "In PDL, prompts are the forefront and the user specifies step-by-step the shape of data they want to generate. In the following, the `text` construct indicates a text block containing a prompt and a model call. Implicitly PDL builds a background conversational context (list of role/content) which is used to make model calls." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "f3c62df1-0347-4711-acd7-3892cfd5df30", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "What is the meaning of life?\n", + "\u001b[32mThe\u001b[0m\u001b[32m meaning\u001b[0m\u001b[32m of\u001b[0m\u001b[32m life\u001b[0m\u001b[32m is\u001b[0m\u001b[32m a\u001b[0m\u001b[32m ph\u001b[0m\u001b[32milo\u001b[0m\u001b[32msop\u001b[0m\u001b[32mh\u001b[0m\u001b[32mical\u001b[0m\u001b[32m and\u001b[0m\u001b[32m met\u001b[0m\u001b[32maph\u001b[0m\u001b[32mysical\u001b[0m\u001b[32m question\u001b[0m\u001b[32m related\u001b[0m\u001b[32m to\u001b[0m\u001b[32m the\u001b[0m\u001b[32m purpose\u001b[0m\u001b[32m or\u001b[0m\u001b[32m signific\u001b[0m\u001b[32mance\u001b[0m\u001b[32m of\u001b[0m\u001b[32m life\u001b[0m\u001b[32m or\u001b[0m\u001b[32m existence\u001b[0m\u001b[32m in\u001b[0m\u001b[32m general\u001b[0m\u001b[32m.\u001b[0m\u001b[32m This\u001b[0m\u001b[32m concept\u001b[0m\u001b[32m has\u001b[0m\u001b[32m been\u001b[0m\u001b[32m appro\u001b[0m\u001b[32mached\u001b[0m\u001b[32m by\u001b[0m\u001b[32m many\u001b[0m\u001b[32m pers\u001b[0m\u001b[32mpect\u001b[0m\u001b[32mives\u001b[0m\u001b[32m including\u001b[0m\u001b[32m ph\u001b[0m\u001b[32milo\u001b[0m\u001b[32msophy\u001b[0m\u001b[32m,\u001b[0m\u001b[32m rel\u001b[0m\u001b[32migion\u001b[0m\u001b[32m,\u001b[0m\u001b[32m and\u001b[0m\u001b[32m science\u001b[0m\u001b[32m.\u001b[0m\u001b[32m Some\u001b[0m\u001b[32m people\u001b[0m\u001b[32m find\u001b[0m\u001b[32m meaning\u001b[0m\u001b[32m through\u001b[0m\u001b[32m personal\u001b[0m\u001b[32m growth\u001b[0m\u001b[32m,\u001b[0m\u001b[32m relationships\u001b[0m\u001b[32m,\u001b[0m\u001b[32m love\u001b[0m\u001b[32m,\u001b[0m\u001b[32m and\u001b[0m\u001b[32m through\u001b[0m\u001b[32m helping\u001b[0m\u001b[32m others\u001b[0m\u001b[32m.\u001b[0m\u001b[32m O\u001b[0m\u001b[32mthers\u001b[0m\u001b[32m seek\u001b[0m\u001b[32m meaning\u001b[0m\u001b[32m through\u001b[0m\u001b[32m spirit\u001b[0m\u001b[32mual\u001b[0m\u001b[32mity\u001b[0m\u001b[32m or\u001b[0m\u001b[32m rel\u001b[0m\u001b[32mig\u001b[0m\u001b[32mious\u001b[0m\u001b[32m bel\u001b[0m\u001b[32mie\u001b[0m\u001b[32mfs\u001b[0m\u001b[32m.\u001b[0m\u001b[32m U\u001b[0m\u001b[32mlt\u001b[0m\u001b[32mimately\u001b[0m\u001b[32m,\u001b[0m\u001b[32m the\u001b[0m\u001b[32m meaning\u001b[0m\u001b[32m of\u001b[0m\u001b[32m life\u001b[0m\u001b[32m may\u001b[0m\u001b[32m be\u001b[0m\u001b[32m a\u001b[0m\u001b[32m personal\u001b[0m\u001b[32m and\u001b[0m\u001b[32m subject\u001b[0m\u001b[32mive\u001b[0m\u001b[32m experience\u001b[0m\u001b[32m.\u001b[0m" + ] + } + ], + "source": [ + "%%pdl --reset-context\n", + "text: \n", + "- \"What is the meaning of life?\\n\"\n", + "- model: ibm/granite-8b-instruct-preview-4k\n", + " platform: bam" + ] + }, + { + "cell_type": "markdown", + "id": "1e41eb56-e278-4024-9979-7c3410e9ccf5", + "metadata": {}, + "source": [ + "## Model chaining\n", + "Model chaining can be done by simply adding to the list of models to call declaratively. " + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "7f6c323b-ad1a-4434-8732-bc19c5c47883", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Say it like a poem\n", + "\u001b[32mLife\u001b[0m\u001b[32m's\u001b[0m\u001b[32m meaning\u001b[0m\u001b[32m,\u001b[0m\u001b[32m a\u001b[0m\u001b[32m question\u001b[0m\u001b[32m vast\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mIn\u001b[0m\u001b[32m ph\u001b[0m\u001b[32milo\u001b[0m\u001b[32msophy\u001b[0m\u001b[32m,\u001b[0m\u001b[32m rel\u001b[0m\u001b[32migion\u001b[0m\u001b[32m,\u001b[0m\u001b[32m and\u001b[0m\u001b[32m science\u001b[0m\u001b[32m cast\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mSome\u001b[0m\u001b[32m find\u001b[0m\u001b[32m purpose\u001b[0m\u001b[32m in\u001b[0m\u001b[32m personal\u001b[0m\u001b[32m growth\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mIn\u001b[0m\u001b[32m love\u001b[0m\u001b[32m and\u001b[0m\u001b[32m relationships\u001b[0m\u001b[32m,\u001b[0m\u001b[32m they\u001b[0m\u001b[32m find\u001b[0m\u001b[32m their\u001b[0m\u001b[32m tro\u001b[0m\u001b[32mth\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mOthers\u001b[0m\u001b[32m seek\u001b[0m\u001b[32m meaning\u001b[0m\u001b[32m through\u001b[0m\u001b[32m spirit\u001b[0m\u001b[32mual\u001b[0m\u001b[32mity\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mIn\u001b[0m\u001b[32m fa\u001b[0m\u001b[32mith\u001b[0m\u001b[32m and\u001b[0m\u001b[32m bel\u001b[0m\u001b[32mief\u001b[0m\u001b[32m,\u001b[0m\u001b[32m they\u001b[0m\u001b[32m find\u001b[0m\u001b[32m their\u001b[0m\u001b[32m reality\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mUlt\u001b[0m\u001b[32mimately\u001b[0m\u001b[32m,\u001b[0m\u001b[32m meaning\u001b[0m\u001b[32m is\u001b[0m\u001b[32m a\u001b[0m\u001b[32m personal\u001b[0m\u001b[32m quest\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mIn\u001b[0m\u001b[32m life\u001b[0m\u001b[32m's\u001b[0m\u001b[32m journey\u001b[0m\u001b[32m,\u001b[0m\u001b[32m we\u001b[0m\u001b[32m are\u001b[0m\u001b[32m put\u001b[0m\u001b[32m to\u001b[0m\u001b[32m the\u001b[0m\u001b[32m test\u001b[0m\u001b[32m.\u001b[0m\n", + "\n", + "Translate it to French\n", + "\u001b[32mLa\u001b[0m\u001b[32m sign\u001b[0m\u001b[32mification\u001b[0m\u001b[32m de\u001b[0m\u001b[32m la\u001b[0m\u001b[32m v\u001b[0m\u001b[32mie\u001b[0m\u001b[32m,\u001b[0m\u001b[32m une\u001b[0m\u001b[32m question\u001b[0m\u001b[32m imm\u001b[0m\u001b[32mense\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mD\u001b[0m\u001b[32mans\u001b[0m\u001b[32m la\u001b[0m\u001b[32m ph\u001b[0m\u001b[32milo\u001b[0m\u001b[32msop\u001b[0m\u001b[32mh\u001b[0m\u001b[32mie\u001b[0m\u001b[32m,\u001b[0m\u001b[32m la\u001b[0m\u001b[32m rel\u001b[0m\u001b[32migion\u001b[0m\u001b[32m et\u001b[0m\u001b[32m la\u001b[0m\u001b[32m science\u001b[0m\u001b[32m,\u001b[0m\u001b[32m el\u001b[0m\u001b[32mle\u001b[0m\u001b[32m est\u001b[0m\u001b[32m pos\u001b[0m\u001b[32mée\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mQue\u001b[0m\u001b[32ml\u001b[0m\u001b[32mques\u001b[0m\u001b[32m-\u001b[0m\u001b[32muns\u001b[0m\u001b[32m tro\u001b[0m\u001b[32mu\u001b[0m\u001b[32mvent\u001b[0m\u001b[32m un\u001b[0m\u001b[32m but\u001b[0m\u001b[32m dans\u001b[0m\u001b[32m le\u001b[0m\u001b[32mur\u001b[0m\u001b[32m cro\u001b[0m\u001b[32miss\u001b[0m\u001b[32mance\u001b[0m\u001b[32m person\u001b[0m\u001b[32mnel\u001b[0m\u001b[32mle\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mD\u001b[0m\u001b[32mans\u001b[0m\u001b[32m l\u001b[0m\u001b[32m'\u001b[0m\u001b[32mam\u001b[0m\u001b[32mour\u001b[0m\u001b[32m et\u001b[0m\u001b[32m les\u001b[0m\u001b[32m relations\u001b[0m\u001b[32m,\u001b[0m\u001b[32m il\u001b[0m\u001b[32ms\u001b[0m\u001b[32m tro\u001b[0m\u001b[32mu\u001b[0m\u001b[32mvent\u001b[0m\u001b[32m le\u001b[0m\u001b[32mur\u001b[0m\u001b[32m foi\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mD\u001b[0m\u001b[32m'\u001b[0m\u001b[32maut\u001b[0m\u001b[32mres\u001b[0m\u001b[32m ch\u001b[0m\u001b[32mer\u001b[0m\u001b[32mch\u001b[0m\u001b[32ment\u001b[0m\u001b[32m la\u001b[0m\u001b[32m sign\u001b[0m\u001b[32mification\u001b[0m\u001b[32m à\u001b[0m\u001b[32m tra\u001b[0m\u001b[32mvers\u001b[0m\u001b[32m la\u001b[0m\u001b[32m spirit\u001b[0m\u001b[32mual\u001b[0m\u001b[32mité\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mD\u001b[0m\u001b[32mans\u001b[0m\u001b[32m la\u001b[0m\u001b[32m foi\u001b[0m\u001b[32m et\u001b[0m\u001b[32m la\u001b[0m\u001b[32m c\u001b[0m\u001b[32mroy\u001b[0m\u001b[32mance\u001b[0m\u001b[32m,\u001b[0m\u001b[32m il\u001b[0m\u001b[32ms\u001b[0m\u001b[32m tro\u001b[0m\u001b[32mu\u001b[0m\u001b[32mvent\u001b[0m\u001b[32m le\u001b[0m\u001b[32mur\u001b[0m\u001b[32m ré\u001b[0m\u001b[32mal\u001b[0m\u001b[32mité\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mEn\u001b[0m\u001b[32m fin\u001b[0m\u001b[32m de\u001b[0m\u001b[32m compte\u001b[0m\u001b[32m,\u001b[0m\u001b[32m le\u001b[0m\u001b[32m but\u001b[0m\u001b[32m est\u001b[0m\u001b[32m une\u001b[0m\u001b[32m qu\u001b[0m\u001b[32mête\u001b[0m\u001b[32m person\u001b[0m\u001b[32mnel\u001b[0m\u001b[32mle\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mD\u001b[0m\u001b[32mans\u001b[0m\u001b[32m le\u001b[0m\u001b[32m vo\u001b[0m\u001b[32my\u001b[0m\u001b[32mage\u001b[0m\u001b[32m de\u001b[0m\u001b[32m la\u001b[0m\u001b[32m v\u001b[0m\u001b[32mie\u001b[0m\u001b[32m,\u001b[0m\u001b[32m nous\u001b[0m\u001b[32m som\u001b[0m\u001b[32mmes\u001b[0m\u001b[32m mis\u001b[0m\u001b[32m à\u001b[0m\u001b[32m l\u001b[0m\u001b[32m'\u001b[0m\u001b[32mé\u001b[0m\u001b[32mpre\u001b[0m\u001b[32muve\u001b[0m\u001b[32m.\u001b[0m" + ] + } + ], + "source": [ + "%%pdl\n", + "text:\n", + "- \"\\nSay it like a poem\\n\"\n", + "- model: ibm/granite-8b-instruct-preview-4k\n", + " platform: bam\n", + "- \"\\n\\nTranslate it to French\\n\"\n", + "- model: ibm/granite-8b-instruct-preview-4k\n", + " platform: bam" + ] + }, + { + "cell_type": "markdown", + "id": "fe9b1959-e49b-48d3-b722-19ace9b981d2", + "metadata": {}, + "source": [ + "## Chat templates\n", + "\n", + "The second call to the model in the above program submits the following prompt. PDL takes care of applying the appropriate prompt templates and tags, and builds the background context implicitly. All the user has to do is list the models they want to chain, PDL takes care of the rest.\n", + "\n", + "```\n", + "<|start_of_role|>user<|end_of_role|>What is the meaning of life?\n", + "<|end_of_text|>\n", + "The meaning of life is a philosophical and metaphysical question related to the purpose or significance of life or existence in general. This concept has been approached by many perspectives including philosophy, religion, and science. Some people find meaning through personal growth, relationships, love, and through helping others. Others seek meaning through spirituality or religious beliefs. Ultimately, the meaning of life may be a personal and subjective experience.\n", + "\n", + "<|start_of_role|>user<|end_of_role|>Say it like a poem<|end_of_text|>\n", + "Life's meaning, a question vast,\n", + "In philosophy, religion, and science cast.\n", + "Some find purpose in personal growth,\n", + "In love and relationships, they find their troth.\n", + "Others seek meaning through spirituality,\n", + "In faith and belief, they find their reality.\n", + "Ultimately, meaning is a personal quest,\n", + "In life's journey, we are put to the test.\n", + "\n", + "<|start_of_role|>user<|end_of_role|>Translate it to French\n", + "<|end_of_text|>\n", + "<|start_of_role|>assistant<|end_of_role|>\n", + "```" + ] + }, + { + "cell_type": "markdown", + "id": "99681db4-8a43-4b06-92a6-8d140989f2ea", + "metadata": {}, + "source": [ + "## Data pipeline\n", + "\n", + "The following program shows a common prompting pattern: read some data, formulate a prompt using that data, submit to a model, and evaluate. In this program, we formulate a prompt for code explanation. The program first defines two variables: `code`, which holds the data we read, and `truth` for the ground truth. It then prints out the source code, formulates a prompts with the data, and calls a model to get an explanation. Finally, a Python code block is used to use the Levenshtein text distance metric and evaluate the explanation against the ground truth. This pipeline can similarly be applied to an entire data set to produce a jsonl file." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "b61b2e25-72a4-4f70-ae83-40d77bed3f4f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "@SuppressWarnings(\"unchecked\")\n", + "public static Map deserializeOffsetMap(String lastSourceOffset) throws IOException {\n", + " Map offsetMap;\n", + " if (lastSourceOffset == null || lastSourceOffset.isEmpty()) { \n", + " offsetMap = new HashMap<>(); \n", + " } else {\n", + " offsetMap = JSON_MAPPER.readValue(lastSourceOffset, Map.class); \n", + " }\n", + " return offsetMap;\n", + "}\n", + "\n", + "\u001b[32m\n", + "\u001b[0m\u001b[32mThis\u001b[0m\u001b[32m Java\u001b[0m\u001b[32m method\u001b[0m\u001b[32m,\u001b[0m\u001b[32m `\u001b[0m\u001b[32mdeserialize\u001b[0m\u001b[32mOffset\u001b[0m\u001b[32mMap\u001b[0m\u001b[32m`,\u001b[0m\u001b[32m is\u001b[0m\u001b[32m designed\u001b[0m\u001b[32m to\u001b[0m\u001b[32m convert\u001b[0m\u001b[32m a\u001b[0m\u001b[32m JSON\u001b[0m\u001b[32m string\u001b[0m\u001b[32m into\u001b[0m\u001b[32m a\u001b[0m\u001b[32m `\u001b[0m\u001b[32mMap\u001b[0m\u001b[32m<\u001b[0m\u001b[32mString\u001b[0m\u001b[32m,\u001b[0m\u001b[32m String\u001b[0m\u001b[32m>`.\u001b[0m\u001b[32m Here\u001b[0m\u001b[32m's\u001b[0m\u001b[32m a\u001b[0m\u001b[32m break\u001b[0m\u001b[32mdown\u001b[0m\u001b[32m of\u001b[0m\u001b[32m the\u001b[0m\u001b[32m code\u001b[0m\u001b[32m:\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32m1\u001b[0m\u001b[32m.\u001b[0m\u001b[32m The\u001b[0m\u001b[32m method\u001b[0m\u001b[32m takes\u001b[0m\u001b[32m a\u001b[0m\u001b[32m single\u001b[0m\u001b[32m parameter\u001b[0m\u001b[32m,\u001b[0m\u001b[32m `\u001b[0m\u001b[32mlast\u001b[0m\u001b[32mSource\u001b[0m\u001b[32mOffset\u001b[0m\u001b[32m`,\u001b[0m\u001b[32m which\u001b[0m\u001b[32m is\u001b[0m\u001b[32m expected\u001b[0m\u001b[32m to\u001b[0m\u001b[32m be\u001b[0m\u001b[32m a\u001b[0m\u001b[32m JSON\u001b[0m\u001b[32m string\u001b[0m\u001b[32m representing\u001b[0m\u001b[32m a\u001b[0m\u001b[32m map\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32m2\u001b[0m\u001b[32m.\u001b[0m\u001b[32m It\u001b[0m\u001b[32m first\u001b[0m\u001b[32m checks\u001b[0m\u001b[32m if\u001b[0m\u001b[32m `\u001b[0m\u001b[32mlast\u001b[0m\u001b[32mSource\u001b[0m\u001b[32mOffset\u001b[0m\u001b[32m`\u001b[0m\u001b[32m is\u001b[0m\u001b[32m either\u001b[0m\u001b[32m null\u001b[0m\u001b[32m or\u001b[0m\u001b[32m an\u001b[0m\u001b[32m empty\u001b[0m\u001b[32m string\u001b[0m\u001b[32m.\u001b[0m\u001b[32m If\u001b[0m\u001b[32m true\u001b[0m\u001b[32m,\u001b[0m\u001b[32m it\u001b[0m\u001b[32m initializes\u001b[0m\u001b[32m a\u001b[0m\u001b[32m new\u001b[0m\u001b[32m `\u001b[0m\u001b[32mHashMap\u001b[0m\u001b[32m`\u001b[0m\u001b[32m and\u001b[0m\u001b[32m assigns\u001b[0m\u001b[32m it\u001b[0m\u001b[32m to\u001b[0m\u001b[32m `\u001b[0m\u001b[32moffset\u001b[0m\u001b[32mMap\u001b[0m\u001b[32m`.\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32m3\u001b[0m\u001b[32m.\u001b[0m\u001b[32m If\u001b[0m\u001b[32m `\u001b[0m\u001b[32mlast\u001b[0m\u001b[32mSource\u001b[0m\u001b[32mOffset\u001b[0m\u001b[32m`\u001b[0m\u001b[32m is\u001b[0m\u001b[32m not\u001b[0m\u001b[32m null\u001b[0m\u001b[32m or\u001b[0m\u001b[32m empty\u001b[0m\u001b[32m,\u001b[0m\u001b[32m it\u001b[0m\u001b[32m uses\u001b[0m\u001b[32m Jack\u001b[0m\u001b[32mson\u001b[0m\u001b[32m's\u001b[0m\u001b[32m `\u001b[0m\u001b[32mJSON\u001b[0m\u001b[32m_\u001b[0m\u001b[32mMAP\u001b[0m\u001b[32mPER\u001b[0m\u001b[32m`\u001b[0m\u001b[32m to\u001b[0m\u001b[32m deserialize\u001b[0m\u001b[32m the\u001b[0m\u001b[32m JSON\u001b[0m\u001b[32m string\u001b[0m\u001b[32m into\u001b[0m\u001b[32m a\u001b[0m\u001b[32m `\u001b[0m\u001b[32mMap\u001b[0m\u001b[32m<\u001b[0m\u001b[32mString\u001b[0m\u001b[32m,\u001b[0m\u001b[32m String\u001b[0m\u001b[32m>`\u001b[0m\u001b[32m and\u001b[0m\u001b[32m assigns\u001b[0m\u001b[32m it\u001b[0m\u001b[32m to\u001b[0m\u001b[32m `\u001b[0m\u001b[32moffset\u001b[0m\u001b[32mMap\u001b[0m\u001b[32m`.\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32m4\u001b[0m\u001b[32m.\u001b[0m\u001b[32m Finally\u001b[0m\u001b[32m,\u001b[0m\u001b[32m it\u001b[0m\u001b[32m returns\u001b[0m\u001b[32m the\u001b[0m\u001b[32m `\u001b[0m\u001b[32moffset\u001b[0m\u001b[32mMap\u001b[0m\u001b[32m`.\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mThe\u001b[0m\u001b[32m `@\u001b[0m\u001b[32mSuppressWarnings\u001b[0m\u001b[32m(\"\u001b[0m\u001b[32munchecked\u001b[0m\u001b[32m\")\u001b[0m\u001b[32m`\u001b[0m\u001b[32m annotation\u001b[0m\u001b[32m is\u001b[0m\u001b[32m used\u001b[0m\u001b[32m to\u001b[0m\u001b[32m suppress\u001b[0m\u001b[32m a\u001b[0m\u001b[32m potential\u001b[0m\u001b[32m unchecked\u001b[0m\u001b[32m warning\u001b[0m\u001b[32m that\u001b[0m\u001b[32m might\u001b[0m\u001b[32m occur\u001b[0m\u001b[32m due\u001b[0m\u001b[32m to\u001b[0m\u001b[32m the\u001b[0m\u001b[32m raw\u001b[0m\u001b[32m type\u001b[0m\u001b[32m usage\u001b[0m\u001b[32m in\u001b[0m\u001b[32m the\u001b[0m\u001b[32m method\u001b[0m\u001b[32m signature\u001b[0m\u001b[32m.\u001b[0m\u001b[32m However\u001b[0m\u001b[32m,\u001b[0m\u001b[32m this\u001b[0m\u001b[32m is\u001b[0m\u001b[32m generally\u001b[0m\u001b[32m considered\u001b[0m\u001b[32m a\u001b[0m\u001b[32m code\u001b[0m\u001b[32m s\u001b[0m\u001b[32mmell\u001b[0m\u001b[32m and\u001b[0m\u001b[32m should\u001b[0m\u001b[32m be\u001b[0m\u001b[32m a\u001b[0m\u001b[32mvo\u001b[0m\u001b[32mided\u001b[0m\u001b[32m if\u001b[0m\u001b[32m possible\u001b[0m\u001b[32m.\u001b[0m\u001b[32m It\u001b[0m\u001b[32m's\u001b[0m\u001b[32m better\u001b[0m\u001b[32m to\u001b[0m\u001b[32m use\u001b[0m\u001b[32m gener\u001b[0m\u001b[32mics\u001b[0m\u001b[32m to\u001b[0m\u001b[32m avoid\u001b[0m\u001b[32m such\u001b[0m\u001b[32m warnings\u001b[0m\u001b[32m.\u001b[0m\n", + "Evaluation:\n", + "The similarity (Levenshtein) between this answer and the ground truth is:\n", + "\u001b[35m0.33441208198489747\u001b[0m" + ] + } + ], + "source": [ + "%%pdl\n", + "defs:\n", + " code:\n", + " read: ./data.yaml\n", + " parser: yaml\n", + " truth:\n", + " read: ./ground_truth.txt\n", + "text:\n", + "- \"\\n${ code.source_code }\\n\"\n", + "- model: ibm/granite-8b-instruct-preview-4k\n", + " platform: bam\n", + " def: explanation\n", + " input: |\n", + " Here is some info about the location of the function in the repo.\n", + " repo: \n", + " ${ code.repo_info.repo }\n", + " path: ${ code.repo_info.path }\n", + " Function_name: ${ code.repo_info.function_name }\n", + "\n", + "\n", + " Explain the following code:\n", + " ```\n", + " ${ code.source_code }```\n", + "- |\n", + "\n", + " Evaluation:\n", + " The similarity (Levenshtein) between this answer and the ground truth is:\n", + "- def: EVAL\n", + " lang: python\n", + " code: |\n", + " import textdistance\n", + " expl = \"\"\"\n", + " ${ explanation }\n", + " \"\"\"\n", + " truth = \"\"\"\n", + " ${ truth }\n", + " \"\"\"\n", + " result = textdistance.levenshtein.normalized_similarity(expl, truth)\n" + ] + }, + { + "cell_type": "markdown", + "id": "41a0dd93-febb-408b-ae22-e829e02906e9", + "metadata": {}, + "source": [ + "## Agentic Flow\n", + "\n", + "The following PDL program shows an agentic flow with a ReAct prompt pattern. It first reads some demonstrations to be used as few-shots. The ReAct pattern is captured with PDL control structures (repeat-until, and if-then-else), and consists of cycling through thoughts, actions, and observations. The tools available are wikipedia search, and calculator (as a Python code). The agent decides when to search and when to calculate. The `spec` indicates a type for the output of the model when actions are produced, it is used to dynamically check outputs of models and fail when they don't conform to the expectation. " + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "b7ff8708-7a82-492d-a91b-2ff4a17c768e", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "How many years ago was the Hubble telescope launched? Keep in mind we are in 2024.\n", + "\n", + "\u001b[32mTh\u001b[0m\u001b[32mo\u001b[0m\u001b[32m:\u001b[0m\u001b[32m I\u001b[0m\u001b[32m need\u001b[0m\u001b[32m to\u001b[0m\u001b[32m search\u001b[0m\u001b[32m H\u001b[0m\u001b[32mubble\u001b[0m\u001b[32m te\u001b[0m\u001b[32mlescope\u001b[0m\u001b[32m,\u001b[0m\u001b[32m find\u001b[0m\u001b[32m its\u001b[0m\u001b[32m launch\u001b[0m\u001b[32m date\u001b[0m\u001b[32m,\u001b[0m\u001b[32m then\u001b[0m\u001b[32m calculate\u001b[0m\u001b[32m how\u001b[0m\u001b[32m many\u001b[0m\u001b[32m years\u001b[0m\u001b[32m ago\u001b[0m\u001b[32m it\u001b[0m\u001b[32m was\u001b[0m\u001b[32m launched\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mAct\u001b[0m\u001b[32m:\u001b[0m\u001b[32m {\"\u001b[0m\u001b[32mname\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m \"\u001b[0m\u001b[32mSearch\u001b[0m\u001b[32m\",\u001b[0m\u001b[32m \"\u001b[0m\u001b[32marguments\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m {\"\u001b[0m\u001b[32mtopic\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m \"\u001b[0m\u001b[32mHub\u001b[0m\u001b[32mble\u001b[0m\u001b[32m te\u001b[0m\u001b[32mlescope\u001b[0m\u001b[32m\"}}\u001b[0m\u001b[32m\n", + "\u001b[0mObs: \u001b[35mThe Hubble Space Telescope (often referred to as HST or Hubble) is a space telescope that was launched into low Earth orbit in 1990 and remains in operation. It was not the first space telescope, but it is one of the largest and most versatile, renowned as a vital research tool and as a public relations boon for astronomy. The Hubble telescope is named after astronomer Edwin Hubble and is one of NASA's Great Observatories. The Space Telescope Science Institute (STScI) selects Hubble's targets and processes the resulting data, while the Goddard Space Flight Center (GSFC) controls the spacecraft. \n", + "Hubble features a 2.4 m (7 ft 10 in) mirror, and its five main instruments observe in the ultraviolet, visible, and near-infrared regions of the electromagnetic spectrum. Hubble's orbit outside the distortion of Earth's atmosphere allows it to capture extremely high-resolution images with substantially lower background light than ground-based telescopes. It has recorded some of the most detailed visible light images, allowing a deep view into space. Many Hubble observations have led to breakthroughs in astrophysics, such as determining the rate of expansion of the universe.\n", + "Space telescopes were proposed as early as 1923, and the Hubble telescope was funded and built in the 1970s by the United States space agency NASA with contributions from the European Space Agency. Its intended launch was in 1983, but the project was beset by technical delays, budget problems, and the 1986 Challenger disaster. Hubble was finally launched in 1990, but its main mirror had been ground incorrectly, resulting in spherical aberration that compromised the telescope's capabilities. The optics were corrected to their intended quality by a servicing mission in 1993.\n", + "Hubble is the only telescope designed to be maintained in space by astronauts. Five Space Shuttle missions have repaired, upgraded, and replaced systems on the telescope, including all five of the main instruments. The fifth mission was initially canceled on safety grounds following the Columbia disaster (2003), but after NASA administrator Michael D. Griffin approved it, the servicing mission was completed in 2009. Hubble completed 30 years of operation in April 2020 and is predicted to last until 2030 to 2040.\n", + "Hubble is the visible light telescope in NASA's Great Observatories program; other parts of the spectrum are covered by the Compton Gamma Ray Observatory, the Chandra X-ray Observatory, and the Spitzer Space Telescope (which covers the infrared bands).\n", + "The mid-IR-to-visible band successor to the Hubble telescope is the James Webb Space Telescope (JWST), which was launched on December 25, 2021, with the Nancy Grace Roman Space Telescope due to follow in 2027.\n", + "\n", + "\u001b[0m\n", + "\u001b[32mTh\u001b[0m\u001b[32mo\u001b[0m\u001b[32m:\u001b[0m\u001b[32m The\u001b[0m\u001b[32m H\u001b[0m\u001b[32mubble\u001b[0m\u001b[32m te\u001b[0m\u001b[32mlescope\u001b[0m\u001b[32m was\u001b[0m\u001b[32m launched\u001b[0m\u001b[32m in\u001b[0m\u001b[32m \u001b[0m\u001b[32m1\u001b[0m\u001b[32m9\u001b[0m\u001b[32m9\u001b[0m\u001b[32m0\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mAct\u001b[0m\u001b[32m:\u001b[0m\u001b[32m {\"\u001b[0m\u001b[32mname\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m \"\u001b[0m\u001b[32mCalc\u001b[0m\u001b[32m\",\u001b[0m\u001b[32m \"\u001b[0m\u001b[32marguments\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m {\"\u001b[0m\u001b[32mexpr\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m \"\u001b[0m\u001b[32m2\u001b[0m\u001b[32m0\u001b[0m\u001b[32m2\u001b[0m\u001b[32m4\u001b[0m\u001b[32m -\u001b[0m\u001b[32m \u001b[0m\u001b[32m1\u001b[0m\u001b[32m9\u001b[0m\u001b[32m9\u001b[0m\u001b[32m0\u001b[0m\u001b[32m\"}}\u001b[0m\u001b[32m\n", + "\u001b[0mObs: \u001b[35m34\u001b[0m\n" + ] + } + ], + "source": [ + "%%pdl --reset-context\n", + "text:\n", + "- read: demonstrations.txt\n", + " contribute: [context]\n", + "- \"How many years ago was the Hubble telescope launched? Keep in mind we are in 2024.\\n\\n\"\n", + "- repeat:\n", + " text:\n", + " - def: thought\n", + " model: ibm/granite-8b-instruct-preview-4k\n", + " platform: bam\n", + " parameters:\n", + " stop_sequences: [\"Act:\"]\n", + " include_stop_sequence: true\n", + " - def: action\n", + " model: ibm/granite-8b-instruct-preview-4k\n", + " platform: bam\n", + " parameters:\n", + " stop_sequences: [\"\\n\"]\n", + " parser: json\n", + " spec: {name: str, arguments: obj}\n", + " - def: observation\n", + " if: ${ action.name == \"Search\" }\n", + " then:\n", + " text:\n", + " - \"Obs: \"\n", + " - lang: python\n", + " code: |\n", + " import warnings, wikipedia\n", + " warnings.simplefilter(\"ignore\")\n", + " try:\n", + " result = wikipedia.summary(\"${ action.arguments.topic }\", auto_suggest=False)\n", + " except wikipedia.WikipediaException as e:\n", + " result = str(e)\n", + " - \"\\n\"\n", + " else:\n", + " - if: ${ action.name == \"Calc\" }\n", + " then:\n", + " text:\n", + " - \"Obs: \"\n", + " - lang: python\n", + " code: result = ${ action.arguments.expr }\n", + " - \"\\n\"\n", + " until: ${ action.name != \"Search\" }\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bf0c64df-2d8e-4606-acc4-f46169c189f4", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/examples/notebooks/demonstrations.txt b/examples/notebooks/demonstrations.txt new file mode 100644 index 000000000..72d75c9c1 --- /dev/null +++ b/examples/notebooks/demonstrations.txt @@ -0,0 +1,28 @@ +| +What is the elevation range for the area that the eastern sector of the Colorado orogeny extends into? +Tho: I need to search Colorado orogeny, find the area that the eastern sector of the Colorado ... +Act: {"name": "Search", "arguments": {"topic": "Colorado orogeny"}} +Obs: The Colorado orogeny was an episode of mountain building (an orogeny) ... +Tho: It does not mention the eastern sector. So I need to look up eastern sector. +Tho: High Plains rise in elevation from around 1,800 to 7,000 ft, so the answer is 1,800 to 7,000 ft. +Act: {"name": "Finish", "arguments": {"topic": "1,800 to 7,000 ft"}} + +What profession does Nicholas Ray and Elia Kazan have in common? +Tho: I need to search Nicholas Ray and Elia Kazan, find their professions, then find the profession they have in common. +Act: {"name": "Search", "arguments": {"topic": "Nicholas Ray"}} +Obs: Nicholas Ray (born Raymond Nicholas Kienzle Jr., August 7, 1911 - June 16, 1979) was an American film director, screenwriter, and actor best known for the 1955 film Rebel Without a Cause. +Tho: Professions of Nicholas Ray are director, screenwriter, and actor. I need to search Elia Kazan next and find his professions. +Act: {"name": "Search", "arguments": {"topic": "Elia Kazan"}} +Obs: Elia Kazan was an American film and theatre director, producer, screenwriter and actor. +Tho: Professions of Elia Kazan are director, producer, screenwriter, and actor. So profession Nicholas Ray and Elia Kazan have in common is director, screenwriter, and actor. +Act: {"name": "Finish", "arguments": {"topic": "director, screenwriter, actor"}} + +What is 18 + 12 x 3? +Act: {"name": "Calc", "arguments": {"expr": "18 + 12 * 3"}} +Obs: 54 +Act: {"name": "Finish", "arguments": {"topic": "54"}} + +A total of 252 qualifying matches were played, and 723 goals were scored. What was the average number of goals per match? +Act: {"name": "Calc", "arguments": {"expr": "723 / 252"}} +Obs: 2.869047619047619 +Act: {"name": "Finish", "arguments": {"topic": "2.869047619047619"}} \ No newline at end of file diff --git a/examples/react/demo.pdl b/examples/react/demo.pdl new file mode 100644 index 000000000..55b0107ee --- /dev/null +++ b/examples/react/demo.pdl @@ -0,0 +1,73 @@ +text: +- | + What is the elevation range for the area that the eastern sector of the Colorado orogeny extends into? + Tho: I need to search Colorado orogeny, find the area that the eastern sector of the Colorado ... + Act: {"name": "Search", "arguments": {"topic": "Colorado orogeny"}} + Obs: The Colorado orogeny was an episode of mountain building (an orogeny) ... + Tho: It does not mention the eastern sector. So I need to look up eastern sector. + Tho: High Plains rise in elevation from around 1,800 to 7,000 ft, so the answer is 1,800 to 7,000 ft. + Act: {"name": "Finish", "arguments": {"topic": "1,800 to 7,000 ft"}} + + What profession does Nicholas Ray and Elia Kazan have in common? + Tho: I need to search Nicholas Ray and Elia Kazan, find their professions, then find the profession they have in common. + Act: {"name": "Search", "arguments": {"topic": "Nicholas Ray"}} + Obs: Nicholas Ray (born Raymond Nicholas Kienzle Jr., August 7, 1911 - June 16, 1979) was an American film director, screenwriter, and actor best known for the 1955 film Rebel Without a Cause. + Tho: Professions of Nicholas Ray are director, screenwriter, and actor. I need to search Elia Kazan next and find his professions. + Act: {"name": "Search", "arguments": {"topic": "Elia Kazan"}} + Obs: Elia Kazan was an American film and theatre director, producer, screenwriter and actor. + Tho: Professions of Elia Kazan are director, producer, screenwriter, and actor. So profession Nicholas Ray and Elia Kazan have in common is director, screenwriter, and actor. + Act: {"name": "Finish", "arguments": {"topic": "director, screenwriter, actor"}} + + What is 18 + 12 x 3? + Act: {"name": "Calc", "arguments": {"expr": "18 + 12 * 3"}} + Obs: 54 + Act: {"name": "Finish", "arguments": {"topic": "54"}} + + A total of 252 qualifying matches were played, and 723 goals were scored. What was the average number of goals per match? + Act: {"name": "Calc", "arguments": {"expr": "723 / 252"}} + Obs: 2.869047619047619 + Act: {"name": "Finish", "arguments": {"topic": "2.869047619047619"}} + + + How many years ago was the discoverer of the Hudson River born? Keep in mind we are in 2024. +- repeat: + text: + - def: thought + model: ibm/granite-8b-instruct-preview-4k + platform: bam + parameters: + stop_sequences: + - "Act:" + include_stop_sequence: true + - def: action + model: ibm/granite-8b-instruct-preview-4k + platform: bam + parameters: + stop_sequences: + - "\n" + parser: json + spec: {name: str, arguments: obj} + - def: observation + if: ${ action.name == "Search" } + then: + text: + - "Obs: " + - lang: python + code: | + import warnings, wikipedia + warnings.simplefilter("ignore") + try: + result = wikipedia.summary("${ action.arguments.topic }") + except wikipedia.WikipediaException as e: + result = str(e) + - "\n" + else: + - if: ${ action.name == "Calc" } + then: + text: + - "Obs: " + - lang: python + code: result = ${ action.arguments.expr } + - "\n" + until: ${ action.name != "Search" } + diff --git a/examples/react/demonstrations.txt b/examples/react/demonstrations.txt new file mode 100644 index 000000000..8879d2804 --- /dev/null +++ b/examples/react/demonstrations.txt @@ -0,0 +1,27 @@ +"What is the elevation range for the area that the eastern sector of the Colorado orogeny extends into? +Tho: I need to search Colorado orogeny, find the area that the eastern sector of the Colorado ... +Act: {"name": "Search", "arguments": {"topic": "Colorado orogeny"}} +Obs: The Colorado orogeny was an episode of mountain building (an orogeny) ... +Tho: It does not mention the eastern sector. So I need to look up eastern sector. +Tho: High Plains rise in elevation from around 1,800 to 7,000 ft, so the answer is 1,800 to 7,000 ft. +Act: {"name": "Finish", "arguments": {"topic": "1,800 to 7,000 ft"}} + +What profession does Nicholas Ray and Elia Kazan have in common? +Tho: I need to search Nicholas Ray and Elia Kazan, find their professions, then find the profession they have in common. +Act: {"name": "Search", "arguments": {"topic": "Nicholas Ray"}} +Obs: Nicholas Ray (born Raymond Nicholas Kienzle Jr., August 7, 1911 - June 16, 1979) was an American film director, screenwriter, and actor best known for the 1955 film Rebel Without a Cause. +Tho: Professions of Nicholas Ray are director, screenwriter, and actor. I need to search Elia Kazan next and find his professions. +Act: {"name": "Search", "arguments": {"topic": "Elia Kazan"}} +Obs: Elia Kazan was an American film and theatre director, producer, screenwriter and actor. +Tho: Professions of Elia Kazan are director, producer, screenwriter, and actor. So profession Nicholas Ray and Elia Kazan have in common is director, screenwriter, and actor. +Act: {"name": "Finish", "arguments": {"topic": "director, screenwriter, actor"}} + +What is 18 + 12 x 3? +Act: {"name": "Calc", "arguments": {"expr": "18 + 12 * 3"}} +Obs: 54 +Act: {"name": "Finish", "arguments": {"topic": "54"}} + +A total of 252 qualifying matches were played, and 723 goals were scored. What was the average number of goals per match? +Act: {"name": "Calc", "arguments": {"expr": "723 / 252"}} +Obs: 2.869047619047619 +Act: {"name": "Finish", "arguments": {"topic": "2.869047619047619"}}" \ No newline at end of file From 33ee84423471be3481415fa8bc2cde3e0741265f Mon Sep 17 00:00:00 2001 From: Mandana Vaziri Date: Mon, 30 Sep 2024 10:24:00 -0400 Subject: [PATCH 08/24] bam branch Signed-off-by: Mandana Vaziri --- examples/arith/arith.pdl | 48 ++++++ examples/chatbot/chatbot.pdl | 4 +- examples/cldk/cldk-assistant.pdl | 247 ++++++++++++++++--------------- examples/hello/test.pdl | 2 + examples/talk/9-react.pdl | 1 - examples/talk/def-use.pdl | 13 ++ 6 files changed, 192 insertions(+), 123 deletions(-) create mode 100644 examples/arith/arith.pdl create mode 100644 examples/talk/def-use.pdl diff --git a/examples/arith/arith.pdl b/examples/arith/arith.pdl new file mode 100644 index 000000000..1aad45f3a --- /dev/null +++ b/examples/arith/arith.pdl @@ -0,0 +1,48 @@ +description: Math Problems +text: +- read: example1.txt +- read: example2.txt +- repeat: + text: + - "\nQuestion: " + - def: QUESTION + model: ibm/granite-34b-code-instruct + platform: bam + parameters: + stop_sequences: + - Answer + - "?" + include_stop_sequence: true + - "\nAnswer: Let's think step by step.\n" + - repeat: + text: + - def: REASON_OR_CALC + model: ibm/granite-34b-code-instruct + platform: bam + parameters: + stop_sequences: + - '<<' + - "Question" + include_stop_sequence: true + - if: ${ REASON_OR_CALC.endswith("<<") } + then: + text: + - def: EXPR + model: ibm/granite-34b-code-instruct + platform: bam + parameters: + stop_sequences: + - '=' + - "\n" + - "Question" + include_stop_sequence: false + - '= ' + - def: RESULT + lan: python + code: result = ${ EXPR } + - ' >>' + until: ${ "The answer is" in REASON_OR_CALC } + as: text + - "\n\n" + as: text + num_iterations: 3 \ No newline at end of file diff --git a/examples/chatbot/chatbot.pdl b/examples/chatbot/chatbot.pdl index ba62ad3a7..262a66e02 100644 --- a/examples/chatbot/chatbot.pdl +++ b/examples/chatbot/chatbot.pdl @@ -5,7 +5,8 @@ text: contribute: [context] - repeat: text: - - model: watsonx/ibm/granite-13b-chat-v2 + - model: ibm/granite-13b-chat-v2 + platform: bam - read: def: eval message: "\nIs this a good answer[yes/no]?\n" @@ -15,6 +16,7 @@ text: text: - read: message: "Why not?\n" + contribute: [] until: ${ eval == 'yes'} diff --git a/examples/cldk/cldk-assistant.pdl b/examples/cldk/cldk-assistant.pdl index 351843557..437177fab 100644 --- a/examples/cldk/cldk-assistant.pdl +++ b/examples/cldk/cldk-assistant.pdl @@ -27,138 +27,143 @@ text: result = cldk_state - " done!" - repeat: - - read: - def: query - message: "\n\nHow can I help you [Type 'quit' to quit]?\n" - contribute: [] - - "\n***Generating PDL code for your query:\n" - - if: ${ query != 'quit'} - then: - - model: watsonx/ibm/granite-20b-code-instruct - def: PDL - input: - - | - Question: What are all the classes? - Answer: - ``` - text: - - lang: python - code: - - | - classes = PDL_SESSION.cldk_state.get_classes().keys() - result = ", ".join(classes) - ``` + text: + - read: + def: query + message: "\n\nHow can I help you [Type 'quit' to quit]?\n" + contribute: [] + - "\n***Generating PDL code for your query:\n" + - if: ${ query != 'quit'} + then: + - model: ibm/granite-20b-code-instruct + platform: bam + def: PDL + input: + - | + Question: What are all the classes? + Answer: + ``` + text: + - lan: python + code: + - | + classes = PDL_SESSION.cldk_state.get_classes().keys() + result = ", ".join(classes) + ``` - Question: What are all the constructors of class org.ibm.App? - Answer: - ``` - text: - - lang: python - code: - - | - constructors = PDL_SESSION.cldk_state.get_constructors("org.ibm.App") - result = ", ".join(constructors) - ``` + Question: What are all the constructors of class org.ibm.App? + Answer: + ``` + text: + - lan: python + code: + - | + constructors = PDL_SESSION.cldk_state.get_constructors("org.ibm.App") + result = ", ".join(constructors) + ``` - Question: What are all the fields of class org.ibm.App? - Answer: - ``` - text: - - lang: python - code: - - | - fields = PDL_SESSION.cldk_state.get_fields("org.ibm.App") - names = sum([f.variables for f in fields], []) - result = ", ".join(names) - ``` + Question: What are all the fields of class org.ibm.App? + Answer: + ``` + text: + - lan: python + code: + - | + fields = PDL_SESSION.cldk_state.get_fields("org.ibm.App") + names = sum([f.variables for f in fields], []) + result = ", ".join(names) + ``` - Question: What are all the methods of class org.ibm.App? - Answer: - ``` - text: - - lang: python - code: - - | - methods = PDL_SESSION.cldk_state.get_methods_in_class("org.ibm.App") - result = ", ".join(methods) - ``` + Question: What are all the methods of class org.ibm.App? + Answer: + ``` + text: + - lan: python + code: + - | + methods = PDL_SESSION.cldk_state.get_methods_in_class("org.ibm.App") + result = ", ".join(methods) + ``` - Question: Show me the call graph of class "org.ibm.App" - Answer: - ``` - text: - - lang: python - code: - - | - graph = PDL_SESSION.cldk_state.get_class_call_graph("org.ibm.App", method_name=None) - result = graph - ``` + Question: Show me the call graph of class "org.ibm.App" + Answer: + ``` + text: + - lan: python + code: + - | + graph = PDL_SESSION.cldk_state.get_class_call_graph("org.ibm.App", method_name=None) + result = graph + ``` - Question: What is the code of method Foo(string) of class org.ibm.App? - Answer: - ``` - text: - - lang: python - code: - - | - method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") - result = method.code - ``` + Question: What is the code of method Foo(string) of class org.ibm.App? + Answer: + ``` + text: + - lan: python + code: + - | + method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") + result = method.code + ``` - Question: Generate a summary for method Foo(string) of class org.ibm.App - Answer: - ``` - text: - - lang: python - code: - - | - method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") - result = method - - "\n\nGenerate a summary of method Foo\n\n" - - model: watsonx/meta-llama/llama-3-1-70b-instruct - ``` + Question: Generate a summary for method Foo(string) of class org.ibm.App + Answer: + ``` + text: + - lan: python + code: + - | + method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") + result = method + - "\n\nGenerate a summary of method Foo\n\n" + - model: meta-llama/llama-3-1-70b-instruct + platform: bam + ``` - Question: Generate a different comment for method Foo(string) in class org.ibm.App? - Answer: - ``` - text: - - lang: python - code: - - | - method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") - result = method - - "\n\nGenerate a different comment for method Foo(string)\n\n" - - model: watsonx/meta-llama/llama-3-1-70b-instruct - ``` + Question: Generate a different comment for method Foo(string) in class org.ibm.App? + Answer: + ``` + text: + - lan: python + code: + - | + method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") + result = method + - "\n\nGenerate a different comment for method Foo(string)\n\n" + - model: meta-llama/llama-3-1-70b-instruct + platform: bam + ``` - If the query contains something about a field be sure to call a model. - - Question: ${ query } + If the query contains something about a field be sure to call a model. + + Question: ${ query } - parameters: - stop_sequence: ["Question"] - include_stop_sequence: false - - "\n\n***Executing the above PDL code:\n\n" - - lang: python - contribute: [] - code: | - from pdl import pdl_ast, pdl_interpreter - from pdl.pdl_ast import Program - from pdl.pdl_interpreter import process_prog - from pdl.pdl_interpreter import InterpreterState - from pdl.pdl_interpreter import empty_scope - import re - import yaml - s = """'${ PDL }'""" - print(s) - pdl = s.split("```")[1] - obj = yaml.safe_load(pdl) - state = InterpreterState() - data = Program.model_validate(obj) - - result, _, _, _ = process_prog(state, empty_scope, data) + parameters: + stop_sequences: ["Question"] + include_stop_sequence: false + - "\n\n***Executing the above PDL code:\n\n" + - lan: python + contribute: [result] + code: | + from pdl import pdl_ast, pdl_interpreter + from pdl.pdl_ast import Program + from pdl.pdl_interpreter import process_prog + from pdl.pdl_interpreter import InterpreterState + from pdl.pdl_interpreter import empty_scope + import re + import yaml + s = """'${ PDL }'""" + print(s) + pdl = s.split("```")[1] + obj = yaml.safe_load(pdl) + state = InterpreterState() + data = Program.model_validate(obj) + + result, _, _, _ = process_prog(state, empty_scope, data) until: ${ query == 'quit' } + as: text diff --git a/examples/hello/test.pdl b/examples/hello/test.pdl index 1af38fdda..6bebd74b6 100644 --- a/examples/hello/test.pdl +++ b/examples/hello/test.pdl @@ -4,4 +4,6 @@ text: - "\n" - repeat: "This is your first PDL program\n" + + as: text num_iterations: 3 diff --git a/examples/talk/9-react.pdl b/examples/talk/9-react.pdl index 2356882ce..f8a852aca 100644 --- a/examples/talk/9-react.pdl +++ b/examples/talk/9-react.pdl @@ -37,7 +37,6 @@ text: stop_sequences: - "\n" parser: json - spec: {name: str, arguments: {topic: str}} - def: observation if: ${ action.name == "Search" } then: diff --git a/examples/talk/def-use.pdl b/examples/talk/def-use.pdl new file mode 100644 index 000000000..230f2cd3d --- /dev/null +++ b/examples/talk/def-use.pdl @@ -0,0 +1,13 @@ +description: Variable def and use, model input +text: +- Hello, +- model: ibm/granite-34b-code-instruct + platform: bam + def: name + parameters: + stop_sequences: ["!"] + include_stop_sequence: false +- "\n" +- model: ibm/granite-20b-multilingual + input: + - "Translate the word '${ name | trim }' to French\n" From 4090b7942adb5013624d8759b24d7bce2ad5f299 Mon Sep 17 00:00:00 2001 From: Mandana Vaziri Date: Tue, 1 Oct 2024 16:07:05 -0400 Subject: [PATCH 09/24] updated bam branch Signed-off-by: Mandana Vaziri --- examples/cldk/cldk-assistant.pdl | 2 +- examples/hello/test.pdl | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/cldk/cldk-assistant.pdl b/examples/cldk/cldk-assistant.pdl index 437177fab..686e6debc 100644 --- a/examples/cldk/cldk-assistant.pdl +++ b/examples/cldk/cldk-assistant.pdl @@ -163,7 +163,7 @@ text: result, _, _, _ = process_prog(state, empty_scope, data) until: ${ query == 'quit' } - as: text + diff --git a/examples/hello/test.pdl b/examples/hello/test.pdl index 6bebd74b6..1af38fdda 100644 --- a/examples/hello/test.pdl +++ b/examples/hello/test.pdl @@ -4,6 +4,4 @@ text: - "\n" - repeat: "This is your first PDL program\n" - - as: text num_iterations: 3 From 2a9331393016bde0de6c0a0aa46db70c9b78b428 Mon Sep 17 00:00:00 2001 From: Mandana Vaziri Date: Wed, 9 Oct 2024 22:21:54 -0400 Subject: [PATCH 10/24] bam examples cleanup Signed-off-by: Mandana Vaziri --- examples/chatbot/chatbot.pdl | 2 +- examples/cldk/cldk-assistant.pdl | 6 +++--- examples/tools/calc.pdl | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/chatbot/chatbot.pdl b/examples/chatbot/chatbot.pdl index 262a66e02..df4a9a61f 100644 --- a/examples/chatbot/chatbot.pdl +++ b/examples/chatbot/chatbot.pdl @@ -10,7 +10,7 @@ text: - read: def: eval message: "\nIs this a good answer[yes/no]?\n" - contribute: [] + contribute: [context] - if: ${ eval == 'no' } then: text: diff --git a/examples/cldk/cldk-assistant.pdl b/examples/cldk/cldk-assistant.pdl index 686e6debc..796b2a535 100644 --- a/examples/cldk/cldk-assistant.pdl +++ b/examples/cldk/cldk-assistant.pdl @@ -35,7 +35,7 @@ text: - "\n***Generating PDL code for your query:\n" - if: ${ query != 'quit'} then: - - model: ibm/granite-20b-code-instruct + - model: ibm/granite-34b-code-instruct platform: bam def: PDL input: @@ -117,7 +117,7 @@ text: method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") result = method - "\n\nGenerate a summary of method Foo\n\n" - - model: meta-llama/llama-3-1-70b-instruct + - model: ibm/granite-34b-code-instruct platform: bam ``` @@ -131,7 +131,7 @@ text: method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") result = method - "\n\nGenerate a different comment for method Foo(string)\n\n" - - model: meta-llama/llama-3-1-70b-instruct + - model: ibm/granite-34b-code-instruct platform: bam ``` diff --git a/examples/tools/calc.pdl b/examples/tools/calc.pdl index 188745c71..004bdf7f6 100644 --- a/examples/tools/calc.pdl +++ b/examples/tools/calc.pdl @@ -17,7 +17,7 @@ text: Out of 1400 participants, 400 passed the test. What percentage is that? Act: - def: action - model: ibm/granite-8b-code-instruct + model: ibm/granite-34b-code-instruct platform: bam parameters: stop_sequences: ["\n"] From 88a440cb52af9832c91273d81cfa8802c704a90c Mon Sep 17 00:00:00 2001 From: Mandana Vaziri Date: Thu, 10 Oct 2024 07:07:51 -0400 Subject: [PATCH 11/24] update to demo notebook Signed-off-by: Mandana Vaziri --- examples/notebooks/demo.ipynb | 231 +++++++++++++++++++++++++++++----- 1 file changed, 202 insertions(+), 29 deletions(-) diff --git a/examples/notebooks/demo.ipynb b/examples/notebooks/demo.ipynb index 3b7f6598b..d15d3f1bb 100644 --- a/examples/notebooks/demo.ipynb +++ b/examples/notebooks/demo.ipynb @@ -7,12 +7,190 @@ "source": [ "# Prompt Declaration Language\n", "\n", - "The Prompt Declaration Language (PDL) is a yaml-based declarative approach to prompt programming. PDL facilitates model chaining and tool use, enables type checking of the input and output of models, and is based on LiteLLM to support a variety of model providers. PDL has been used for: RAG, CoT, ReAct prompting patterns and is being used in the SWE Agent-102. PDL is [open-source](https://github.com/IBM/prompt-declaration-language) and works well with watsonx.ai and Granite models.\n" + "Prompt engineering is difficult: minor variations in prompts have large impacts on the output of LLMs and prompts are model-dependent. In recent years prompt programming languages have emerged to bring discipline to prompt engineering. Many of them are embedded in an imperative language such as Python or TypeScript, making it difficult for users to directly interact with prompts and multi-turn LLM interactions.\n", + "\n", + "The Prompt Declaration Language (PDL) is a yaml-based declarative approach to prompt programming, where prompts are at the forefront. PDL facilitates model chaining and tool use, abstracting away the plumbing necessary for such compositions, enables type checking of the input and output of models, and is based on LiteLLM to support a variety of model providers. PDL has been used with RAG, CoT, ReAct, and an agent for solving SWE-bench. PDL is [open-source](https://github.com/IBM/prompt-declaration-language) and works well with watsonx.ai and Granite models.\n", + "\n", + "All examples in this notebook use the new ibm/granite-8b-instruct-preview-4k model. You can use PDL stand-alone or from a Python SDK or, as shown here, in a notebook via a notebook extension. In the cell output, model-generated text is rendered in green font, and tool-generated text is rendered in purple font." ] }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 4, + "id": "ca2e7ba6-e0f0-4d88-a083-5ff257ed2c34", + "metadata": { + "collapsed": true, + "jupyter": { + "outputs_hidden": true + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: prompt-declaration-language in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (0.0.7.dev6+g11f5271.d20241010)\n", + "Requirement already satisfied: pydantic~=2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language) (2.9.1)\n", + "Requirement already satisfied: ibm-generative-ai~=3.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language) (3.0.0)\n", + "Requirement already satisfied: requests~=2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language) (2.32.3)\n", + "Requirement already satisfied: python-dotenv~=1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language) (1.0.1)\n", + "Requirement already satisfied: jinja2~=3.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language) (3.1.4)\n", + "Requirement already satisfied: PyYAML~=6.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language) (6.0.2)\n", + "Requirement already satisfied: jsonschema~=4.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language) (4.23.0)\n", + "Requirement already satisfied: litellm~=1.47 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language) (1.49.0)\n", + "Requirement already satisfied: termcolor~=2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language) (2.4.0)\n", + "Requirement already satisfied: ipython~=8.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language) (8.27.0)\n", + "Requirement already satisfied: aiolimiter<2.0.0,>=1.1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ibm-generative-ai~=3.0->prompt-declaration-language) (1.1.0)\n", + "Requirement already satisfied: deprecated<2.0.0,>=1.2.14 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ibm-generative-ai~=3.0->prompt-declaration-language) (1.2.14)\n", + "Requirement already satisfied: httpx<0.28.0,>=0.27.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ibm-generative-ai~=3.0->prompt-declaration-language) (0.27.2)\n", + "Requirement already satisfied: httpx-sse<0.5.0,>=0.4.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ibm-generative-ai~=3.0->prompt-declaration-language) (0.4.0)\n", + "Requirement already satisfied: decorator in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language) (5.1.1)\n", + "Requirement already satisfied: jedi>=0.16 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language) (0.19.1)\n", + "Requirement already satisfied: matplotlib-inline in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language) (0.1.7)\n", + "Requirement already satisfied: prompt-toolkit<3.1.0,>=3.0.41 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language) (3.0.47)\n", + "Requirement already satisfied: pygments>=2.4.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language) (2.18.0)\n", + "Requirement already satisfied: stack-data in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language) (0.6.3)\n", + "Requirement already satisfied: traitlets>=5.13.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language) (5.14.3)\n", + "Requirement already satisfied: pexpect>4.3 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language) (4.9.0)\n", + "Requirement already satisfied: MarkupSafe>=2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jinja2~=3.0->prompt-declaration-language) (2.1.5)\n", + "Requirement already satisfied: attrs>=22.2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jsonschema~=4.0->prompt-declaration-language) (24.2.0)\n", + "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jsonschema~=4.0->prompt-declaration-language) (2023.12.1)\n", + "Requirement already satisfied: referencing>=0.28.4 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jsonschema~=4.0->prompt-declaration-language) (0.35.1)\n", + "Requirement already satisfied: rpds-py>=0.7.1 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jsonschema~=4.0->prompt-declaration-language) (0.20.0)\n", + "Requirement already satisfied: aiohttp in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from litellm~=1.47->prompt-declaration-language) (3.10.5)\n", + "Requirement already satisfied: click in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from litellm~=1.47->prompt-declaration-language) (8.1.7)\n", + "Requirement already satisfied: importlib-metadata>=6.8.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from litellm~=1.47->prompt-declaration-language) (8.4.0)\n", + "Requirement already satisfied: openai>=1.51.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from litellm~=1.47->prompt-declaration-language) (1.51.0)\n", + "Requirement already satisfied: tiktoken>=0.7.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from litellm~=1.47->prompt-declaration-language) (0.7.0)\n", + "Requirement already satisfied: tokenizers in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from litellm~=1.47->prompt-declaration-language) (0.19.1)\n", + "Requirement already satisfied: annotated-types>=0.6.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pydantic~=2.0->prompt-declaration-language) (0.7.0)\n", + "Requirement already satisfied: pydantic-core==2.23.3 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pydantic~=2.0->prompt-declaration-language) (2.23.3)\n", + "Requirement already satisfied: typing-extensions>=4.6.1 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pydantic~=2.0->prompt-declaration-language) (4.12.2)\n", + "Requirement already satisfied: charset-normalizer<4,>=2 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from requests~=2.0->prompt-declaration-language) (3.3.2)\n", + "Requirement already satisfied: idna<4,>=2.5 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from requests~=2.0->prompt-declaration-language) (3.10)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from requests~=2.0->prompt-declaration-language) (1.26.20)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from requests~=2.0->prompt-declaration-language) (2024.8.30)\n", + "Requirement already satisfied: wrapt<2,>=1.10 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from deprecated<2.0.0,>=1.2.14->ibm-generative-ai~=3.0->prompt-declaration-language) (1.16.0)\n", + "Requirement already satisfied: anyio in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from httpx<0.28.0,>=0.27.0->ibm-generative-ai~=3.0->prompt-declaration-language) (4.4.0)\n", + "Requirement already satisfied: httpcore==1.* in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from httpx<0.28.0,>=0.27.0->ibm-generative-ai~=3.0->prompt-declaration-language) (1.0.5)\n", + "Requirement already satisfied: sniffio in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from httpx<0.28.0,>=0.27.0->ibm-generative-ai~=3.0->prompt-declaration-language) (1.3.1)\n", + "Requirement already satisfied: h11<0.15,>=0.13 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from httpcore==1.*->httpx<0.28.0,>=0.27.0->ibm-generative-ai~=3.0->prompt-declaration-language) (0.14.0)\n", + "Requirement already satisfied: zipp>=0.5 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from importlib-metadata>=6.8.0->litellm~=1.47->prompt-declaration-language) (3.20.1)\n", + "Requirement already satisfied: parso<0.9.0,>=0.8.3 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jedi>=0.16->ipython~=8.0->prompt-declaration-language) (0.8.4)\n", + "Requirement already satisfied: distro<2,>=1.7.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from openai>=1.51.0->litellm~=1.47->prompt-declaration-language) (1.9.0)\n", + "Requirement already satisfied: jiter<1,>=0.4.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from openai>=1.51.0->litellm~=1.47->prompt-declaration-language) (0.5.0)\n", + "Requirement already satisfied: tqdm>4 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from openai>=1.51.0->litellm~=1.47->prompt-declaration-language) (4.66.5)\n", + "Requirement already satisfied: ptyprocess>=0.5 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pexpect>4.3->ipython~=8.0->prompt-declaration-language) (0.7.0)\n", + "Requirement already satisfied: wcwidth in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-toolkit<3.1.0,>=3.0.41->ipython~=8.0->prompt-declaration-language) (0.2.13)\n", + "Requirement already satisfied: regex>=2022.1.18 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from tiktoken>=0.7.0->litellm~=1.47->prompt-declaration-language) (2024.7.24)\n", + "Requirement already satisfied: aiohappyeyeballs>=2.3.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from aiohttp->litellm~=1.47->prompt-declaration-language) (2.4.0)\n", + "Requirement already satisfied: aiosignal>=1.1.2 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from aiohttp->litellm~=1.47->prompt-declaration-language) (1.3.1)\n", + "Requirement already satisfied: frozenlist>=1.1.1 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from aiohttp->litellm~=1.47->prompt-declaration-language) (1.4.1)\n", + "Requirement already satisfied: multidict<7.0,>=4.5 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from aiohttp->litellm~=1.47->prompt-declaration-language) (6.1.0)\n", + "Requirement already satisfied: yarl<2.0,>=1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from aiohttp->litellm~=1.47->prompt-declaration-language) (1.11.1)\n", + "Requirement already satisfied: executing>=1.2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from stack-data->ipython~=8.0->prompt-declaration-language) (2.1.0)\n", + "Requirement already satisfied: asttokens>=2.1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from stack-data->ipython~=8.0->prompt-declaration-language) (2.4.1)\n", + "Requirement already satisfied: pure-eval in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from stack-data->ipython~=8.0->prompt-declaration-language) (0.2.3)\n", + "Requirement already satisfied: huggingface-hub<1.0,>=0.16.4 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from tokenizers->litellm~=1.47->prompt-declaration-language) (0.24.7)\n", + "Requirement already satisfied: six>=1.12.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from asttokens>=2.1.0->stack-data->ipython~=8.0->prompt-declaration-language) (1.16.0)\n", + "Requirement already satisfied: filelock in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from huggingface-hub<1.0,>=0.16.4->tokenizers->litellm~=1.47->prompt-declaration-language) (3.16.0)\n", + "Requirement already satisfied: fsspec>=2023.5.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from huggingface-hub<1.0,>=0.16.4->tokenizers->litellm~=1.47->prompt-declaration-language) (2024.6.1)\n", + "Requirement already satisfied: packaging>=20.9 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from huggingface-hub<1.0,>=0.16.4->tokenizers->litellm~=1.47->prompt-declaration-language) (24.1)\n", + "Requirement already satisfied: prompt-declaration-language[examples] in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (0.0.7.dev6+g11f5271.d20241010)\n", + "Requirement already satisfied: pydantic~=2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (2.9.1)\n", + "Requirement already satisfied: ibm-generative-ai~=3.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (3.0.0)\n", + "Requirement already satisfied: requests~=2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (2.32.3)\n", + "Requirement already satisfied: python-dotenv~=1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (1.0.1)\n", + "Requirement already satisfied: jinja2~=3.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (3.1.4)\n", + "Requirement already satisfied: PyYAML~=6.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (6.0.2)\n", + "Requirement already satisfied: jsonschema~=4.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (4.23.0)\n", + "Requirement already satisfied: litellm~=1.47 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (1.49.0)\n", + "Requirement already satisfied: termcolor~=2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (2.4.0)\n", + "Requirement already satisfied: ipython~=8.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (8.27.0)\n", + "Requirement already satisfied: wikipedia~=1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (1.4.0)\n", + "Requirement already satisfied: textdistance~=4.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (4.6.3)\n", + "Requirement already satisfied: faiss-cpu~=1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (1.8.0.post1)\n", + "Requirement already satisfied: datasets<4,>2 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (3.0.1)\n", + "Requirement already satisfied: sympy~=1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (1.13.2)\n", + "Requirement already satisfied: filelock in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (3.16.0)\n", + "Requirement already satisfied: numpy>=1.17 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (1.26.4)\n", + "Requirement already satisfied: pyarrow>=15.0.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (17.0.0)\n", + "Requirement already satisfied: dill<0.3.9,>=0.3.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (0.3.8)\n", + "Requirement already satisfied: pandas in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (2.2.2)\n", + "Requirement already satisfied: tqdm>=4.66.3 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (4.66.5)\n", + "Requirement already satisfied: xxhash in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (3.5.0)\n", + "Requirement already satisfied: multiprocess in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (0.70.16)\n", + "Requirement already satisfied: fsspec<=2024.6.1,>=2023.1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from fsspec[http]<=2024.6.1,>=2023.1.0->datasets<4,>2->prompt-declaration-language[examples]) (2024.6.1)\n", + "Requirement already satisfied: aiohttp in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (3.10.5)\n", + "Requirement already satisfied: huggingface-hub>=0.22.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (0.24.7)\n", + "Requirement already satisfied: packaging in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (24.1)\n", + "Requirement already satisfied: aiolimiter<2.0.0,>=1.1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ibm-generative-ai~=3.0->prompt-declaration-language[examples]) (1.1.0)\n", + "Requirement already satisfied: deprecated<2.0.0,>=1.2.14 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ibm-generative-ai~=3.0->prompt-declaration-language[examples]) (1.2.14)\n", + "Requirement already satisfied: httpx<0.28.0,>=0.27.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ibm-generative-ai~=3.0->prompt-declaration-language[examples]) (0.27.2)\n", + "Requirement already satisfied: httpx-sse<0.5.0,>=0.4.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ibm-generative-ai~=3.0->prompt-declaration-language[examples]) (0.4.0)\n", + "Requirement already satisfied: decorator in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language[examples]) (5.1.1)\n", + "Requirement already satisfied: jedi>=0.16 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language[examples]) (0.19.1)\n", + "Requirement already satisfied: matplotlib-inline in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language[examples]) (0.1.7)\n", + "Requirement already satisfied: prompt-toolkit<3.1.0,>=3.0.41 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language[examples]) (3.0.47)\n", + "Requirement already satisfied: pygments>=2.4.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language[examples]) (2.18.0)\n", + "Requirement already satisfied: stack-data in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language[examples]) (0.6.3)\n", + "Requirement already satisfied: traitlets>=5.13.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language[examples]) (5.14.3)\n", + "Requirement already satisfied: pexpect>4.3 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language[examples]) (4.9.0)\n", + "Requirement already satisfied: MarkupSafe>=2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jinja2~=3.0->prompt-declaration-language[examples]) (2.1.5)\n", + "Requirement already satisfied: attrs>=22.2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jsonschema~=4.0->prompt-declaration-language[examples]) (24.2.0)\n", + "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jsonschema~=4.0->prompt-declaration-language[examples]) (2023.12.1)\n", + "Requirement already satisfied: referencing>=0.28.4 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jsonschema~=4.0->prompt-declaration-language[examples]) (0.35.1)\n", + "Requirement already satisfied: rpds-py>=0.7.1 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jsonschema~=4.0->prompt-declaration-language[examples]) (0.20.0)\n", + "Requirement already satisfied: click in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from litellm~=1.47->prompt-declaration-language[examples]) (8.1.7)\n", + "Requirement already satisfied: importlib-metadata>=6.8.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from litellm~=1.47->prompt-declaration-language[examples]) (8.4.0)\n", + "Requirement already satisfied: openai>=1.51.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from litellm~=1.47->prompt-declaration-language[examples]) (1.51.0)\n", + "Requirement already satisfied: tiktoken>=0.7.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from litellm~=1.47->prompt-declaration-language[examples]) (0.7.0)\n", + "Requirement already satisfied: tokenizers in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from litellm~=1.47->prompt-declaration-language[examples]) (0.19.1)\n", + "Requirement already satisfied: annotated-types>=0.6.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pydantic~=2.0->prompt-declaration-language[examples]) (0.7.0)\n", + "Requirement already satisfied: pydantic-core==2.23.3 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pydantic~=2.0->prompt-declaration-language[examples]) (2.23.3)\n", + "Requirement already satisfied: typing-extensions>=4.6.1 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pydantic~=2.0->prompt-declaration-language[examples]) (4.12.2)\n", + "Requirement already satisfied: charset-normalizer<4,>=2 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from requests~=2.0->prompt-declaration-language[examples]) (3.3.2)\n", + "Requirement already satisfied: idna<4,>=2.5 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from requests~=2.0->prompt-declaration-language[examples]) (3.10)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from requests~=2.0->prompt-declaration-language[examples]) (1.26.20)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from requests~=2.0->prompt-declaration-language[examples]) (2024.8.30)\n", + "Requirement already satisfied: mpmath<1.4,>=1.1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from sympy~=1.0->prompt-declaration-language[examples]) (1.3.0)\n", + "Requirement already satisfied: beautifulsoup4 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from wikipedia~=1.0->prompt-declaration-language[examples]) (4.12.3)\n", + "Requirement already satisfied: wrapt<2,>=1.10 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from deprecated<2.0.0,>=1.2.14->ibm-generative-ai~=3.0->prompt-declaration-language[examples]) (1.16.0)\n", + "Requirement already satisfied: aiohappyeyeballs>=2.3.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from aiohttp->datasets<4,>2->prompt-declaration-language[examples]) (2.4.0)\n", + "Requirement already satisfied: aiosignal>=1.1.2 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from aiohttp->datasets<4,>2->prompt-declaration-language[examples]) (1.3.1)\n", + "Requirement already satisfied: frozenlist>=1.1.1 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from aiohttp->datasets<4,>2->prompt-declaration-language[examples]) (1.4.1)\n", + "Requirement already satisfied: multidict<7.0,>=4.5 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from aiohttp->datasets<4,>2->prompt-declaration-language[examples]) (6.1.0)\n", + "Requirement already satisfied: yarl<2.0,>=1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from aiohttp->datasets<4,>2->prompt-declaration-language[examples]) (1.11.1)\n", + "Requirement already satisfied: anyio in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from httpx<0.28.0,>=0.27.0->ibm-generative-ai~=3.0->prompt-declaration-language[examples]) (4.4.0)\n", + "Requirement already satisfied: httpcore==1.* in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from httpx<0.28.0,>=0.27.0->ibm-generative-ai~=3.0->prompt-declaration-language[examples]) (1.0.5)\n", + "Requirement already satisfied: sniffio in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from httpx<0.28.0,>=0.27.0->ibm-generative-ai~=3.0->prompt-declaration-language[examples]) (1.3.1)\n", + "Requirement already satisfied: h11<0.15,>=0.13 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from httpcore==1.*->httpx<0.28.0,>=0.27.0->ibm-generative-ai~=3.0->prompt-declaration-language[examples]) (0.14.0)\n", + "Requirement already satisfied: zipp>=0.5 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from importlib-metadata>=6.8.0->litellm~=1.47->prompt-declaration-language[examples]) (3.20.1)\n", + "Requirement already satisfied: parso<0.9.0,>=0.8.3 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jedi>=0.16->ipython~=8.0->prompt-declaration-language[examples]) (0.8.4)\n", + "Requirement already satisfied: distro<2,>=1.7.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from openai>=1.51.0->litellm~=1.47->prompt-declaration-language[examples]) (1.9.0)\n", + "Requirement already satisfied: jiter<1,>=0.4.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from openai>=1.51.0->litellm~=1.47->prompt-declaration-language[examples]) (0.5.0)\n", + "Requirement already satisfied: ptyprocess>=0.5 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pexpect>4.3->ipython~=8.0->prompt-declaration-language[examples]) (0.7.0)\n", + "Requirement already satisfied: wcwidth in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-toolkit<3.1.0,>=3.0.41->ipython~=8.0->prompt-declaration-language[examples]) (0.2.13)\n", + "Requirement already satisfied: regex>=2022.1.18 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from tiktoken>=0.7.0->litellm~=1.47->prompt-declaration-language[examples]) (2024.7.24)\n", + "Requirement already satisfied: soupsieve>1.2 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from beautifulsoup4->wikipedia~=1.0->prompt-declaration-language[examples]) (2.6)\n", + "Requirement already satisfied: python-dateutil>=2.8.2 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pandas->datasets<4,>2->prompt-declaration-language[examples]) (2.9.0.post0)\n", + "Requirement already satisfied: pytz>=2020.1 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pandas->datasets<4,>2->prompt-declaration-language[examples]) (2024.2)\n", + "Requirement already satisfied: tzdata>=2022.7 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pandas->datasets<4,>2->prompt-declaration-language[examples]) (2024.1)\n", + "Requirement already satisfied: executing>=1.2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from stack-data->ipython~=8.0->prompt-declaration-language[examples]) (2.1.0)\n", + "Requirement already satisfied: asttokens>=2.1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from stack-data->ipython~=8.0->prompt-declaration-language[examples]) (2.4.1)\n", + "Requirement already satisfied: pure-eval in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from stack-data->ipython~=8.0->prompt-declaration-language[examples]) (0.2.3)\n", + "Requirement already satisfied: six>=1.12.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from asttokens>=2.1.0->stack-data->ipython~=8.0->prompt-declaration-language[examples]) (1.16.0)\n" + ] + } + ], + "source": [ + "! pip install prompt-declaration-language\n", + "! pip install 'prompt-declaration-language[examples]'" + ] + }, + { + "cell_type": "code", + "execution_count": 2, "id": "e25a6874-54d9-4167-82ed-ab2f4fdc0a6f", "metadata": {}, "outputs": [], @@ -27,7 +205,7 @@ "source": [ "## Model call\n", "\n", - "In PDL, prompts are the forefront and the user specifies step-by-step the shape of data they want to generate. In the following, the `text` construct indicates a text block containing a prompt and a model call. Implicitly PDL builds a background conversational context (list of role/content) which is used to make model calls." + "In PDL, prompts are the forefront and the user specifies step-by-step the shape of data they want to generate. In the following, the `text` construct indicates a text block containing a prompt and a model call. Implicitly PDL builds a background conversational context (list of role/content) which is used to make model calls. Each model call uses the context built so far as its input prompt." ] }, { @@ -59,7 +237,7 @@ "metadata": {}, "source": [ "## Model chaining\n", - "Model chaining can be done by simply adding to the list of models to call declaratively. " + "Model chaining can be done by simply adding to the list of models to call declaratively. Since this cell has the `%%pdl` cell magic without `--reset-context`, it executes in the context created by the previous cell." ] }, { @@ -113,7 +291,7 @@ "source": [ "## Chat templates\n", "\n", - "The second call to the model in the above program submits the following prompt. PDL takes care of applying the appropriate prompt templates and tags, and builds the background context implicitly. All the user has to do is list the models they want to chain, PDL takes care of the rest.\n", + "The second call to the model in the above program submits the following prompt. PDL takes care of applying the appropriate chat templates and tags, and builds the background context implicitly. Chat templates make your program easier to port across models, since you do not need to specify control tokens by hand. All the user has to do is list the models they want to chain, PDL takes care of the rest.\n", "\n", "```\n", "<|start_of_role|>user<|end_of_role|>What is the meaning of life?\n", @@ -239,7 +417,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 16, "id": "b7ff8708-7a82-492d-a91b-2ff4a17c768e", "metadata": { "scrolled": true @@ -249,21 +427,15 @@ "name": "stdout", "output_type": "stream", "text": [ - "How many years ago was the Hubble telescope launched? Keep in mind we are in 2024.\n", - "\n", - "\u001b[32mTh\u001b[0m\u001b[32mo\u001b[0m\u001b[32m:\u001b[0m\u001b[32m I\u001b[0m\u001b[32m need\u001b[0m\u001b[32m to\u001b[0m\u001b[32m search\u001b[0m\u001b[32m H\u001b[0m\u001b[32mubble\u001b[0m\u001b[32m te\u001b[0m\u001b[32mlescope\u001b[0m\u001b[32m,\u001b[0m\u001b[32m find\u001b[0m\u001b[32m its\u001b[0m\u001b[32m launch\u001b[0m\u001b[32m date\u001b[0m\u001b[32m,\u001b[0m\u001b[32m then\u001b[0m\u001b[32m calculate\u001b[0m\u001b[32m how\u001b[0m\u001b[32m many\u001b[0m\u001b[32m years\u001b[0m\u001b[32m ago\u001b[0m\u001b[32m it\u001b[0m\u001b[32m was\u001b[0m\u001b[32m launched\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mAct\u001b[0m\u001b[32m:\u001b[0m\u001b[32m {\"\u001b[0m\u001b[32mname\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m \"\u001b[0m\u001b[32mSearch\u001b[0m\u001b[32m\",\u001b[0m\u001b[32m \"\u001b[0m\u001b[32marguments\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m {\"\u001b[0m\u001b[32mtopic\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m \"\u001b[0m\u001b[32mHub\u001b[0m\u001b[32mble\u001b[0m\u001b[32m te\u001b[0m\u001b[32mlescope\u001b[0m\u001b[32m\"}}\u001b[0m\u001b[32m\n", - "\u001b[0mObs: \u001b[35mThe Hubble Space Telescope (often referred to as HST or Hubble) is a space telescope that was launched into low Earth orbit in 1990 and remains in operation. It was not the first space telescope, but it is one of the largest and most versatile, renowned as a vital research tool and as a public relations boon for astronomy. The Hubble telescope is named after astronomer Edwin Hubble and is one of NASA's Great Observatories. The Space Telescope Science Institute (STScI) selects Hubble's targets and processes the resulting data, while the Goddard Space Flight Center (GSFC) controls the spacecraft. \n", - "Hubble features a 2.4 m (7 ft 10 in) mirror, and its five main instruments observe in the ultraviolet, visible, and near-infrared regions of the electromagnetic spectrum. Hubble's orbit outside the distortion of Earth's atmosphere allows it to capture extremely high-resolution images with substantially lower background light than ground-based telescopes. It has recorded some of the most detailed visible light images, allowing a deep view into space. Many Hubble observations have led to breakthroughs in astrophysics, such as determining the rate of expansion of the universe.\n", - "Space telescopes were proposed as early as 1923, and the Hubble telescope was funded and built in the 1970s by the United States space agency NASA with contributions from the European Space Agency. Its intended launch was in 1983, but the project was beset by technical delays, budget problems, and the 1986 Challenger disaster. Hubble was finally launched in 1990, but its main mirror had been ground incorrectly, resulting in spherical aberration that compromised the telescope's capabilities. The optics were corrected to their intended quality by a servicing mission in 1993.\n", - "Hubble is the only telescope designed to be maintained in space by astronauts. Five Space Shuttle missions have repaired, upgraded, and replaced systems on the telescope, including all five of the main instruments. The fifth mission was initially canceled on safety grounds following the Columbia disaster (2003), but after NASA administrator Michael D. Griffin approved it, the servicing mission was completed in 2009. Hubble completed 30 years of operation in April 2020 and is predicted to last until 2030 to 2040.\n", - "Hubble is the visible light telescope in NASA's Great Observatories program; other parts of the spectrum are covered by the Compton Gamma Ray Observatory, the Chandra X-ray Observatory, and the Spitzer Space Telescope (which covers the infrared bands).\n", - "The mid-IR-to-visible band successor to the Hubble telescope is the James Webb Space Telescope (JWST), which was launched on December 25, 2021, with the Nancy Grace Roman Space Telescope due to follow in 2027.\n", - "\n", - "\u001b[0m\n", - "\u001b[32mTh\u001b[0m\u001b[32mo\u001b[0m\u001b[32m:\u001b[0m\u001b[32m The\u001b[0m\u001b[32m H\u001b[0m\u001b[32mubble\u001b[0m\u001b[32m te\u001b[0m\u001b[32mlescope\u001b[0m\u001b[32m was\u001b[0m\u001b[32m launched\u001b[0m\u001b[32m in\u001b[0m\u001b[32m \u001b[0m\u001b[32m1\u001b[0m\u001b[32m9\u001b[0m\u001b[32m9\u001b[0m\u001b[32m0\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mAct\u001b[0m\u001b[32m:\u001b[0m\u001b[32m {\"\u001b[0m\u001b[32mname\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m \"\u001b[0m\u001b[32mCalc\u001b[0m\u001b[32m\",\u001b[0m\u001b[32m \"\u001b[0m\u001b[32marguments\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m {\"\u001b[0m\u001b[32mexpr\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m \"\u001b[0m\u001b[32m2\u001b[0m\u001b[32m0\u001b[0m\u001b[32m2\u001b[0m\u001b[32m4\u001b[0m\u001b[32m -\u001b[0m\u001b[32m \u001b[0m\u001b[32m1\u001b[0m\u001b[32m9\u001b[0m\u001b[32m9\u001b[0m\u001b[32m0\u001b[0m\u001b[32m\"}}\u001b[0m\u001b[32m\n", - "\u001b[0mObs: \u001b[35m34\u001b[0m\n" + "How many years ago was the discoverer of the Hudson River born? Keep in mind we are in 2024.\n", + "\u001b[32mAct\u001b[0m\u001b[32m:\u001b[0m\u001b[32m{\"\u001b[0m\u001b[32mname\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m \"\u001b[0m\u001b[32mSearch\u001b[0m\u001b[32m\",\u001b[0m\u001b[32m \"\u001b[0m\u001b[32marguments\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m {\"\u001b[0m\u001b[32mtopic\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m \"\u001b[0m\u001b[32mH\u001b[0m\u001b[32men\u001b[0m\u001b[32mry\u001b[0m\u001b[32m H\u001b[0m\u001b[32mudson\u001b[0m\u001b[32m\"}}\u001b[0m\u001b[32m\n", + "\u001b[0mObs: \u001b[35mHenry Hudson (c. 1565 – disappeared 23 June 1611) was an English sea explorer and navigator during the early 17th century, best known for his explorations of present-day Canada and parts of the Northeastern United States.\n", + "In 1607 and 1608, Hudson made two attempts on behalf of English merchants to find a rumoured Northeast Passage to Cathay via a route above the Arctic Circle. In 1609, he landed in North America on behalf of the Dutch East India Company and explored the region around the modern New York metropolitan area. Looking for a Northwest Passage to Asia on his ship Halve Maen (\"Half Moon\"), he sailed up the Hudson River, which was later named after him, and thereby laid the foundation for Dutch colonization of the region. His contributions to the exploration of the New World were significant and lasting. His voyages helped to establish European contact with the native peoples of North America and contributed to the development of trade and commerce. \n", + "On his final expedition, while still searching for the Northwest Passage, Hudson became the first European to see Hudson Strait and the immense Hudson Bay. In 1611, after wintering on the shore of James Bay, Hudson wanted to press on to the west, but most of his crew mutinied. The mutineers cast Hudson, his son, and six others adrift; the Hudsons and their companions were never seen again.\u001b[0m\n", + "\u001b[32mH\u001b[0m\u001b[32men\u001b[0m\u001b[32mry\u001b[0m\u001b[32m H\u001b[0m\u001b[32mudson\u001b[0m\u001b[32m was\u001b[0m\u001b[32m born\u001b[0m\u001b[32m in\u001b[0m\u001b[32m the\u001b[0m\u001b[32m late\u001b[0m\u001b[32m \u001b[0m\u001b[32m1\u001b[0m\u001b[32m6\u001b[0m\u001b[32mth\u001b[0m\u001b[32m cent\u001b[0m\u001b[32mury\u001b[0m\u001b[32m,\u001b[0m\u001b[32m around\u001b[0m\u001b[32m \u001b[0m\u001b[32m1\u001b[0m\u001b[32m5\u001b[0m\u001b[32m6\u001b[0m\u001b[32m5\u001b[0m\u001b[32m.\u001b[0m\u001b[32m To\u001b[0m\u001b[32m find\u001b[0m\u001b[32m out\u001b[0m\u001b[32m how\u001b[0m\u001b[32m many\u001b[0m\u001b[32m years\u001b[0m\u001b[32m ago\u001b[0m\u001b[32m he\u001b[0m\u001b[32m was\u001b[0m\u001b[32m born\u001b[0m\u001b[32m,\u001b[0m\u001b[32m we\u001b[0m\u001b[32m need\u001b[0m\u001b[32m to\u001b[0m\u001b[32m subtract\u001b[0m\u001b[32m his\u001b[0m\u001b[32m birth\u001b[0m\u001b[32m year\u001b[0m\u001b[32m from\u001b[0m\u001b[32m the\u001b[0m\u001b[32m current\u001b[0m\u001b[32m year\u001b[0m\u001b[32m,\u001b[0m\u001b[32m which\u001b[0m\u001b[32m is\u001b[0m\u001b[32m \u001b[0m\u001b[32m2\u001b[0m\u001b[32m0\u001b[0m\u001b[32m2\u001b[0m\u001b[32m4\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mAct\u001b[0m\u001b[32m:\u001b[0m\u001b[32m{\"\u001b[0m\u001b[32mname\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m \"\u001b[0m\u001b[32mCalc\u001b[0m\u001b[32m\",\u001b[0m\u001b[32m \"\u001b[0m\u001b[32marguments\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m {\"\u001b[0m\u001b[32mexpr\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m \"\u001b[0m\u001b[32m2\u001b[0m\u001b[32m0\u001b[0m\u001b[32m2\u001b[0m\u001b[32m4\u001b[0m\u001b[32m -\u001b[0m\u001b[32m \u001b[0m\u001b[32m1\u001b[0m\u001b[32m5\u001b[0m\u001b[32m6\u001b[0m\u001b[32m5\u001b[0m\u001b[32m\"}}\u001b[0m\u001b[32m\n", + "\u001b[0mObs: \u001b[35m459\u001b[0m\n" ] } ], @@ -272,7 +444,7 @@ "text:\n", "- read: demonstrations.txt\n", " contribute: [context]\n", - "- \"How many years ago was the Hubble telescope launched? Keep in mind we are in 2024.\\n\\n\"\n", + "- \"How many years ago was the discoverer of the Hudson River born? Keep in mind we are in 2024.\\n\"\n", "- repeat:\n", " text:\n", " - def: thought\n", @@ -310,17 +482,18 @@ " - lang: python\n", " code: result = ${ action.arguments.expr }\n", " - \"\\n\"\n", - " until: ${ action.name != \"Search\" }\n", - "\n" + " until: ${ action.name != \"Search\" }" ] }, { - "cell_type": "code", - "execution_count": null, - "id": "bf0c64df-2d8e-4606-acc4-f46169c189f4", + "cell_type": "markdown", + "id": "89438b62-29e4-472e-89ec-57c1626ffd44", "metadata": {}, - "outputs": [], - "source": [] + "source": [ + "## Conclusion\n", + "\n", + "Since prompts are at the forefront, PDL makes users more productive in their trial-and-error with LLMs. PDL is a representation for prompting that can be used not only for low-level prompting, but as" + ] } ], "metadata": { From b1e0a2c99cf0d0cb9db847aface9dbc4333f7760 Mon Sep 17 00:00:00 2001 From: Mandana Vaziri Date: Thu, 10 Oct 2024 07:11:33 -0400 Subject: [PATCH 12/24] update to demo notebook Signed-off-by: Mandana Vaziri --- examples/notebooks/demo.ipynb | 171 +--------------------------------- 1 file changed, 4 insertions(+), 167 deletions(-) diff --git a/examples/notebooks/demo.ipynb b/examples/notebooks/demo.ipynb index d15d3f1bb..aa29445e7 100644 --- a/examples/notebooks/demo.ipynb +++ b/examples/notebooks/demo.ipynb @@ -16,173 +16,10 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "id": "ca2e7ba6-e0f0-4d88-a083-5ff257ed2c34", - "metadata": { - "collapsed": true, - "jupyter": { - "outputs_hidden": true - } - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Requirement already satisfied: prompt-declaration-language in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (0.0.7.dev6+g11f5271.d20241010)\n", - "Requirement already satisfied: pydantic~=2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language) (2.9.1)\n", - "Requirement already satisfied: ibm-generative-ai~=3.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language) (3.0.0)\n", - "Requirement already satisfied: requests~=2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language) (2.32.3)\n", - "Requirement already satisfied: python-dotenv~=1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language) (1.0.1)\n", - "Requirement already satisfied: jinja2~=3.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language) (3.1.4)\n", - "Requirement already satisfied: PyYAML~=6.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language) (6.0.2)\n", - "Requirement already satisfied: jsonschema~=4.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language) (4.23.0)\n", - "Requirement already satisfied: litellm~=1.47 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language) (1.49.0)\n", - "Requirement already satisfied: termcolor~=2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language) (2.4.0)\n", - "Requirement already satisfied: ipython~=8.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language) (8.27.0)\n", - "Requirement already satisfied: aiolimiter<2.0.0,>=1.1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ibm-generative-ai~=3.0->prompt-declaration-language) (1.1.0)\n", - "Requirement already satisfied: deprecated<2.0.0,>=1.2.14 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ibm-generative-ai~=3.0->prompt-declaration-language) (1.2.14)\n", - "Requirement already satisfied: httpx<0.28.0,>=0.27.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ibm-generative-ai~=3.0->prompt-declaration-language) (0.27.2)\n", - "Requirement already satisfied: httpx-sse<0.5.0,>=0.4.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ibm-generative-ai~=3.0->prompt-declaration-language) (0.4.0)\n", - "Requirement already satisfied: decorator in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language) (5.1.1)\n", - "Requirement already satisfied: jedi>=0.16 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language) (0.19.1)\n", - "Requirement already satisfied: matplotlib-inline in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language) (0.1.7)\n", - "Requirement already satisfied: prompt-toolkit<3.1.0,>=3.0.41 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language) (3.0.47)\n", - "Requirement already satisfied: pygments>=2.4.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language) (2.18.0)\n", - "Requirement already satisfied: stack-data in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language) (0.6.3)\n", - "Requirement already satisfied: traitlets>=5.13.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language) (5.14.3)\n", - "Requirement already satisfied: pexpect>4.3 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language) (4.9.0)\n", - "Requirement already satisfied: MarkupSafe>=2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jinja2~=3.0->prompt-declaration-language) (2.1.5)\n", - "Requirement already satisfied: attrs>=22.2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jsonschema~=4.0->prompt-declaration-language) (24.2.0)\n", - "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jsonschema~=4.0->prompt-declaration-language) (2023.12.1)\n", - "Requirement already satisfied: referencing>=0.28.4 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jsonschema~=4.0->prompt-declaration-language) (0.35.1)\n", - "Requirement already satisfied: rpds-py>=0.7.1 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jsonschema~=4.0->prompt-declaration-language) (0.20.0)\n", - "Requirement already satisfied: aiohttp in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from litellm~=1.47->prompt-declaration-language) (3.10.5)\n", - "Requirement already satisfied: click in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from litellm~=1.47->prompt-declaration-language) (8.1.7)\n", - "Requirement already satisfied: importlib-metadata>=6.8.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from litellm~=1.47->prompt-declaration-language) (8.4.0)\n", - "Requirement already satisfied: openai>=1.51.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from litellm~=1.47->prompt-declaration-language) (1.51.0)\n", - "Requirement already satisfied: tiktoken>=0.7.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from litellm~=1.47->prompt-declaration-language) (0.7.0)\n", - "Requirement already satisfied: tokenizers in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from litellm~=1.47->prompt-declaration-language) (0.19.1)\n", - "Requirement already satisfied: annotated-types>=0.6.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pydantic~=2.0->prompt-declaration-language) (0.7.0)\n", - "Requirement already satisfied: pydantic-core==2.23.3 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pydantic~=2.0->prompt-declaration-language) (2.23.3)\n", - "Requirement already satisfied: typing-extensions>=4.6.1 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pydantic~=2.0->prompt-declaration-language) (4.12.2)\n", - "Requirement already satisfied: charset-normalizer<4,>=2 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from requests~=2.0->prompt-declaration-language) (3.3.2)\n", - "Requirement already satisfied: idna<4,>=2.5 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from requests~=2.0->prompt-declaration-language) (3.10)\n", - "Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from requests~=2.0->prompt-declaration-language) (1.26.20)\n", - "Requirement already satisfied: certifi>=2017.4.17 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from requests~=2.0->prompt-declaration-language) (2024.8.30)\n", - "Requirement already satisfied: wrapt<2,>=1.10 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from deprecated<2.0.0,>=1.2.14->ibm-generative-ai~=3.0->prompt-declaration-language) (1.16.0)\n", - "Requirement already satisfied: anyio in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from httpx<0.28.0,>=0.27.0->ibm-generative-ai~=3.0->prompt-declaration-language) (4.4.0)\n", - "Requirement already satisfied: httpcore==1.* in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from httpx<0.28.0,>=0.27.0->ibm-generative-ai~=3.0->prompt-declaration-language) (1.0.5)\n", - "Requirement already satisfied: sniffio in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from httpx<0.28.0,>=0.27.0->ibm-generative-ai~=3.0->prompt-declaration-language) (1.3.1)\n", - "Requirement already satisfied: h11<0.15,>=0.13 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from httpcore==1.*->httpx<0.28.0,>=0.27.0->ibm-generative-ai~=3.0->prompt-declaration-language) (0.14.0)\n", - "Requirement already satisfied: zipp>=0.5 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from importlib-metadata>=6.8.0->litellm~=1.47->prompt-declaration-language) (3.20.1)\n", - "Requirement already satisfied: parso<0.9.0,>=0.8.3 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jedi>=0.16->ipython~=8.0->prompt-declaration-language) (0.8.4)\n", - "Requirement already satisfied: distro<2,>=1.7.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from openai>=1.51.0->litellm~=1.47->prompt-declaration-language) (1.9.0)\n", - "Requirement already satisfied: jiter<1,>=0.4.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from openai>=1.51.0->litellm~=1.47->prompt-declaration-language) (0.5.0)\n", - "Requirement already satisfied: tqdm>4 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from openai>=1.51.0->litellm~=1.47->prompt-declaration-language) (4.66.5)\n", - "Requirement already satisfied: ptyprocess>=0.5 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pexpect>4.3->ipython~=8.0->prompt-declaration-language) (0.7.0)\n", - "Requirement already satisfied: wcwidth in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-toolkit<3.1.0,>=3.0.41->ipython~=8.0->prompt-declaration-language) (0.2.13)\n", - "Requirement already satisfied: regex>=2022.1.18 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from tiktoken>=0.7.0->litellm~=1.47->prompt-declaration-language) (2024.7.24)\n", - "Requirement already satisfied: aiohappyeyeballs>=2.3.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from aiohttp->litellm~=1.47->prompt-declaration-language) (2.4.0)\n", - "Requirement already satisfied: aiosignal>=1.1.2 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from aiohttp->litellm~=1.47->prompt-declaration-language) (1.3.1)\n", - "Requirement already satisfied: frozenlist>=1.1.1 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from aiohttp->litellm~=1.47->prompt-declaration-language) (1.4.1)\n", - "Requirement already satisfied: multidict<7.0,>=4.5 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from aiohttp->litellm~=1.47->prompt-declaration-language) (6.1.0)\n", - "Requirement already satisfied: yarl<2.0,>=1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from aiohttp->litellm~=1.47->prompt-declaration-language) (1.11.1)\n", - "Requirement already satisfied: executing>=1.2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from stack-data->ipython~=8.0->prompt-declaration-language) (2.1.0)\n", - "Requirement already satisfied: asttokens>=2.1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from stack-data->ipython~=8.0->prompt-declaration-language) (2.4.1)\n", - "Requirement already satisfied: pure-eval in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from stack-data->ipython~=8.0->prompt-declaration-language) (0.2.3)\n", - "Requirement already satisfied: huggingface-hub<1.0,>=0.16.4 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from tokenizers->litellm~=1.47->prompt-declaration-language) (0.24.7)\n", - "Requirement already satisfied: six>=1.12.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from asttokens>=2.1.0->stack-data->ipython~=8.0->prompt-declaration-language) (1.16.0)\n", - "Requirement already satisfied: filelock in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from huggingface-hub<1.0,>=0.16.4->tokenizers->litellm~=1.47->prompt-declaration-language) (3.16.0)\n", - "Requirement already satisfied: fsspec>=2023.5.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from huggingface-hub<1.0,>=0.16.4->tokenizers->litellm~=1.47->prompt-declaration-language) (2024.6.1)\n", - "Requirement already satisfied: packaging>=20.9 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from huggingface-hub<1.0,>=0.16.4->tokenizers->litellm~=1.47->prompt-declaration-language) (24.1)\n", - "Requirement already satisfied: prompt-declaration-language[examples] in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (0.0.7.dev6+g11f5271.d20241010)\n", - "Requirement already satisfied: pydantic~=2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (2.9.1)\n", - "Requirement already satisfied: ibm-generative-ai~=3.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (3.0.0)\n", - "Requirement already satisfied: requests~=2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (2.32.3)\n", - "Requirement already satisfied: python-dotenv~=1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (1.0.1)\n", - "Requirement already satisfied: jinja2~=3.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (3.1.4)\n", - "Requirement already satisfied: PyYAML~=6.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (6.0.2)\n", - "Requirement already satisfied: jsonschema~=4.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (4.23.0)\n", - "Requirement already satisfied: litellm~=1.47 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (1.49.0)\n", - "Requirement already satisfied: termcolor~=2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (2.4.0)\n", - "Requirement already satisfied: ipython~=8.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (8.27.0)\n", - "Requirement already satisfied: wikipedia~=1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (1.4.0)\n", - "Requirement already satisfied: textdistance~=4.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (4.6.3)\n", - "Requirement already satisfied: faiss-cpu~=1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (1.8.0.post1)\n", - "Requirement already satisfied: datasets<4,>2 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (3.0.1)\n", - "Requirement already satisfied: sympy~=1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (1.13.2)\n", - "Requirement already satisfied: filelock in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (3.16.0)\n", - "Requirement already satisfied: numpy>=1.17 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (1.26.4)\n", - "Requirement already satisfied: pyarrow>=15.0.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (17.0.0)\n", - "Requirement already satisfied: dill<0.3.9,>=0.3.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (0.3.8)\n", - "Requirement already satisfied: pandas in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (2.2.2)\n", - "Requirement already satisfied: tqdm>=4.66.3 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (4.66.5)\n", - "Requirement already satisfied: xxhash in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (3.5.0)\n", - "Requirement already satisfied: multiprocess in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (0.70.16)\n", - "Requirement already satisfied: fsspec<=2024.6.1,>=2023.1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from fsspec[http]<=2024.6.1,>=2023.1.0->datasets<4,>2->prompt-declaration-language[examples]) (2024.6.1)\n", - "Requirement already satisfied: aiohttp in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (3.10.5)\n", - "Requirement already satisfied: huggingface-hub>=0.22.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (0.24.7)\n", - "Requirement already satisfied: packaging in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (24.1)\n", - "Requirement already satisfied: aiolimiter<2.0.0,>=1.1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ibm-generative-ai~=3.0->prompt-declaration-language[examples]) (1.1.0)\n", - "Requirement already satisfied: deprecated<2.0.0,>=1.2.14 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ibm-generative-ai~=3.0->prompt-declaration-language[examples]) (1.2.14)\n", - "Requirement already satisfied: httpx<0.28.0,>=0.27.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ibm-generative-ai~=3.0->prompt-declaration-language[examples]) (0.27.2)\n", - "Requirement already satisfied: httpx-sse<0.5.0,>=0.4.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ibm-generative-ai~=3.0->prompt-declaration-language[examples]) (0.4.0)\n", - "Requirement already satisfied: decorator in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language[examples]) (5.1.1)\n", - "Requirement already satisfied: jedi>=0.16 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language[examples]) (0.19.1)\n", - "Requirement already satisfied: matplotlib-inline in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language[examples]) (0.1.7)\n", - "Requirement already satisfied: prompt-toolkit<3.1.0,>=3.0.41 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language[examples]) (3.0.47)\n", - "Requirement already satisfied: pygments>=2.4.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language[examples]) (2.18.0)\n", - "Requirement already satisfied: stack-data in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language[examples]) (0.6.3)\n", - "Requirement already satisfied: traitlets>=5.13.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language[examples]) (5.14.3)\n", - "Requirement already satisfied: pexpect>4.3 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language[examples]) (4.9.0)\n", - "Requirement already satisfied: MarkupSafe>=2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jinja2~=3.0->prompt-declaration-language[examples]) (2.1.5)\n", - "Requirement already satisfied: attrs>=22.2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jsonschema~=4.0->prompt-declaration-language[examples]) (24.2.0)\n", - "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jsonschema~=4.0->prompt-declaration-language[examples]) (2023.12.1)\n", - "Requirement already satisfied: referencing>=0.28.4 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jsonschema~=4.0->prompt-declaration-language[examples]) (0.35.1)\n", - "Requirement already satisfied: rpds-py>=0.7.1 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jsonschema~=4.0->prompt-declaration-language[examples]) (0.20.0)\n", - "Requirement already satisfied: click in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from litellm~=1.47->prompt-declaration-language[examples]) (8.1.7)\n", - "Requirement already satisfied: importlib-metadata>=6.8.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from litellm~=1.47->prompt-declaration-language[examples]) (8.4.0)\n", - "Requirement already satisfied: openai>=1.51.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from litellm~=1.47->prompt-declaration-language[examples]) (1.51.0)\n", - "Requirement already satisfied: tiktoken>=0.7.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from litellm~=1.47->prompt-declaration-language[examples]) (0.7.0)\n", - "Requirement already satisfied: tokenizers in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from litellm~=1.47->prompt-declaration-language[examples]) (0.19.1)\n", - "Requirement already satisfied: annotated-types>=0.6.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pydantic~=2.0->prompt-declaration-language[examples]) (0.7.0)\n", - "Requirement already satisfied: pydantic-core==2.23.3 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pydantic~=2.0->prompt-declaration-language[examples]) (2.23.3)\n", - "Requirement already satisfied: typing-extensions>=4.6.1 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pydantic~=2.0->prompt-declaration-language[examples]) (4.12.2)\n", - "Requirement already satisfied: charset-normalizer<4,>=2 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from requests~=2.0->prompt-declaration-language[examples]) (3.3.2)\n", - "Requirement already satisfied: idna<4,>=2.5 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from requests~=2.0->prompt-declaration-language[examples]) (3.10)\n", - "Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from requests~=2.0->prompt-declaration-language[examples]) (1.26.20)\n", - "Requirement already satisfied: certifi>=2017.4.17 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from requests~=2.0->prompt-declaration-language[examples]) (2024.8.30)\n", - "Requirement already satisfied: mpmath<1.4,>=1.1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from sympy~=1.0->prompt-declaration-language[examples]) (1.3.0)\n", - "Requirement already satisfied: beautifulsoup4 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from wikipedia~=1.0->prompt-declaration-language[examples]) (4.12.3)\n", - "Requirement already satisfied: wrapt<2,>=1.10 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from deprecated<2.0.0,>=1.2.14->ibm-generative-ai~=3.0->prompt-declaration-language[examples]) (1.16.0)\n", - "Requirement already satisfied: aiohappyeyeballs>=2.3.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from aiohttp->datasets<4,>2->prompt-declaration-language[examples]) (2.4.0)\n", - "Requirement already satisfied: aiosignal>=1.1.2 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from aiohttp->datasets<4,>2->prompt-declaration-language[examples]) (1.3.1)\n", - "Requirement already satisfied: frozenlist>=1.1.1 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from aiohttp->datasets<4,>2->prompt-declaration-language[examples]) (1.4.1)\n", - "Requirement already satisfied: multidict<7.0,>=4.5 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from aiohttp->datasets<4,>2->prompt-declaration-language[examples]) (6.1.0)\n", - "Requirement already satisfied: yarl<2.0,>=1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from aiohttp->datasets<4,>2->prompt-declaration-language[examples]) (1.11.1)\n", - "Requirement already satisfied: anyio in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from httpx<0.28.0,>=0.27.0->ibm-generative-ai~=3.0->prompt-declaration-language[examples]) (4.4.0)\n", - "Requirement already satisfied: httpcore==1.* in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from httpx<0.28.0,>=0.27.0->ibm-generative-ai~=3.0->prompt-declaration-language[examples]) (1.0.5)\n", - "Requirement already satisfied: sniffio in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from httpx<0.28.0,>=0.27.0->ibm-generative-ai~=3.0->prompt-declaration-language[examples]) (1.3.1)\n", - "Requirement already satisfied: h11<0.15,>=0.13 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from httpcore==1.*->httpx<0.28.0,>=0.27.0->ibm-generative-ai~=3.0->prompt-declaration-language[examples]) (0.14.0)\n", - "Requirement already satisfied: zipp>=0.5 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from importlib-metadata>=6.8.0->litellm~=1.47->prompt-declaration-language[examples]) (3.20.1)\n", - "Requirement already satisfied: parso<0.9.0,>=0.8.3 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jedi>=0.16->ipython~=8.0->prompt-declaration-language[examples]) (0.8.4)\n", - "Requirement already satisfied: distro<2,>=1.7.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from openai>=1.51.0->litellm~=1.47->prompt-declaration-language[examples]) (1.9.0)\n", - "Requirement already satisfied: jiter<1,>=0.4.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from openai>=1.51.0->litellm~=1.47->prompt-declaration-language[examples]) (0.5.0)\n", - "Requirement already satisfied: ptyprocess>=0.5 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pexpect>4.3->ipython~=8.0->prompt-declaration-language[examples]) (0.7.0)\n", - "Requirement already satisfied: wcwidth in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-toolkit<3.1.0,>=3.0.41->ipython~=8.0->prompt-declaration-language[examples]) (0.2.13)\n", - "Requirement already satisfied: regex>=2022.1.18 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from tiktoken>=0.7.0->litellm~=1.47->prompt-declaration-language[examples]) (2024.7.24)\n", - "Requirement already satisfied: soupsieve>1.2 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from beautifulsoup4->wikipedia~=1.0->prompt-declaration-language[examples]) (2.6)\n", - "Requirement already satisfied: python-dateutil>=2.8.2 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pandas->datasets<4,>2->prompt-declaration-language[examples]) (2.9.0.post0)\n", - "Requirement already satisfied: pytz>=2020.1 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pandas->datasets<4,>2->prompt-declaration-language[examples]) (2024.2)\n", - "Requirement already satisfied: tzdata>=2022.7 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pandas->datasets<4,>2->prompt-declaration-language[examples]) (2024.1)\n", - "Requirement already satisfied: executing>=1.2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from stack-data->ipython~=8.0->prompt-declaration-language[examples]) (2.1.0)\n", - "Requirement already satisfied: asttokens>=2.1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from stack-data->ipython~=8.0->prompt-declaration-language[examples]) (2.4.1)\n", - "Requirement already satisfied: pure-eval in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from stack-data->ipython~=8.0->prompt-declaration-language[examples]) (0.2.3)\n", - "Requirement already satisfied: six>=1.12.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from asttokens>=2.1.0->stack-data->ipython~=8.0->prompt-declaration-language[examples]) (1.16.0)\n" - ] - } - ], + "metadata": {}, + "outputs": [], "source": [ "! pip install prompt-declaration-language\n", "! pip install 'prompt-declaration-language[examples]'" @@ -492,7 +329,7 @@ "source": [ "## Conclusion\n", "\n", - "Since prompts are at the forefront, PDL makes users more productive in their trial-and-error with LLMs. PDL is a representation for prompting that can be used not only for low-level prompting, but as" + "Since prompts are at the forefront, PDL makes users more productive in their trial-and-error with LLMs. Try it!" ] } ], From d0503385874645f5017d799ccd71bc4a90027988 Mon Sep 17 00:00:00 2001 From: Mandana Vaziri Date: Thu, 10 Oct 2024 13:18:38 -0400 Subject: [PATCH 13/24] demo update Signed-off-by: Mandana Vaziri --- examples/notebooks/demo.ipynb | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/examples/notebooks/demo.ipynb b/examples/notebooks/demo.ipynb index aa29445e7..2dc425aca 100644 --- a/examples/notebooks/demo.ipynb +++ b/examples/notebooks/demo.ipynb @@ -9,7 +9,7 @@ "\n", "Prompt engineering is difficult: minor variations in prompts have large impacts on the output of LLMs and prompts are model-dependent. In recent years prompt programming languages have emerged to bring discipline to prompt engineering. Many of them are embedded in an imperative language such as Python or TypeScript, making it difficult for users to directly interact with prompts and multi-turn LLM interactions.\n", "\n", - "The Prompt Declaration Language (PDL) is a yaml-based declarative approach to prompt programming, where prompts are at the forefront. PDL facilitates model chaining and tool use, abstracting away the plumbing necessary for such compositions, enables type checking of the input and output of models, and is based on LiteLLM to support a variety of model providers. PDL has been used with RAG, CoT, ReAct, and an agent for solving SWE-bench. PDL is [open-source](https://github.com/IBM/prompt-declaration-language) and works well with watsonx.ai and Granite models.\n", + "The Prompt Declaration Language (PDL) is a YAML-based declarative approach to prompt programming, where prompts are at the forefront. PDL facilitates model chaining and tool use, abstracting away the plumbing necessary for such compositions, enables type checking of the input and output of models, and is based on LiteLLM to support a variety of model providers. PDL has been used with RAG, CoT, ReAct, and an agent for solving SWE-bench. PDL is [open-source](https://github.com/IBM/prompt-declaration-language) and works well with watsonx.ai and Granite models.\n", "\n", "All examples in this notebook use the new ibm/granite-8b-instruct-preview-4k model. You can use PDL stand-alone or from a Python SDK or, as shown here, in a notebook via a notebook extension. In the cell output, model-generated text is rendered in green font, and tool-generated text is rendered in purple font." ] @@ -42,7 +42,7 @@ "source": [ "## Model call\n", "\n", - "In PDL, prompts are the forefront and the user specifies step-by-step the shape of data they want to generate. In the following, the `text` construct indicates a text block containing a prompt and a model call. Implicitly PDL builds a background conversational context (list of role/content) which is used to make model calls. Each model call uses the context built so far as its input prompt." + "In PDL, the user specifies step-by-step the shape of data they want to generate. In the following, the `text` construct indicates a text block containing a prompt and a model call. Implicitly, PDL builds a background conversational context (list of role/content) which is used to make model calls. Each model call uses the context built so far as its input prompt." ] }, { @@ -158,7 +158,7 @@ "source": [ "## Data pipeline\n", "\n", - "The following program shows a common prompting pattern: read some data, formulate a prompt using that data, submit to a model, and evaluate. In this program, we formulate a prompt for code explanation. The program first defines two variables: `code`, which holds the data we read, and `truth` for the ground truth. It then prints out the source code, formulates a prompts with the data, and calls a model to get an explanation. Finally, a Python code block is used to use the Levenshtein text distance metric and evaluate the explanation against the ground truth. This pipeline can similarly be applied to an entire data set to produce a jsonl file." + "The following program shows a common prompting pattern: read some data, formulate a prompt using that data, submit to a model, and evaluate. In this program, we formulate a prompt for code explanation. The program first defines two variables: `code`, which holds the data we read, and `truth` for the ground truth. It then prints out the source code, formulates a prompts with the data, and calls a model to get an explanation. Finally, a Python code block uses the Levenshtein text distance metric and evaluate the explanation against the ground truth. This pipeline can similarly be applied to an entire data set to produce a jsonl file." ] }, { @@ -249,13 +249,13 @@ "source": [ "## Agentic Flow\n", "\n", - "The following PDL program shows an agentic flow with a ReAct prompt pattern. It first reads some demonstrations to be used as few-shots. The ReAct pattern is captured with PDL control structures (repeat-until, and if-then-else), and consists of cycling through thoughts, actions, and observations. The tools available are wikipedia search, and calculator (as a Python code). The agent decides when to search and when to calculate. The `spec` indicates a type for the output of the model when actions are produced, it is used to dynamically check outputs of models and fail when they don't conform to the expectation. " + "The following PDL program shows an agentic flow with a ReAct prompt pattern. It first reads some demonstrations to be used as few-shots. The ReAct pattern is captured with PDL control structures (repeat-until and if-then-else), and consists of cycling through thoughts, actions, and observations. The tools available are Wikipedia search, and calculator (as Python code). The agent decides when to search and when to calculate. The `spec` indicates a type for the output of the model when actions are produced, it is used to dynamically check outputs of models and fail when they don't conform to the expectation. " ] }, { "cell_type": "code", - "execution_count": 16, - "id": "b7ff8708-7a82-492d-a91b-2ff4a17c768e", + "execution_count": 17, + "id": "dfef7096-b7a6-4966-8356-a306e701974b", "metadata": { "scrolled": true }, @@ -329,8 +329,18 @@ "source": [ "## Conclusion\n", "\n", - "Since prompts are at the forefront, PDL makes users more productive in their trial-and-error with LLMs. Try it!" + "Since prompts are at the forefront, PDL makes users more productive in their trial-and-error with LLMs. Try it!\n", + "\n", + "https://github.com/IBM/prompt-declaration-language" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b7576532-aee3-4580-85fd-0b97bc503621", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { From c27d163895034e70559307973067c06cb374cf9d Mon Sep 17 00:00:00 2001 From: Mandana Vaziri Date: Sun, 13 Oct 2024 15:12:38 -0400 Subject: [PATCH 14/24] demo notebook Signed-off-by: Mandana Vaziri --- examples/notebooks/demo.ipynb | 71 ++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/examples/notebooks/demo.ipynb b/examples/notebooks/demo.ipynb index 2dc425aca..92aaab0a5 100644 --- a/examples/notebooks/demo.ipynb +++ b/examples/notebooks/demo.ipynb @@ -21,13 +21,12 @@ "metadata": {}, "outputs": [], "source": [ - "! pip install prompt-declaration-language\n", "! pip install 'prompt-declaration-language[examples]'" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "id": "e25a6874-54d9-4167-82ed-ab2f4fdc0a6f", "metadata": {}, "outputs": [], @@ -47,7 +46,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 32, "id": "f3c62df1-0347-4711-acd7-3892cfd5df30", "metadata": {}, "outputs": [ @@ -56,7 +55,7 @@ "output_type": "stream", "text": [ "What is the meaning of life?\n", - "\u001b[32mThe\u001b[0m\u001b[32m meaning\u001b[0m\u001b[32m of\u001b[0m\u001b[32m life\u001b[0m\u001b[32m is\u001b[0m\u001b[32m a\u001b[0m\u001b[32m ph\u001b[0m\u001b[32milo\u001b[0m\u001b[32msop\u001b[0m\u001b[32mh\u001b[0m\u001b[32mical\u001b[0m\u001b[32m and\u001b[0m\u001b[32m met\u001b[0m\u001b[32maph\u001b[0m\u001b[32mysical\u001b[0m\u001b[32m question\u001b[0m\u001b[32m related\u001b[0m\u001b[32m to\u001b[0m\u001b[32m the\u001b[0m\u001b[32m purpose\u001b[0m\u001b[32m or\u001b[0m\u001b[32m signific\u001b[0m\u001b[32mance\u001b[0m\u001b[32m of\u001b[0m\u001b[32m life\u001b[0m\u001b[32m or\u001b[0m\u001b[32m existence\u001b[0m\u001b[32m in\u001b[0m\u001b[32m general\u001b[0m\u001b[32m.\u001b[0m\u001b[32m This\u001b[0m\u001b[32m concept\u001b[0m\u001b[32m has\u001b[0m\u001b[32m been\u001b[0m\u001b[32m appro\u001b[0m\u001b[32mached\u001b[0m\u001b[32m by\u001b[0m\u001b[32m many\u001b[0m\u001b[32m pers\u001b[0m\u001b[32mpect\u001b[0m\u001b[32mives\u001b[0m\u001b[32m including\u001b[0m\u001b[32m ph\u001b[0m\u001b[32milo\u001b[0m\u001b[32msophy\u001b[0m\u001b[32m,\u001b[0m\u001b[32m rel\u001b[0m\u001b[32migion\u001b[0m\u001b[32m,\u001b[0m\u001b[32m and\u001b[0m\u001b[32m science\u001b[0m\u001b[32m.\u001b[0m\u001b[32m Some\u001b[0m\u001b[32m people\u001b[0m\u001b[32m find\u001b[0m\u001b[32m meaning\u001b[0m\u001b[32m through\u001b[0m\u001b[32m personal\u001b[0m\u001b[32m growth\u001b[0m\u001b[32m,\u001b[0m\u001b[32m relationships\u001b[0m\u001b[32m,\u001b[0m\u001b[32m love\u001b[0m\u001b[32m,\u001b[0m\u001b[32m and\u001b[0m\u001b[32m through\u001b[0m\u001b[32m helping\u001b[0m\u001b[32m others\u001b[0m\u001b[32m.\u001b[0m\u001b[32m O\u001b[0m\u001b[32mthers\u001b[0m\u001b[32m seek\u001b[0m\u001b[32m meaning\u001b[0m\u001b[32m through\u001b[0m\u001b[32m spirit\u001b[0m\u001b[32mual\u001b[0m\u001b[32mity\u001b[0m\u001b[32m or\u001b[0m\u001b[32m rel\u001b[0m\u001b[32mig\u001b[0m\u001b[32mious\u001b[0m\u001b[32m bel\u001b[0m\u001b[32mie\u001b[0m\u001b[32mfs\u001b[0m\u001b[32m.\u001b[0m\u001b[32m U\u001b[0m\u001b[32mlt\u001b[0m\u001b[32mimately\u001b[0m\u001b[32m,\u001b[0m\u001b[32m the\u001b[0m\u001b[32m meaning\u001b[0m\u001b[32m of\u001b[0m\u001b[32m life\u001b[0m\u001b[32m may\u001b[0m\u001b[32m be\u001b[0m\u001b[32m a\u001b[0m\u001b[32m personal\u001b[0m\u001b[32m and\u001b[0m\u001b[32m subject\u001b[0m\u001b[32mive\u001b[0m\u001b[32m experience\u001b[0m\u001b[32m.\u001b[0m" + "\u001b[32mThe\u001b[0m\u001b[32m meaning\u001b[0m\u001b[32m of\u001b[0m\u001b[32m life\u001b[0m\u001b[32m is\u001b[0m\u001b[32m a\u001b[0m\u001b[32m ph\u001b[0m\u001b[32milo\u001b[0m\u001b[32msop\u001b[0m\u001b[32mh\u001b[0m\u001b[32mical\u001b[0m\u001b[32m and\u001b[0m\u001b[32m met\u001b[0m\u001b[32maph\u001b[0m\u001b[32mysical\u001b[0m\u001b[32m question\u001b[0m\u001b[32m related\u001b[0m\u001b[32m to\u001b[0m\u001b[32m the\u001b[0m\u001b[32m purpose\u001b[0m\u001b[32m or\u001b[0m\u001b[32m signific\u001b[0m\u001b[32mance\u001b[0m\u001b[32m of\u001b[0m\u001b[32m life\u001b[0m\u001b[32m or\u001b[0m\u001b[32m existence\u001b[0m\u001b[32m in\u001b[0m\u001b[32m general\u001b[0m\u001b[32m.\u001b[0m\u001b[32m This\u001b[0m\u001b[32m question\u001b[0m\u001b[32m has\u001b[0m\u001b[32m been\u001b[0m\u001b[32m asked\u001b[0m\u001b[32m for\u001b[0m\u001b[32m cent\u001b[0m\u001b[32mur\u001b[0m\u001b[32mies\u001b[0m\u001b[32m and\u001b[0m\u001b[32m does\u001b[0m\u001b[32m not\u001b[0m\u001b[32m have\u001b[0m\u001b[32m a\u001b[0m\u001b[32m def\u001b[0m\u001b[32minit\u001b[0m\u001b[32mive\u001b[0m\u001b[32m answer\u001b[0m\u001b[32m.\u001b[0m\u001b[32m Some\u001b[0m\u001b[32m people\u001b[0m\u001b[32m find\u001b[0m\u001b[32m meaning\u001b[0m\u001b[32m through\u001b[0m\u001b[32m personal\u001b[0m\u001b[32m growth\u001b[0m\u001b[32m,\u001b[0m\u001b[32m relationships\u001b[0m\u001b[32m,\u001b[0m\u001b[32m love\u001b[0m\u001b[32m,\u001b[0m\u001b[32m or\u001b[0m\u001b[32m through\u001b[0m\u001b[32m contributing\u001b[0m\u001b[32m to\u001b[0m\u001b[32m the\u001b[0m\u001b[32m better\u001b[0m\u001b[32mment\u001b[0m\u001b[32m of\u001b[0m\u001b[32m human\u001b[0m\u001b[32mity\u001b[0m\u001b[32m.\u001b[0m\u001b[32m U\u001b[0m\u001b[32mlt\u001b[0m\u001b[32mimately\u001b[0m\u001b[32m,\u001b[0m\u001b[32m the\u001b[0m\u001b[32m meaning\u001b[0m\u001b[32m of\u001b[0m\u001b[32m life\u001b[0m\u001b[32m may\u001b[0m\u001b[32m be\u001b[0m\u001b[32m a\u001b[0m\u001b[32m personal\u001b[0m\u001b[32m and\u001b[0m\u001b[32m subject\u001b[0m\u001b[32mive\u001b[0m\u001b[32m concept\u001b[0m\u001b[32m.\u001b[0m" ] } ], @@ -79,7 +78,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 33, "id": "7f6c323b-ad1a-4434-8732-bc19c5c47883", "metadata": {}, "outputs": [ @@ -90,23 +89,25 @@ "\n", "Say it like a poem\n", "\u001b[32mLife\u001b[0m\u001b[32m's\u001b[0m\u001b[32m meaning\u001b[0m\u001b[32m,\u001b[0m\u001b[32m a\u001b[0m\u001b[32m question\u001b[0m\u001b[32m vast\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mIn\u001b[0m\u001b[32m ph\u001b[0m\u001b[32milo\u001b[0m\u001b[32msophy\u001b[0m\u001b[32m,\u001b[0m\u001b[32m rel\u001b[0m\u001b[32migion\u001b[0m\u001b[32m,\u001b[0m\u001b[32m and\u001b[0m\u001b[32m science\u001b[0m\u001b[32m cast\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mSome\u001b[0m\u001b[32m find\u001b[0m\u001b[32m purpose\u001b[0m\u001b[32m in\u001b[0m\u001b[32m personal\u001b[0m\u001b[32m growth\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mIn\u001b[0m\u001b[32m love\u001b[0m\u001b[32m and\u001b[0m\u001b[32m relationships\u001b[0m\u001b[32m,\u001b[0m\u001b[32m they\u001b[0m\u001b[32m find\u001b[0m\u001b[32m their\u001b[0m\u001b[32m tro\u001b[0m\u001b[32mth\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mOthers\u001b[0m\u001b[32m seek\u001b[0m\u001b[32m meaning\u001b[0m\u001b[32m through\u001b[0m\u001b[32m spirit\u001b[0m\u001b[32mual\u001b[0m\u001b[32mity\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mIn\u001b[0m\u001b[32m fa\u001b[0m\u001b[32mith\u001b[0m\u001b[32m and\u001b[0m\u001b[32m bel\u001b[0m\u001b[32mief\u001b[0m\u001b[32m,\u001b[0m\u001b[32m they\u001b[0m\u001b[32m find\u001b[0m\u001b[32m their\u001b[0m\u001b[32m reality\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mUlt\u001b[0m\u001b[32mimately\u001b[0m\u001b[32m,\u001b[0m\u001b[32m meaning\u001b[0m\u001b[32m is\u001b[0m\u001b[32m a\u001b[0m\u001b[32m personal\u001b[0m\u001b[32m quest\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mIn\u001b[0m\u001b[32m life\u001b[0m\u001b[32m's\u001b[0m\u001b[32m journey\u001b[0m\u001b[32m,\u001b[0m\u001b[32m we\u001b[0m\u001b[32m are\u001b[0m\u001b[32m put\u001b[0m\u001b[32m to\u001b[0m\u001b[32m the\u001b[0m\u001b[32m test\u001b[0m\u001b[32m.\u001b[0m\n", + "\u001b[0m\u001b[32mIn\u001b[0m\u001b[32m ph\u001b[0m\u001b[32milo\u001b[0m\u001b[32msophy\u001b[0m\u001b[32m,\u001b[0m\u001b[32m it\u001b[0m\u001b[32m's\u001b[0m\u001b[32m often\u001b[0m\u001b[32m cast\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mPersonal\u001b[0m\u001b[32m growth\u001b[0m\u001b[32m,\u001b[0m\u001b[32m love\u001b[0m\u001b[32m,\u001b[0m\u001b[32m or\u001b[0m\u001b[32m de\u001b[0m\u001b[32meds\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mSome\u001b[0m\u001b[32m find\u001b[0m\u001b[32m purpose\u001b[0m\u001b[32m in\u001b[0m\u001b[32m these\u001b[0m\u001b[32m cre\u001b[0m\u001b[32meds\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mA\u001b[0m\u001b[32m subject\u001b[0m\u001b[32mive\u001b[0m\u001b[32m concept\u001b[0m\u001b[32m,\u001b[0m\u001b[32m it\u001b[0m\u001b[32m may\u001b[0m\u001b[32m be\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mY\u001b[0m\u001b[32met\u001b[0m\u001b[32m,\u001b[0m\u001b[32m each\u001b[0m\u001b[32m soul\u001b[0m\u001b[32m see\u001b[0m\u001b[32mks\u001b[0m\u001b[32m its\u001b[0m\u001b[32m dec\u001b[0m\u001b[32mree\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mIn\u001b[0m\u001b[32m the\u001b[0m\u001b[32m end\u001b[0m\u001b[32m,\u001b[0m\u001b[32m it\u001b[0m\u001b[32m's\u001b[0m\u001b[32m up\u001b[0m\u001b[32m to\u001b[0m\u001b[32m you\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mTo\u001b[0m\u001b[32m find\u001b[0m\u001b[32m your\u001b[0m\u001b[32m own\u001b[0m\u001b[32m meaning\u001b[0m\u001b[32m an\u001b[0m\u001b[32mew\u001b[0m\u001b[32m.\u001b[0m\n", "\n", "Translate it to French\n", "\u001b[32mLa\u001b[0m\u001b[32m sign\u001b[0m\u001b[32mification\u001b[0m\u001b[32m de\u001b[0m\u001b[32m la\u001b[0m\u001b[32m v\u001b[0m\u001b[32mie\u001b[0m\u001b[32m,\u001b[0m\u001b[32m une\u001b[0m\u001b[32m question\u001b[0m\u001b[32m imm\u001b[0m\u001b[32mense\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mD\u001b[0m\u001b[32mans\u001b[0m\u001b[32m la\u001b[0m\u001b[32m ph\u001b[0m\u001b[32milo\u001b[0m\u001b[32msop\u001b[0m\u001b[32mh\u001b[0m\u001b[32mie\u001b[0m\u001b[32m,\u001b[0m\u001b[32m la\u001b[0m\u001b[32m rel\u001b[0m\u001b[32migion\u001b[0m\u001b[32m et\u001b[0m\u001b[32m la\u001b[0m\u001b[32m science\u001b[0m\u001b[32m,\u001b[0m\u001b[32m el\u001b[0m\u001b[32mle\u001b[0m\u001b[32m est\u001b[0m\u001b[32m pos\u001b[0m\u001b[32mée\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mQue\u001b[0m\u001b[32ml\u001b[0m\u001b[32mques\u001b[0m\u001b[32m-\u001b[0m\u001b[32muns\u001b[0m\u001b[32m tro\u001b[0m\u001b[32mu\u001b[0m\u001b[32mvent\u001b[0m\u001b[32m un\u001b[0m\u001b[32m but\u001b[0m\u001b[32m dans\u001b[0m\u001b[32m le\u001b[0m\u001b[32mur\u001b[0m\u001b[32m cro\u001b[0m\u001b[32miss\u001b[0m\u001b[32mance\u001b[0m\u001b[32m person\u001b[0m\u001b[32mnel\u001b[0m\u001b[32mle\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mD\u001b[0m\u001b[32mans\u001b[0m\u001b[32m l\u001b[0m\u001b[32m'\u001b[0m\u001b[32mam\u001b[0m\u001b[32mour\u001b[0m\u001b[32m et\u001b[0m\u001b[32m les\u001b[0m\u001b[32m relations\u001b[0m\u001b[32m,\u001b[0m\u001b[32m il\u001b[0m\u001b[32ms\u001b[0m\u001b[32m tro\u001b[0m\u001b[32mu\u001b[0m\u001b[32mvent\u001b[0m\u001b[32m le\u001b[0m\u001b[32mur\u001b[0m\u001b[32m foi\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mD\u001b[0m\u001b[32m'\u001b[0m\u001b[32maut\u001b[0m\u001b[32mres\u001b[0m\u001b[32m ch\u001b[0m\u001b[32mer\u001b[0m\u001b[32mch\u001b[0m\u001b[32ment\u001b[0m\u001b[32m la\u001b[0m\u001b[32m sign\u001b[0m\u001b[32mification\u001b[0m\u001b[32m à\u001b[0m\u001b[32m tra\u001b[0m\u001b[32mvers\u001b[0m\u001b[32m la\u001b[0m\u001b[32m spirit\u001b[0m\u001b[32mual\u001b[0m\u001b[32mité\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mD\u001b[0m\u001b[32mans\u001b[0m\u001b[32m la\u001b[0m\u001b[32m foi\u001b[0m\u001b[32m et\u001b[0m\u001b[32m la\u001b[0m\u001b[32m c\u001b[0m\u001b[32mroy\u001b[0m\u001b[32mance\u001b[0m\u001b[32m,\u001b[0m\u001b[32m il\u001b[0m\u001b[32ms\u001b[0m\u001b[32m tro\u001b[0m\u001b[32mu\u001b[0m\u001b[32mvent\u001b[0m\u001b[32m le\u001b[0m\u001b[32mur\u001b[0m\u001b[32m ré\u001b[0m\u001b[32mal\u001b[0m\u001b[32mité\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mEn\u001b[0m\u001b[32m fin\u001b[0m\u001b[32m de\u001b[0m\u001b[32m compte\u001b[0m\u001b[32m,\u001b[0m\u001b[32m le\u001b[0m\u001b[32m but\u001b[0m\u001b[32m est\u001b[0m\u001b[32m une\u001b[0m\u001b[32m qu\u001b[0m\u001b[32mête\u001b[0m\u001b[32m person\u001b[0m\u001b[32mnel\u001b[0m\u001b[32mle\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mD\u001b[0m\u001b[32mans\u001b[0m\u001b[32m le\u001b[0m\u001b[32m vo\u001b[0m\u001b[32my\u001b[0m\u001b[32mage\u001b[0m\u001b[32m de\u001b[0m\u001b[32m la\u001b[0m\u001b[32m v\u001b[0m\u001b[32mie\u001b[0m\u001b[32m,\u001b[0m\u001b[32m nous\u001b[0m\u001b[32m som\u001b[0m\u001b[32mmes\u001b[0m\u001b[32m mis\u001b[0m\u001b[32m à\u001b[0m\u001b[32m l\u001b[0m\u001b[32m'\u001b[0m\u001b[32mé\u001b[0m\u001b[32mpre\u001b[0m\u001b[32muve\u001b[0m\u001b[32m.\u001b[0m" + "\u001b[0m\u001b[32mD\u001b[0m\u001b[32mans\u001b[0m\u001b[32m la\u001b[0m\u001b[32m ph\u001b[0m\u001b[32milo\u001b[0m\u001b[32msop\u001b[0m\u001b[32mh\u001b[0m\u001b[32mie\u001b[0m\u001b[32m,\u001b[0m\u001b[32m el\u001b[0m\u001b[32mle\u001b[0m\u001b[32m est\u001b[0m\u001b[32m sou\u001b[0m\u001b[32mvent\u001b[0m\u001b[32m pos\u001b[0m\u001b[32mée\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mLe\u001b[0m\u001b[32m dé\u001b[0m\u001b[32mvelop\u001b[0m\u001b[32mpe\u001b[0m\u001b[32mment\u001b[0m\u001b[32m person\u001b[0m\u001b[32mnel\u001b[0m\u001b[32m,\u001b[0m\u001b[32m l\u001b[0m\u001b[32m'\u001b[0m\u001b[32mam\u001b[0m\u001b[32mour\u001b[0m\u001b[32m ou\u001b[0m\u001b[32m les\u001b[0m\u001b[32m act\u001b[0m\u001b[32mes\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mCert\u001b[0m\u001b[32mains\u001b[0m\u001b[32m tro\u001b[0m\u001b[32mu\u001b[0m\u001b[32mvent\u001b[0m\u001b[32m un\u001b[0m\u001b[32m sens\u001b[0m\u001b[32m dans\u001b[0m\u001b[32m ces\u001b[0m\u001b[32m cré\u001b[0m\u001b[32md\u001b[0m\u001b[32mules\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mUn\u001b[0m\u001b[32m concept\u001b[0m\u001b[32m subject\u001b[0m\u001b[32mif\u001b[0m\u001b[32m,\u001b[0m\u001b[32m il\u001b[0m\u001b[32m peut\u001b[0m\u001b[32m être\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mM\u001b[0m\u001b[32mais\u001b[0m\u001b[32m chaque\u001b[0m\u001b[32m â\u001b[0m\u001b[32mme\u001b[0m\u001b[32m ch\u001b[0m\u001b[32mer\u001b[0m\u001b[32mche\u001b[0m\u001b[32m sa\u001b[0m\u001b[32m pro\u001b[0m\u001b[32mpre\u001b[0m\u001b[32m dé\u001b[0m\u001b[32mcision\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mEn\u001b[0m\u001b[32m fin\u001b[0m\u001b[32m de\u001b[0m\u001b[32m compte\u001b[0m\u001b[32m,\u001b[0m\u001b[32m c\u001b[0m\u001b[32m'\u001b[0m\u001b[32mest\u001b[0m\u001b[32m à\u001b[0m\u001b[32m vous\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mDe\u001b[0m\u001b[32m tro\u001b[0m\u001b[32mu\u001b[0m\u001b[32mver\u001b[0m\u001b[32m votre\u001b[0m\u001b[32m pro\u001b[0m\u001b[32mpre\u001b[0m\u001b[32m sens\u001b[0m\u001b[32m de\u001b[0m\u001b[32m nou\u001b[0m\u001b[32mveau\u001b[0m\u001b[32m.\u001b[0m" ] } ], @@ -163,7 +164,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 34, "id": "b61b2e25-72a4-4f70-ae83-40d77bed3f4f", "metadata": {}, "outputs": [ @@ -183,21 +184,20 @@ " return offsetMap;\n", "}\n", "\n", - "\u001b[32m\n", - "\u001b[0m\u001b[32mThis\u001b[0m\u001b[32m Java\u001b[0m\u001b[32m method\u001b[0m\u001b[32m,\u001b[0m\u001b[32m `\u001b[0m\u001b[32mdeserialize\u001b[0m\u001b[32mOffset\u001b[0m\u001b[32mMap\u001b[0m\u001b[32m`,\u001b[0m\u001b[32m is\u001b[0m\u001b[32m designed\u001b[0m\u001b[32m to\u001b[0m\u001b[32m convert\u001b[0m\u001b[32m a\u001b[0m\u001b[32m JSON\u001b[0m\u001b[32m string\u001b[0m\u001b[32m into\u001b[0m\u001b[32m a\u001b[0m\u001b[32m `\u001b[0m\u001b[32mMap\u001b[0m\u001b[32m<\u001b[0m\u001b[32mString\u001b[0m\u001b[32m,\u001b[0m\u001b[32m String\u001b[0m\u001b[32m>`.\u001b[0m\u001b[32m Here\u001b[0m\u001b[32m's\u001b[0m\u001b[32m a\u001b[0m\u001b[32m break\u001b[0m\u001b[32mdown\u001b[0m\u001b[32m of\u001b[0m\u001b[32m the\u001b[0m\u001b[32m code\u001b[0m\u001b[32m:\u001b[0m\u001b[32m\n", + "\u001b[32mThis\u001b[0m\u001b[32m Java\u001b[0m\u001b[32m method\u001b[0m\u001b[32m,\u001b[0m\u001b[32m `\u001b[0m\u001b[32mdeserialize\u001b[0m\u001b[32mOffset\u001b[0m\u001b[32mMap\u001b[0m\u001b[32m`,\u001b[0m\u001b[32m is\u001b[0m\u001b[32m designed\u001b[0m\u001b[32m to\u001b[0m\u001b[32m convert\u001b[0m\u001b[32m a\u001b[0m\u001b[32m JSON\u001b[0m\u001b[32m string\u001b[0m\u001b[32m into\u001b[0m\u001b[32m a\u001b[0m\u001b[32m `\u001b[0m\u001b[32mMap\u001b[0m\u001b[32m<\u001b[0m\u001b[32mString\u001b[0m\u001b[32m,\u001b[0m\u001b[32m String\u001b[0m\u001b[32m>`.\u001b[0m\u001b[32m Here\u001b[0m\u001b[32m's\u001b[0m\u001b[32m a\u001b[0m\u001b[32m break\u001b[0m\u001b[32mdown\u001b[0m\u001b[32m of\u001b[0m\u001b[32m the\u001b[0m\u001b[32m code\u001b[0m\u001b[32m:\u001b[0m\u001b[32m\n", "\u001b[0m\u001b[32m\n", "\u001b[0m\u001b[32m1\u001b[0m\u001b[32m.\u001b[0m\u001b[32m The\u001b[0m\u001b[32m method\u001b[0m\u001b[32m takes\u001b[0m\u001b[32m a\u001b[0m\u001b[32m single\u001b[0m\u001b[32m parameter\u001b[0m\u001b[32m,\u001b[0m\u001b[32m `\u001b[0m\u001b[32mlast\u001b[0m\u001b[32mSource\u001b[0m\u001b[32mOffset\u001b[0m\u001b[32m`,\u001b[0m\u001b[32m which\u001b[0m\u001b[32m is\u001b[0m\u001b[32m expected\u001b[0m\u001b[32m to\u001b[0m\u001b[32m be\u001b[0m\u001b[32m a\u001b[0m\u001b[32m JSON\u001b[0m\u001b[32m string\u001b[0m\u001b[32m representing\u001b[0m\u001b[32m a\u001b[0m\u001b[32m map\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", "\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32m2\u001b[0m\u001b[32m.\u001b[0m\u001b[32m It\u001b[0m\u001b[32m first\u001b[0m\u001b[32m checks\u001b[0m\u001b[32m if\u001b[0m\u001b[32m `\u001b[0m\u001b[32mlast\u001b[0m\u001b[32mSource\u001b[0m\u001b[32mOffset\u001b[0m\u001b[32m`\u001b[0m\u001b[32m is\u001b[0m\u001b[32m either\u001b[0m\u001b[32m null\u001b[0m\u001b[32m or\u001b[0m\u001b[32m an\u001b[0m\u001b[32m empty\u001b[0m\u001b[32m string\u001b[0m\u001b[32m.\u001b[0m\u001b[32m If\u001b[0m\u001b[32m true\u001b[0m\u001b[32m,\u001b[0m\u001b[32m it\u001b[0m\u001b[32m initializes\u001b[0m\u001b[32m a\u001b[0m\u001b[32m new\u001b[0m\u001b[32m `\u001b[0m\u001b[32mHashMap\u001b[0m\u001b[32m`\u001b[0m\u001b[32m and\u001b[0m\u001b[32m assigns\u001b[0m\u001b[32m it\u001b[0m\u001b[32m to\u001b[0m\u001b[32m `\u001b[0m\u001b[32moffset\u001b[0m\u001b[32mMap\u001b[0m\u001b[32m`.\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32m2\u001b[0m\u001b[32m.\u001b[0m\u001b[32m It\u001b[0m\u001b[32m first\u001b[0m\u001b[32m checks\u001b[0m\u001b[32m if\u001b[0m\u001b[32m `\u001b[0m\u001b[32mlast\u001b[0m\u001b[32mSource\u001b[0m\u001b[32mOffset\u001b[0m\u001b[32m`\u001b[0m\u001b[32m is\u001b[0m\u001b[32m either\u001b[0m\u001b[32m `\u001b[0m\u001b[32mnull\u001b[0m\u001b[32m`\u001b[0m\u001b[32m or\u001b[0m\u001b[32m an\u001b[0m\u001b[32m empty\u001b[0m\u001b[32m string\u001b[0m\u001b[32m.\u001b[0m\u001b[32m If\u001b[0m\u001b[32m true\u001b[0m\u001b[32m,\u001b[0m\u001b[32m it\u001b[0m\u001b[32m initializes\u001b[0m\u001b[32m a\u001b[0m\u001b[32m new\u001b[0m\u001b[32m `\u001b[0m\u001b[32mHashMap\u001b[0m\u001b[32m`\u001b[0m\u001b[32m and\u001b[0m\u001b[32m assigns\u001b[0m\u001b[32m it\u001b[0m\u001b[32m to\u001b[0m\u001b[32m `\u001b[0m\u001b[32moffset\u001b[0m\u001b[32mMap\u001b[0m\u001b[32m`.\u001b[0m\u001b[32m\n", "\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32m3\u001b[0m\u001b[32m.\u001b[0m\u001b[32m If\u001b[0m\u001b[32m `\u001b[0m\u001b[32mlast\u001b[0m\u001b[32mSource\u001b[0m\u001b[32mOffset\u001b[0m\u001b[32m`\u001b[0m\u001b[32m is\u001b[0m\u001b[32m not\u001b[0m\u001b[32m null\u001b[0m\u001b[32m or\u001b[0m\u001b[32m empty\u001b[0m\u001b[32m,\u001b[0m\u001b[32m it\u001b[0m\u001b[32m uses\u001b[0m\u001b[32m Jack\u001b[0m\u001b[32mson\u001b[0m\u001b[32m's\u001b[0m\u001b[32m `\u001b[0m\u001b[32mJSON\u001b[0m\u001b[32m_\u001b[0m\u001b[32mMAP\u001b[0m\u001b[32mPER\u001b[0m\u001b[32m`\u001b[0m\u001b[32m to\u001b[0m\u001b[32m deserialize\u001b[0m\u001b[32m the\u001b[0m\u001b[32m JSON\u001b[0m\u001b[32m string\u001b[0m\u001b[32m into\u001b[0m\u001b[32m a\u001b[0m\u001b[32m `\u001b[0m\u001b[32mMap\u001b[0m\u001b[32m<\u001b[0m\u001b[32mString\u001b[0m\u001b[32m,\u001b[0m\u001b[32m String\u001b[0m\u001b[32m>`\u001b[0m\u001b[32m and\u001b[0m\u001b[32m assigns\u001b[0m\u001b[32m it\u001b[0m\u001b[32m to\u001b[0m\u001b[32m `\u001b[0m\u001b[32moffset\u001b[0m\u001b[32mMap\u001b[0m\u001b[32m`.\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32m3\u001b[0m\u001b[32m.\u001b[0m\u001b[32m If\u001b[0m\u001b[32m `\u001b[0m\u001b[32mlast\u001b[0m\u001b[32mSource\u001b[0m\u001b[32mOffset\u001b[0m\u001b[32m`\u001b[0m\u001b[32m is\u001b[0m\u001b[32m not\u001b[0m\u001b[32m `\u001b[0m\u001b[32mnull\u001b[0m\u001b[32m`\u001b[0m\u001b[32m or\u001b[0m\u001b[32m empty\u001b[0m\u001b[32m,\u001b[0m\u001b[32m it\u001b[0m\u001b[32m uses\u001b[0m\u001b[32m Jack\u001b[0m\u001b[32mson\u001b[0m\u001b[32m's\u001b[0m\u001b[32m `\u001b[0m\u001b[32mJSON\u001b[0m\u001b[32m_\u001b[0m\u001b[32mMAP\u001b[0m\u001b[32mPER\u001b[0m\u001b[32m`\u001b[0m\u001b[32m to\u001b[0m\u001b[32m deserialize\u001b[0m\u001b[32m the\u001b[0m\u001b[32m JSON\u001b[0m\u001b[32m string\u001b[0m\u001b[32m into\u001b[0m\u001b[32m a\u001b[0m\u001b[32m `\u001b[0m\u001b[32mMap\u001b[0m\u001b[32m<\u001b[0m\u001b[32mString\u001b[0m\u001b[32m,\u001b[0m\u001b[32m String\u001b[0m\u001b[32m>`\u001b[0m\u001b[32m and\u001b[0m\u001b[32m assigns\u001b[0m\u001b[32m it\u001b[0m\u001b[32m to\u001b[0m\u001b[32m `\u001b[0m\u001b[32moffset\u001b[0m\u001b[32mMap\u001b[0m\u001b[32m`.\u001b[0m\u001b[32m\n", "\u001b[0m\u001b[32m\n", "\u001b[0m\u001b[32m4\u001b[0m\u001b[32m.\u001b[0m\u001b[32m Finally\u001b[0m\u001b[32m,\u001b[0m\u001b[32m it\u001b[0m\u001b[32m returns\u001b[0m\u001b[32m the\u001b[0m\u001b[32m `\u001b[0m\u001b[32moffset\u001b[0m\u001b[32mMap\u001b[0m\u001b[32m`.\u001b[0m\u001b[32m\n", "\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mThe\u001b[0m\u001b[32m `@\u001b[0m\u001b[32mSuppressWarnings\u001b[0m\u001b[32m(\"\u001b[0m\u001b[32munchecked\u001b[0m\u001b[32m\")\u001b[0m\u001b[32m`\u001b[0m\u001b[32m annotation\u001b[0m\u001b[32m is\u001b[0m\u001b[32m used\u001b[0m\u001b[32m to\u001b[0m\u001b[32m suppress\u001b[0m\u001b[32m a\u001b[0m\u001b[32m potential\u001b[0m\u001b[32m unchecked\u001b[0m\u001b[32m warning\u001b[0m\u001b[32m that\u001b[0m\u001b[32m might\u001b[0m\u001b[32m occur\u001b[0m\u001b[32m due\u001b[0m\u001b[32m to\u001b[0m\u001b[32m the\u001b[0m\u001b[32m raw\u001b[0m\u001b[32m type\u001b[0m\u001b[32m usage\u001b[0m\u001b[32m in\u001b[0m\u001b[32m the\u001b[0m\u001b[32m method\u001b[0m\u001b[32m signature\u001b[0m\u001b[32m.\u001b[0m\u001b[32m However\u001b[0m\u001b[32m,\u001b[0m\u001b[32m this\u001b[0m\u001b[32m is\u001b[0m\u001b[32m generally\u001b[0m\u001b[32m considered\u001b[0m\u001b[32m a\u001b[0m\u001b[32m code\u001b[0m\u001b[32m s\u001b[0m\u001b[32mmell\u001b[0m\u001b[32m and\u001b[0m\u001b[32m should\u001b[0m\u001b[32m be\u001b[0m\u001b[32m a\u001b[0m\u001b[32mvo\u001b[0m\u001b[32mided\u001b[0m\u001b[32m if\u001b[0m\u001b[32m possible\u001b[0m\u001b[32m.\u001b[0m\u001b[32m It\u001b[0m\u001b[32m's\u001b[0m\u001b[32m better\u001b[0m\u001b[32m to\u001b[0m\u001b[32m use\u001b[0m\u001b[32m gener\u001b[0m\u001b[32mics\u001b[0m\u001b[32m to\u001b[0m\u001b[32m avoid\u001b[0m\u001b[32m such\u001b[0m\u001b[32m warnings\u001b[0m\u001b[32m.\u001b[0m\n", + "\u001b[0m\u001b[32mThe\u001b[0m\u001b[32m `@\u001b[0m\u001b[32mSuppressWarnings\u001b[0m\u001b[32m(\"\u001b[0m\u001b[32munchecked\u001b[0m\u001b[32m\")\u001b[0m\u001b[32m`\u001b[0m\u001b[32m annotation\u001b[0m\u001b[32m is\u001b[0m\u001b[32m used\u001b[0m\u001b[32m to\u001b[0m\u001b[32m suppress\u001b[0m\u001b[32m a\u001b[0m\u001b[32m potential\u001b[0m\u001b[32m unchecked\u001b[0m\u001b[32m warning\u001b[0m\u001b[32m that\u001b[0m\u001b[32m might\u001b[0m\u001b[32m occur\u001b[0m\u001b[32m due\u001b[0m\u001b[32m to\u001b[0m\u001b[32m the\u001b[0m\u001b[32m raw\u001b[0m\u001b[32m type\u001b[0m\u001b[32m usage\u001b[0m\u001b[32m in\u001b[0m\u001b[32m the\u001b[0m\u001b[32m `\u001b[0m\u001b[32mJSON\u001b[0m\u001b[32m_\u001b[0m\u001b[32mMAP\u001b[0m\u001b[32mPER\u001b[0m\u001b[32m.\u001b[0m\u001b[32mreadValue\u001b[0m\u001b[32m`\u001b[0m\u001b[32m method\u001b[0m\u001b[32m.\u001b[0m\u001b[32m This\u001b[0m\u001b[32m is\u001b[0m\u001b[32m because\u001b[0m\u001b[32m the\u001b[0m\u001b[32m method\u001b[0m\u001b[32m expects\u001b[0m\u001b[32m a\u001b[0m\u001b[32m `\u001b[0m\u001b[32mMap\u001b[0m\u001b[32m.\u001b[0m\u001b[32mclass\u001b[0m\u001b[32m`\u001b[0m\u001b[32m as\u001b[0m\u001b[32m the\u001b[0m\u001b[32m second\u001b[0m\u001b[32m argument\u001b[0m\u001b[32m,\u001b[0m\u001b[32m but\u001b[0m\u001b[32m the\u001b[0m\u001b[32m actual\u001b[0m\u001b[32m type\u001b[0m\u001b[32m of\u001b[0m\u001b[32m the\u001b[0m\u001b[32m map\u001b[0m\u001b[32m is\u001b[0m\u001b[32m not\u001b[0m\u001b[32m known\u001b[0m\u001b[32m at\u001b[0m\u001b[32m compile\u001b[0m\u001b[32m time\u001b[0m\u001b[32m.\u001b[0m\n", "Evaluation:\n", "The similarity (Levenshtein) between this answer and the ground truth is:\n", - "\u001b[35m0.33441208198489747\u001b[0m" + "\u001b[35m0.34468085106382984\u001b[0m" ] } ], @@ -254,7 +254,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 35, "id": "dfef7096-b7a6-4966-8356-a306e701974b", "metadata": { "scrolled": true @@ -265,12 +265,12 @@ "output_type": "stream", "text": [ "How many years ago was the discoverer of the Hudson River born? Keep in mind we are in 2024.\n", - "\u001b[32mAct\u001b[0m\u001b[32m:\u001b[0m\u001b[32m{\"\u001b[0m\u001b[32mname\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m \"\u001b[0m\u001b[32mSearch\u001b[0m\u001b[32m\",\u001b[0m\u001b[32m \"\u001b[0m\u001b[32marguments\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m {\"\u001b[0m\u001b[32mtopic\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m \"\u001b[0m\u001b[32mH\u001b[0m\u001b[32men\u001b[0m\u001b[32mry\u001b[0m\u001b[32m H\u001b[0m\u001b[32mudson\u001b[0m\u001b[32m\"}}\u001b[0m\u001b[32m\n", + "Tho:\u001b[32mI\u001b[0m\u001b[32m need\u001b[0m\u001b[32m to\u001b[0m\u001b[32m search\u001b[0m\u001b[32m Hen\u001b[0m\u001b[32mry\u001b[0m\u001b[32m H\u001b[0m\u001b[32mudson\u001b[0m\u001b[32m,\u001b[0m\u001b[32m find\u001b[0m\u001b[32m out\u001b[0m\u001b[32m when\u001b[0m\u001b[32m he\u001b[0m\u001b[32m was\u001b[0m\u001b[32m born\u001b[0m\u001b[32m,\u001b[0m\u001b[32m then\u001b[0m\u001b[32m calculate\u001b[0m\u001b[32m how\u001b[0m\u001b[32m many\u001b[0m\u001b[32m years\u001b[0m\u001b[32m ago\u001b[0m\u001b[32m it\u001b[0m\u001b[32m was\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", + "\u001b[0m\u001b[32mAct\u001b[0m\u001b[32m:\u001b[0m\u001b[32m{\"\u001b[0m\u001b[32mname\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m \"\u001b[0m\u001b[32mSearch\u001b[0m\u001b[32m\",\u001b[0m\u001b[32m \"\u001b[0m\u001b[32marguments\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m {\"\u001b[0m\u001b[32mtopic\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m \"\u001b[0m\u001b[32mH\u001b[0m\u001b[32men\u001b[0m\u001b[32mry\u001b[0m\u001b[32m H\u001b[0m\u001b[32mudson\u001b[0m\u001b[32m\"}}\u001b[0m\u001b[32m\n", "\u001b[0mObs: \u001b[35mHenry Hudson (c. 1565 – disappeared 23 June 1611) was an English sea explorer and navigator during the early 17th century, best known for his explorations of present-day Canada and parts of the Northeastern United States.\n", "In 1607 and 1608, Hudson made two attempts on behalf of English merchants to find a rumoured Northeast Passage to Cathay via a route above the Arctic Circle. In 1609, he landed in North America on behalf of the Dutch East India Company and explored the region around the modern New York metropolitan area. Looking for a Northwest Passage to Asia on his ship Halve Maen (\"Half Moon\"), he sailed up the Hudson River, which was later named after him, and thereby laid the foundation for Dutch colonization of the region. His contributions to the exploration of the New World were significant and lasting. His voyages helped to establish European contact with the native peoples of North America and contributed to the development of trade and commerce. \n", "On his final expedition, while still searching for the Northwest Passage, Hudson became the first European to see Hudson Strait and the immense Hudson Bay. In 1611, after wintering on the shore of James Bay, Hudson wanted to press on to the west, but most of his crew mutinied. The mutineers cast Hudson, his son, and six others adrift; the Hudsons and their companions were never seen again.\u001b[0m\n", - "\u001b[32mH\u001b[0m\u001b[32men\u001b[0m\u001b[32mry\u001b[0m\u001b[32m H\u001b[0m\u001b[32mudson\u001b[0m\u001b[32m was\u001b[0m\u001b[32m born\u001b[0m\u001b[32m in\u001b[0m\u001b[32m the\u001b[0m\u001b[32m late\u001b[0m\u001b[32m \u001b[0m\u001b[32m1\u001b[0m\u001b[32m6\u001b[0m\u001b[32mth\u001b[0m\u001b[32m cent\u001b[0m\u001b[32mury\u001b[0m\u001b[32m,\u001b[0m\u001b[32m around\u001b[0m\u001b[32m \u001b[0m\u001b[32m1\u001b[0m\u001b[32m5\u001b[0m\u001b[32m6\u001b[0m\u001b[32m5\u001b[0m\u001b[32m.\u001b[0m\u001b[32m To\u001b[0m\u001b[32m find\u001b[0m\u001b[32m out\u001b[0m\u001b[32m how\u001b[0m\u001b[32m many\u001b[0m\u001b[32m years\u001b[0m\u001b[32m ago\u001b[0m\u001b[32m he\u001b[0m\u001b[32m was\u001b[0m\u001b[32m born\u001b[0m\u001b[32m,\u001b[0m\u001b[32m we\u001b[0m\u001b[32m need\u001b[0m\u001b[32m to\u001b[0m\u001b[32m subtract\u001b[0m\u001b[32m his\u001b[0m\u001b[32m birth\u001b[0m\u001b[32m year\u001b[0m\u001b[32m from\u001b[0m\u001b[32m the\u001b[0m\u001b[32m current\u001b[0m\u001b[32m year\u001b[0m\u001b[32m,\u001b[0m\u001b[32m which\u001b[0m\u001b[32m is\u001b[0m\u001b[32m \u001b[0m\u001b[32m2\u001b[0m\u001b[32m0\u001b[0m\u001b[32m2\u001b[0m\u001b[32m4\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32m\n", + "Tho:\u001b[32mH\u001b[0m\u001b[32men\u001b[0m\u001b[32mry\u001b[0m\u001b[32m H\u001b[0m\u001b[32mudson\u001b[0m\u001b[32m was\u001b[0m\u001b[32m born\u001b[0m\u001b[32m around\u001b[0m\u001b[32m \u001b[0m\u001b[32m1\u001b[0m\u001b[32m5\u001b[0m\u001b[32m6\u001b[0m\u001b[32m5\u001b[0m\u001b[32m.\u001b[0m\u001b[32m To\u001b[0m\u001b[32m find\u001b[0m\u001b[32m out\u001b[0m\u001b[32m how\u001b[0m\u001b[32m many\u001b[0m\u001b[32m years\u001b[0m\u001b[32m ago\u001b[0m\u001b[32m it\u001b[0m\u001b[32m was\u001b[0m\u001b[32m,\u001b[0m\u001b[32m I\u001b[0m\u001b[32m need\u001b[0m\u001b[32m to\u001b[0m\u001b[32m subtract\u001b[0m\u001b[32m his\u001b[0m\u001b[32m birth\u001b[0m\u001b[32m year\u001b[0m\u001b[32m from\u001b[0m\u001b[32m the\u001b[0m\u001b[32m current\u001b[0m\u001b[32m year\u001b[0m\u001b[32m,\u001b[0m\u001b[32m which\u001b[0m\u001b[32m is\u001b[0m\u001b[32m \u001b[0m\u001b[32m2\u001b[0m\u001b[32m0\u001b[0m\u001b[32m2\u001b[0m\u001b[32m4\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", "\u001b[0m\u001b[32mAct\u001b[0m\u001b[32m:\u001b[0m\u001b[32m{\"\u001b[0m\u001b[32mname\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m \"\u001b[0m\u001b[32mCalc\u001b[0m\u001b[32m\",\u001b[0m\u001b[32m \"\u001b[0m\u001b[32marguments\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m {\"\u001b[0m\u001b[32mexpr\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m \"\u001b[0m\u001b[32m2\u001b[0m\u001b[32m0\u001b[0m\u001b[32m2\u001b[0m\u001b[32m4\u001b[0m\u001b[32m -\u001b[0m\u001b[32m \u001b[0m\u001b[32m1\u001b[0m\u001b[32m5\u001b[0m\u001b[32m6\u001b[0m\u001b[32m5\u001b[0m\u001b[32m\"}}\u001b[0m\u001b[32m\n", "\u001b[0mObs: \u001b[35m459\u001b[0m\n" ] @@ -284,6 +284,7 @@ "- \"How many years ago was the discoverer of the Hudson River born? Keep in mind we are in 2024.\\n\"\n", "- repeat:\n", " text:\n", + " - \"Tho:\"\n", " - def: thought\n", " model: ibm/granite-8b-instruct-preview-4k\n", " platform: bam\n", @@ -322,6 +323,16 @@ " until: ${ action.name != \"Search\" }" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "9b919506-79ed-4a13-ac1d-1fdfc3e4f9d9", + "metadata": {}, + "outputs": [], + "source": [ + "! cat log.txt" + ] + }, { "cell_type": "markdown", "id": "89438b62-29e4-472e-89ec-57c1626ffd44", From f01b6cf9e2a43efac0b20e1ecdaebc37bbf6aa37 Mon Sep 17 00:00:00 2001 From: Mandana Vaziri Date: Mon, 14 Oct 2024 18:22:38 -0400 Subject: [PATCH 15/24] using replicate model Signed-off-by: Mandana Vaziri --- examples/arith/Arith-simple.pdl | 20 +++---- examples/arith/arith.pdl | 48 ----------------- examples/chatbot/chatbot.pdl | 3 +- examples/cldk/cldk-assistant.pdl | 13 ++--- examples/code/code-eval.pdl | 3 +- examples/code/code-json.pdl | 3 +- examples/code/code.pdl | 3 +- examples/demo/1-gen-data.pdl | 9 ++-- examples/demo/3-weather.pdl | 13 ++--- examples/demo/4-translator.pdl | 14 ++--- examples/earth/Earth.pdl | 10 ++-- examples/fibonacci/fib.pdl | 13 ++--- examples/hello/hello-def-use.pdl | 7 +-- examples/hello/hello-model-chaining.pdl | 15 ++---- examples/hello/hello-model-input.pdl | 7 +-- examples/hello/hello-parser-json.pdl | 20 +++---- examples/hello/hello-parser-regex.pdl | 8 +-- examples/hello/hello-roles-array.pdl | 3 +- examples/hello/hello-type.pdl | 15 ++---- examples/hello/hello.pdl | 8 +-- examples/joke/Joke.pdl | 18 ++----- examples/meta/pdl-gen.pdl | 43 ++++----------- examples/oddOneOut/OddOneOut.pdl | 27 +++------- examples/rag/rag.pdl | 7 +-- examples/react/demo.pdl | 29 ++++++----- examples/react/multi-agent.pdl | 4 +- examples/react/react_call.pdl | 2 +- examples/react/react_fun.pdl | 25 +++++---- examples/react/wikipedia.pdl | 55 +++++++++++++++----- examples/talk/1-hello.pdl | 5 +- examples/talk/11-sdg.pdl | 6 +-- examples/talk/2-model-chaining.pdl | 13 ++--- examples/talk/3-def-use.pdl | 13 ++--- examples/talk/4-function.pdl | 6 +-- examples/talk/5-code-eval.pdl | 3 +- examples/talk/6-code-json.pdl | 3 +- examples/talk/7-chatbot-roles.pdl | 6 +-- examples/talk/8-tools.pdl | 18 ++++--- examples/talk/9-react.pdl | 54 ++++++++++++++----- examples/teacher/teacher.pdl | 6 +-- examples/thing/Thing.pdl | 10 +--- examples/tools/calc.pdl | 18 ++++--- examples/tutorial/calling_apis.pdl | 20 +++---- examples/tutorial/calling_llm.pdl | 7 +-- examples/tutorial/calling_llm_with_input.pdl | 3 +- examples/tutorial/data_block.pdl | 3 +- examples/tutorial/function_definition.pdl | 8 +-- examples/tutorial/gen-data.pdl | 3 +- examples/tutorial/grouping_definitions.pdl | 5 +- examples/tutorial/include.pdl | 3 +- examples/tutorial/model_chaining.pdl | 12 ++--- examples/tutorial/muting_block_output.pdl | 5 +- examples/tutorial/variable_def_use.pdl | 6 +-- examples/weather/weather.pdl | 15 ++---- 54 files changed, 279 insertions(+), 417 deletions(-) delete mode 100644 examples/arith/arith.pdl diff --git a/examples/arith/Arith-simple.pdl b/examples/arith/Arith-simple.pdl index ff30702bd..1243ecdf9 100644 --- a/examples/arith/Arith-simple.pdl +++ b/examples/arith/Arith-simple.pdl @@ -4,29 +4,23 @@ text: - read: ./example2.txt - "\n" - | - Question: Noah charges $10 for a large box and $5 for a small box. + Question: Noah charges $25 for a large box and $11 for a small box. Last month he sold four large boxes and two small boxes. - If he sold half as much this month, how much is his sales for this month? + If he sold three times as much this month, how much is his sales for this month? - repeat: text: - def: REASON_OR_CALC - model: ibm/granite-8b-instruct-preview-4k - platform: bam + model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: - stop_sequences: - - '{' - include_stop_sequence: true + stop_sequences: '{' + temperature: 0 - if: ${ REASON_OR_CALC.endswith("{") } then: text: - def: EXPR - model: ibm/granite-8b-instruct-preview-4k - platform: bam + model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: - stop_sequences: - - '=' - - "\n" - - "Question" + stop_sequences: "=,\n,Question" include_stop_sequence: false - '= ' - def: RESULT diff --git a/examples/arith/arith.pdl b/examples/arith/arith.pdl deleted file mode 100644 index 1aad45f3a..000000000 --- a/examples/arith/arith.pdl +++ /dev/null @@ -1,48 +0,0 @@ -description: Math Problems -text: -- read: example1.txt -- read: example2.txt -- repeat: - text: - - "\nQuestion: " - - def: QUESTION - model: ibm/granite-34b-code-instruct - platform: bam - parameters: - stop_sequences: - - Answer - - "?" - include_stop_sequence: true - - "\nAnswer: Let's think step by step.\n" - - repeat: - text: - - def: REASON_OR_CALC - model: ibm/granite-34b-code-instruct - platform: bam - parameters: - stop_sequences: - - '<<' - - "Question" - include_stop_sequence: true - - if: ${ REASON_OR_CALC.endswith("<<") } - then: - text: - - def: EXPR - model: ibm/granite-34b-code-instruct - platform: bam - parameters: - stop_sequences: - - '=' - - "\n" - - "Question" - include_stop_sequence: false - - '= ' - - def: RESULT - lan: python - code: result = ${ EXPR } - - ' >>' - until: ${ "The answer is" in REASON_OR_CALC } - as: text - - "\n\n" - as: text - num_iterations: 3 \ No newline at end of file diff --git a/examples/chatbot/chatbot.pdl b/examples/chatbot/chatbot.pdl index df4a9a61f..cbea4c720 100644 --- a/examples/chatbot/chatbot.pdl +++ b/examples/chatbot/chatbot.pdl @@ -5,8 +5,7 @@ text: contribute: [context] - repeat: text: - - model: ibm/granite-13b-chat-v2 - platform: bam + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - read: def: eval message: "\nIs this a good answer[yes/no]?\n" diff --git a/examples/cldk/cldk-assistant.pdl b/examples/cldk/cldk-assistant.pdl index 796b2a535..05c739064 100644 --- a/examples/cldk/cldk-assistant.pdl +++ b/examples/cldk/cldk-assistant.pdl @@ -35,8 +35,7 @@ text: - "\n***Generating PDL code for your query:\n" - if: ${ query != 'quit'} then: - - model: ibm/granite-34b-code-instruct - platform: bam + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 def: PDL input: - | @@ -117,8 +116,7 @@ text: method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") result = method - "\n\nGenerate a summary of method Foo\n\n" - - model: ibm/granite-34b-code-instruct - platform: bam + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 ``` Question: Generate a different comment for method Foo(string) in class org.ibm.App? @@ -131,8 +129,7 @@ text: method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") result = method - "\n\nGenerate a different comment for method Foo(string)\n\n" - - model: ibm/granite-34b-code-instruct - platform: bam + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 ``` If the query contains something about a field be sure to call a model. @@ -141,10 +138,10 @@ text: parameters: - stop_sequences: ["Question"] + stop_sequences: "Question" include_stop_sequence: false - "\n\n***Executing the above PDL code:\n\n" - - lan: python + - lang: python contribute: [result] code: | from pdl import pdl_ast, pdl_interpreter diff --git a/examples/code/code-eval.pdl b/examples/code/code-eval.pdl index 55fbc9543..f92c27f06 100644 --- a/examples/code/code-eval.pdl +++ b/examples/code/code-eval.pdl @@ -7,8 +7,7 @@ defs: read: ./ground_truth.txt text: - "\n${ CODE.source_code }\n" -- model: ibm/granite-8b-instruct-preview-4k - platform: bam +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 def: EXPLANATION input: | Here is some info about the location of the function in the repo. diff --git a/examples/code/code-json.pdl b/examples/code/code-json.pdl index c0eedecfd..58d778c06 100644 --- a/examples/code/code-json.pdl +++ b/examples/code/code-json.pdl @@ -6,8 +6,7 @@ defs: TRUTH: read: ./ground_truth.txt text: -- model: ibm/granite-8b-instruct-preview-4k - platform: bam +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 def: EXPLANATION contribute: [] input: diff --git a/examples/code/code.pdl b/examples/code/code.pdl index 632224902..86df57407 100644 --- a/examples/code/code.pdl +++ b/examples/code/code.pdl @@ -5,8 +5,7 @@ defs: parser: yaml text: - "\n${ CODE.source_code }\n" -- model: ibm/granite-8b-instruct-preview-4k - platform: bam +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 input: - | Here is some info about the location of the function in the repo. diff --git a/examples/demo/1-gen-data.pdl b/examples/demo/1-gen-data.pdl index bca38bfc9..73b3697ae 100644 --- a/examples/demo/1-gen-data.pdl +++ b/examples/demo/1-gen-data.pdl @@ -5,8 +5,7 @@ defs: parser: yaml spec: { questions: [str], answers: [obj] } text: - - model: ibm/granite-8b-instruct-preview-4k - platform: bam + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 def: model_output spec: {name: str, age: int} input: @@ -23,7 +22,7 @@ text: and set them appropriately. Write the age in letters. parser: yaml parameters: - stop_sequences: - - '}' - include_stop_sequence: true + stop_sequences: "\n" + temperature: 0 + \ No newline at end of file diff --git a/examples/demo/3-weather.pdl b/examples/demo/3-weather.pdl index b49ecbbfa..66e91bd98 100644 --- a/examples/demo/3-weather.pdl +++ b/examples/demo/3-weather.pdl @@ -4,8 +4,7 @@ text: def: QUERY message: "Ask a query: " contribute: [] -- model: ibm/granite-8b-instruct-preview-4k - platform: bam +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 input: | Extract the location from the question. Question: What is the weather in London? @@ -16,12 +15,7 @@ text: Answer: Lagos Question: ${ QUERY } parameters: - stop_sequences: - - Question - - What - - '!' - - "\n" - include_stop_sequence: false + stop_sequences: "Question,What,!,\n" def: LOCATION contribute: [] - lang: python @@ -33,8 +27,7 @@ text: parser: json contribute: [] -- model: ibm/granite-8b-instruct-preview-4k - platform: bam +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 input: | Explain the weather from the following JSON: ${ WEATHER } diff --git a/examples/demo/4-translator.pdl b/examples/demo/4-translator.pdl index 4c7aeced4..222b0b9ce 100644 --- a/examples/demo/4-translator.pdl +++ b/examples/demo/4-translator.pdl @@ -1,12 +1,7 @@ description: PDL program text: -- What is APR? -- model: ibm/granite-13b-chat-v2 - platform: bam - parameters: - max_new_tokens: 128 - stop_sequences: ["."] - include_stop_sequence: true +- "What is APR?\n" +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - repeat: text: - read: @@ -15,7 +10,6 @@ text: - if: ${ language != 'stop' } then: text: - - "\n\nTranslate the above to ${ language }" - - model: ibm/granite-13b-chat-v2 - platform: bam + - "\n\nTranslate the above to ${ language }\n" + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 until: ${ language == 'stop' } diff --git a/examples/earth/Earth.pdl b/examples/earth/Earth.pdl index 83c14c118..85fdacc95 100644 --- a/examples/earth/Earth.pdl +++ b/examples/earth/Earth.pdl @@ -2,14 +2,10 @@ description: Earth circumference question text: - 'What is the circumference of the earth? I believe the best person to answer this question is ' - def: EXPERT - model: ibm/granite-8b-instruct-preview-4k - platform: bam + model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: - stop_sequences: - - "." - include_stop_sequence: false + stop_sequences: "." - '. Indeed, ' - get: EXPERT - ' addressed this question: ' -- model: ibm/granite-8b-instruct-preview-4k - platform: bam \ No newline at end of file +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 \ No newline at end of file diff --git a/examples/fibonacci/fib.pdl b/examples/fibonacci/fib.pdl index e80fdd52b..b27eec7a9 100644 --- a/examples/fibonacci/fib.pdl +++ b/examples/fibonacci/fib.pdl @@ -1,9 +1,10 @@ description: Fibonacci text: - def: CODE - model: ibm/granite-8b-instruct-preview-4k - platform: bam - input: "Write a Python function to compute the Fibonacci sequence\n\n" + model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 + input: "Write a Python function to compute the Fibonacci sequence. Do not include a doc string.\n\n" + parameters: + temperature: 0 - "\nFind a random number between 1 and 20\n" - def: N @@ -11,7 +12,7 @@ text: code: | import random result = random.randint(1, 20) -- "\nNow computing fib(${ N })\n" +- "\nNow computing fibonacci(${ N })\n" - def: EXTRACTED lang: python code: | @@ -25,5 +26,5 @@ text: contribute: [] - 'The result is: ${ RESULT }' - "\n\nExplain what the above code does and what the result means\n\n" -- model: ibm/granite-8b-instruct-preview-4k - platform: bam \ No newline at end of file +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 + \ No newline at end of file diff --git a/examples/hello/hello-def-use.pdl b/examples/hello/hello-def-use.pdl index 174c48bfa..bee6b6cb3 100644 --- a/examples/hello/hello-def-use.pdl +++ b/examples/hello/hello-def-use.pdl @@ -1,13 +1,10 @@ description: Hello world with variable use text: - Hello, -- model: ibm/granite-34b-code-instruct - platform: bam +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: decoding_method: greedy - stop_sequences: - - '!' - include_stop_sequence: false + stop_sequences: '!' def: NAME - | diff --git a/examples/hello/hello-model-chaining.pdl b/examples/hello/hello-model-chaining.pdl index 1f0b6d4b4..7db8e698d 100644 --- a/examples/hello/hello-model-chaining.pdl +++ b/examples/hello/hello-model-chaining.pdl @@ -1,22 +1,17 @@ description: Hello world showing model chaining text: - Hello, -- model: ibm/granite-8b-instruct-preview-4k - platform: bam +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: decoding_method: greedy - stop_sequences: - - '!' - include_stop_sequence: false + stop_sequences: '!' def: NAME - |- ! Who is${ NAME }? - "\n" -- model: google/flan-t5-xl - platform: bam +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: decoding_method: greedy - stop_sequences: - - '.' - include_stop_sequence: true + stop_sequences: '.' + \ No newline at end of file diff --git a/examples/hello/hello-model-input.pdl b/examples/hello/hello-model-input.pdl index e107f189b..3ebc842f1 100644 --- a/examples/hello/hello-model-input.pdl +++ b/examples/hello/hello-model-input.pdl @@ -1,9 +1,6 @@ description: Hello world with model input text: -- model: ibm/granite-8b-instruct-preview-4k - platform: bam +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 input: "Hello," parameters: - stop_sequences: - - '!' - include_stop_sequence: true + stop_sequences: '!' diff --git a/examples/hello/hello-parser-json.pdl b/examples/hello/hello-parser-json.pdl index 8a63c0eb6..a14d5112f 100644 --- a/examples/hello/hello-parser-json.pdl +++ b/examples/hello/hello-parser-json.pdl @@ -3,13 +3,12 @@ defs: data: read: ./hello-parser-json-data.yaml parser: yaml - spec: { "questions": ["str"], "answers": ["obj"] } + spec: { questions: [str], answers: [obj] } text: - - model: ibm/granite-8b-instruct-preview-4k - platform: bam + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 def: model_output - spec: {"name": str, "age": int} - input: + spec: {name: str, age: int} + input: text: - for: question: ${ data.questions } @@ -20,14 +19,9 @@ text: ${ answer } - > Question: Create a JSON object with fields 'name' and 'age' - and set them appropriately. + and set them appropriately. parser: yaml parameters: - decoding_method: greedy - stop_sequences: - - '}' - include_stop_sequence: true - - - + stop_sequences: "\n" + temperature: 0 diff --git a/examples/hello/hello-parser-regex.pdl b/examples/hello/hello-parser-regex.pdl index dc3219e7c..ede4d8474 100644 --- a/examples/hello/hello-parser-regex.pdl +++ b/examples/hello/hello-parser-regex.pdl @@ -1,13 +1,9 @@ description: Hello world with parser using regex text: -- model: ibm/granite-8b-instruct-preview-4k - platform: bam +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 input: "Hello," parameters: - decoding_method: greedy - stop_sequences: - - '!' - include_stop_sequence: false + stop_sequences: '!' spec: {"name": str} parser: spec: diff --git a/examples/hello/hello-roles-array.pdl b/examples/hello/hello-roles-array.pdl index b456afa9b..1c3be4509 100644 --- a/examples/hello/hello-roles-array.pdl +++ b/examples/hello/hello-roles-array.pdl @@ -7,7 +7,6 @@ text: - role: user content: Write a Python function that implement merge sort. contribute: [] -- model: ibm/granite-8b-instruct-preview-4k - platform: bam +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 input: ${ prompt } diff --git a/examples/hello/hello-type.pdl b/examples/hello/hello-type.pdl index 09ac31a8c..1ad94085d 100644 --- a/examples/hello/hello-type.pdl +++ b/examples/hello/hello-type.pdl @@ -1,13 +1,10 @@ description: Hello world with type specification text: - Hello, -- model: ibm/granite-8b-instruct-preview-4k - platform: bam +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 def: GEN parameters: - stop_sequences: - - '!' - include_stop_sequence: true + stop_sequences: "!" - def: translate function: sentence: str @@ -15,13 +12,9 @@ text: spec: int return: - "\nTranslate the sentence '${ sentence }' to ${ language }\n" - - model: ibm/granite-20b-multilingual - platform: bam + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: - stop_sequences: - - "\n" - include_stop_sequence: true - + stop_sequences: "\n" - call: translate spec: str args: diff --git a/examples/hello/hello.pdl b/examples/hello/hello.pdl index 8bc00a4b3..ef1036d6a 100644 --- a/examples/hello/hello.pdl +++ b/examples/hello/hello.pdl @@ -1,10 +1,4 @@ description: Hello world text: - "Hello\n" -- model: ibm/granite-8b-instruct-preview-4k - platform: bam - parameters: - decoding_method: greedy - stop_sequences: - - '!' - include_stop_sequence: true \ No newline at end of file +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 diff --git a/examples/joke/Joke.pdl b/examples/joke/Joke.pdl index db930ce00..0501416f2 100644 --- a/examples/joke/Joke.pdl +++ b/examples/joke/Joke.pdl @@ -10,22 +10,12 @@ text: text: - 'Q: ' - def: JOKE - model: ibm/granite-8b-instruct-preview-4k - platform: bam + model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: - decoding_method: sample - stop_sequences: - - '?' - - "\n" - include_stop_sequence: false + stop_sequences: "?,\n" - "\nA: " - - model: ibm/granite-8b-instruct-preview-4k - platform: bam + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: - decoding_method: sample - stop_sequences: - - END - - "\n" - include_stop_sequence: true + stop_sequences: "END,\n" - "\n" num_iterations: 2 diff --git a/examples/meta/pdl-gen.pdl b/examples/meta/pdl-gen.pdl index 6e60fc415..68e2d748a 100644 --- a/examples/meta/pdl-gen.pdl +++ b/examples/meta/pdl-gen.pdl @@ -14,10 +14,7 @@ text: result = ''.join(contents) def: QUERY contribute: [] -- model: ibm/granite-8b-instruct-preview-4k - platform: bam - parameters: - decoding_method: greedy +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 input: text: - |- @@ -106,9 +103,7 @@ text: ``` description: PDL with model call text: - - model: watsonx/ibm/granite-20b-code-instruct - parameters: - decoding_method: greedy + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 ``` Question: Write a PDL script that makes a call to a model with stop sequence '!' and stop sequences included @@ -117,12 +112,7 @@ text: ``` description: PDL with model call text: - - model: watsonx/ibm/granite-20b-code-instruct - parameters: - decoding_method: greedy - stop_sequences: - - '!' - include_stop_sequence: true + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 ``` @@ -132,9 +122,7 @@ text: ``` description: PDL with model call text: - - model: "watsonx/google/flan-t5-xl" - parameters: - decoding_method: greedy + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 ``` Question: Write a PDL script that makes a call to a model with stop sequence '\n' and stop sequences not included @@ -143,12 +131,7 @@ text: ``` description: PDL with model call text: - - model: watsonx/ibm/granite-20b-code-instruct - parameters: - decoding_method: greedy - stop_sequences: - - '\n' - include_stop_sequence: false + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 ``` Question: Write a PDL script with a block that has an assignment to variable NAME @@ -157,9 +140,7 @@ text: ``` description: PDL with model call text: - - model: "watsonx/google/flan-t5-xl" - parameters: - decoding_method: greedy + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 def: NAME ``` @@ -169,9 +150,7 @@ text: ``` description: PDL with model call text: - - model: "watsonx/google/flan-t5-xl" - parameters: - decoding_method: greedy + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 contribute: [] ``` @@ -223,7 +202,7 @@ text: ``` description: PDL with model call text: - - model: "watsonx/google/flan-t5-xl" + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: decoding_method: greedy input: @@ -242,7 +221,7 @@ text: ``` description: PDL with model call text: - - model: "google/flan-t5-xl" + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: decoding_method: greedy input: @@ -262,7 +241,7 @@ text: ``` description: PDL with model call text: - - model: "watsonx/google/flan-t5-xl" + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: decoding_method: greedy input: @@ -284,7 +263,7 @@ text: ``` description: PDL with model call text: - - model: "watsonx/google/flan-t5-xl" + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: decoding_method: greedy input: diff --git a/examples/oddOneOut/OddOneOut.pdl b/examples/oddOneOut/OddOneOut.pdl index 2cf80ad44..5f0edc85a 100644 --- a/examples/oddOneOut/OddOneOut.pdl +++ b/examples/oddOneOut/OddOneOut.pdl @@ -12,31 +12,16 @@ text: text: - "Question: Pick the odd word out:\n" - def: OPTIONS - model: ibm/granite-3b-instruct-preview - platform: bam + model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: - decoding_method: greedy - stop_sequences: - - . - include_stop_sequence: false + stop_sequences: "." - "\nReasoning:\n" - - model: ibm/granite-3b-instruct-preview - platform: bam + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: - decoding_method: greedy - stop_sequences: - - Pick the odd word - - "\n" - - So the odd one - - . - include_stop_sequence: false + stop_sequences: "Pick the odd word,\n,So the odd one,." - "\nResult:\n" - - model: ibm/granite-3b-instruct-preview - platform: bam + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: - decoding_method: greedy - stop_sequences: - - Pick the odd word - include_stop_sequence: false + stop_sequences: "Pick the odd word" - "\n\n" num_iterations: 2 diff --git a/examples/rag/rag.pdl b/examples/rag/rag.pdl index d2083b335..a61d70fdc 100644 --- a/examples/rag/rag.pdl +++ b/examples/rag/rag.pdl @@ -42,8 +42,5 @@ text: - |- Q: ${ TEST_PROMPT } - A: ``` -- model: ibm/granite-20b-code-instruct-v2 - platform: bam - parameters: - stop_sequences: ["```"] + A: +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 diff --git a/examples/react/demo.pdl b/examples/react/demo.pdl index 55b0107ee..169eb599a 100644 --- a/examples/react/demo.pdl +++ b/examples/react/demo.pdl @@ -19,11 +19,13 @@ text: Act: {"name": "Finish", "arguments": {"topic": "director, screenwriter, actor"}} What is 18 + 12 x 3? + Tho: I need to call a calculator. Act: {"name": "Calc", "arguments": {"expr": "18 + 12 * 3"}} Obs: 54 Act: {"name": "Finish", "arguments": {"topic": "54"}} A total of 252 qualifying matches were played, and 723 goals were scored. What was the average number of goals per match? + Tho: I need to call a calculator. Act: {"name": "Calc", "arguments": {"expr": "723 / 252"}} Obs: 2.869047619047619 Act: {"name": "Finish", "arguments": {"topic": "2.869047619047619"}} @@ -33,25 +35,28 @@ text: - repeat: text: - def: thought - model: ibm/granite-8b-instruct-preview-4k - platform: bam + model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: - stop_sequences: - - "Act:" - include_stop_sequence: true - - def: action - model: ibm/granite-8b-instruct-preview-4k - platform: bam + stop_sequences: "Act:" + temperature: 0 + - def: rawAction + model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: - stop_sequences: - - "\n" + stop_sequences: "\n" + temperature: 0 + - def: action + lang: python parser: json spec: {name: str, arguments: obj} + contribute: [context] + code: + | + result = '${ rawAction }'.replace("Act: ", "") - def: observation if: ${ action.name == "Search" } then: text: - - "Obs: " + - "\nObs: " - lang: python code: | import warnings, wikipedia @@ -65,7 +70,7 @@ text: - if: ${ action.name == "Calc" } then: text: - - "Obs: " + - "\nObs: " - lang: python code: result = ${ action.arguments.expr } - "\n" diff --git a/examples/react/multi-agent.pdl b/examples/react/multi-agent.pdl index 2dcfd35b2..5c5a95b13 100644 --- a/examples/react/multi-agent.pdl +++ b/examples/react/multi-agent.pdl @@ -6,13 +6,13 @@ text: call: react args: question: ${ question } - model: ibm/granite-20b-code-instruct + model: replicate/ibm-granite/granite-20b-code-instruct-8k - "\n\n----- Verifying answer... -----\n\n" - def: verified call: react args: question: ${ question } - model: ibm/granite-8b-instruct-preview-4k + model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - "\n" - if: ${ proposed.split('Act:') | last == verified.split('Act:') | last } then: diff --git a/examples/react/react_call.pdl b/examples/react/react_call.pdl index 540b3cb82..a3393d6dc 100644 --- a/examples/react/react_call.pdl +++ b/examples/react/react_call.pdl @@ -4,6 +4,6 @@ text: - call: react args: question: How many years ago was the discoverer of the Hudson River born? - model: ibm/granite-8b-instruct-preview-4k + model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 diff --git a/examples/react/react_fun.pdl b/examples/react/react_fun.pdl index 68677b2a2..ca07f2843 100644 --- a/examples/react/react_fun.pdl +++ b/examples/react/react_fun.pdl @@ -24,26 +24,29 @@ defs: text: - def: thought model: ${ model } - platform: bam parameters: - stop_sequences: - - "Act:" - include_stop_sequence: true - - def: action + stop_sequences: "Act:" + temperature: 0 + - def: rawAction model: ${ model } - platform: bam parameters: - stop_sequences: - - "\n" + stop_sequences: "\n" + temperature: 0 + - def: action + lang: python parser: json spec: {name: str, arguments: obj} - - if: ${ action != prev_action} + contribute: [context] + code: + | + result = '${ rawAction }'.replace("Act: ", "") + - if: ${ action != prev_action} then: - def: observation if: ${ action.name == "Search" } then: text: - - "Obs: " + - "\nObs: " - lang: python code: | import warnings, wikipedia @@ -57,7 +60,7 @@ defs: - if: ${ action.name == "Calc" } then: text: - - "Obs: " + - "\nObs: " - lang: python code: result = ${ action.arguments.expr } - "\n" diff --git a/examples/react/wikipedia.pdl b/examples/react/wikipedia.pdl index 2356882ce..49a3f06ba 100644 --- a/examples/react/wikipedia.pdl +++ b/examples/react/wikipedia.pdl @@ -18,31 +18,57 @@ text: Tho: Professions of Elia Kazan are director, producer, screenwriter, and actor. So profession Nicholas Ray and Elia Kazan have in common is director, screenwriter, and actor. Act: {"name": "Finish", "arguments": {"topic": "director, screenwriter, actor"}} - + What is 18 + 12 x 3? + Tho: I need to call a calculator. + Act: {"name": "Calc", "arguments": {"expr": "18 + 12 * 3"}} + Obs: 54 + Act: {"name": "Finish", "arguments": {"topic": "54"}} - Find the year when the discoverer of the Hudson River was born? + A total of 252 qualifying matches were played, and 723 goals were scored. What was the average number of goals per match? + Tho: I need to call a calculator. + Act: {"name": "Calc", "arguments": {"expr": "723 / 252"}} + Obs: 2.869047619047619 + Act: {"name": "Finish", "arguments": {"topic": "2.869047619047619"}} + + What is 18 + 12 x 3? + Tho: I need to call a calculator. + Act: {"name": "Calc", "arguments": {"expr": "18 + 12 * 3"}} + Obs: 54 + Act: {"name": "Finish", "arguments": {"topic": "54"}} + + A total of 252 qualifying matches were played, and 723 goals were scored. What was the average number of goals per match? + Tho: I need to call a calculator. + Act: {"name": "Calc", "arguments": {"expr": "723 / 252"}} + Obs: 2.869047619047619 + Act: {"name": "Finish", "arguments": {"topic": "2.869047619047619"}} + + + when was the discoverer of the Hudson River born? - repeat: text: - def: thought - model: ibm/granite-8b-instruct-preview-4k - platform: bam + model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: - stop_sequences: - - "Act:" - include_stop_sequence: true - - def: action - model: ibm/granite-8b-instruct-preview-4k - platform: bam + stop_sequences: "Act:" + temperature: 0 + - def: rawAction + model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: - stop_sequences: - - "\n" + stop_sequences: "\n" + temperature: 0 + - def: action + lang: python parser: json - spec: {name: str, arguments: {topic: str}} + spec: {name: str, arguments: obj} + contribute: [context] + code: + | + result = '${ rawAction }'.replace("Act: ", "") - def: observation if: ${ action.name == "Search" } then: text: - - "Obs: " + - "\nObs: " - lang: python code: | import warnings, wikipedia @@ -51,5 +77,6 @@ text: result = wikipedia.summary("${ action.arguments.topic }") except wikipedia.WikipediaException as e: result = str(e) + - "\n" until: ${ action.name != "Search" } diff --git a/examples/talk/1-hello.pdl b/examples/talk/1-hello.pdl index cf2fab0a1..3786fb557 100644 --- a/examples/talk/1-hello.pdl +++ b/examples/talk/1-hello.pdl @@ -1,9 +1,8 @@ description: Model call text: - "Hello\n" -- model: ibm/granite-8b-instruct-preview-4k - platform: bam +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: - stop_sequences: ["!"] + stop_sequences: "!" include_stop_sequence: true diff --git a/examples/talk/11-sdg.pdl b/examples/talk/11-sdg.pdl index 6ec636c25..7fe1dce08 100644 --- a/examples/talk/11-sdg.pdl +++ b/examples/talk/11-sdg.pdl @@ -1,7 +1,7 @@ description: Real-world Synthetic Data Generation (SDG) pipeline defs: teacher_sys_prompt: You are a very knowledgeable AI Assistant that will faithfully assist the user with their task. - teacher_model: mistralai/mixtral-8x7b-instruct-v01 + teacher_model: watsonx/mistralai/mixtral-8x7b-instruct-v01 teacher_template: function: sys_prompt: str @@ -66,7 +66,6 @@ defs: ${prompt_data.generation} teacher_output: model: ${teacher_model} - platform: bam input: ${teacher_input} parameters: stop_sequences: ["${teacher_stop_token}"] @@ -157,7 +156,6 @@ defs: teacher_output: model: ${teacher_model} input: ${teacher_input} - platform: bam parameters: stop_sequences: ["${teacher_stop_token}"] include_stop_sequence: false @@ -253,7 +251,6 @@ defs: teacher_output: model: ${teacher_model} input: ${teacher_input} - platform: bam parameters: stop_sequences: ${ [teacher_stop_token] + prompt_data.additional_stop_tokens } include_stop_sequence: false @@ -341,7 +338,6 @@ defs: teacher_output: model: ${teacher_model} input: ${teacher_input} - platform: bam parameters: stop_sequences: ["${teacher_stop_token}"] include_stop_sequence: false diff --git a/examples/talk/2-model-chaining.pdl b/examples/talk/2-model-chaining.pdl index f2967594c..bfc517468 100644 --- a/examples/talk/2-model-chaining.pdl +++ b/examples/talk/2-model-chaining.pdl @@ -1,14 +1,11 @@ description: Model chaining text: - "Hello\n" -- model: ibm/granite-8b-instruct-preview-4k - platform: bam +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: - stop_sequences: ["!"] - include_stop_sequence: true + stop_sequences: "!" - "\nTranslate this to French\n" -- model: ibm/granite-20b-multilang-lab-rc - platform: bam +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: - stop_sequences: ["!"] - include_stop_sequence: true + stop_sequences: "!" + \ No newline at end of file diff --git a/examples/talk/3-def-use.pdl b/examples/talk/3-def-use.pdl index cba997fd3..ca2328f3f 100644 --- a/examples/talk/3-def-use.pdl +++ b/examples/talk/3-def-use.pdl @@ -1,17 +1,14 @@ description: Variable def and use, model input text: - "Hello,\n" -- model: ibm/granite-8b-instruct-preview-4k - platform: bam +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 def: name parameters: - stop_sequences: ["!"] - include_stop_sequence: false + stop_sequences: "!" - "\n" -- model: ibm/granite-20b-multilingual - platform: bam +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 input: - "Translate the word ${ name | trim } to French\n" parameters: - stop_sequences: - - "\n" + stop_sequences: "\n" + temperature: 0 diff --git a/examples/talk/4-function.pdl b/examples/talk/4-function.pdl index cb8c4161e..ccb06c493 100644 --- a/examples/talk/4-function.pdl +++ b/examples/talk/4-function.pdl @@ -6,10 +6,10 @@ text: language: str return: - "\nTranslate the sentence '${ sentence }' to ${ language }.\n" - - model: ibm/granite-20b-multilingual - platform: bam + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: - stop_sequences: ["\n"] + stop_sequences: "\n" + temperature: 0 - call: translate args: sentence: I love Paris! diff --git a/examples/talk/5-code-eval.pdl b/examples/talk/5-code-eval.pdl index 55fbc9543..d6d0f6101 100644 --- a/examples/talk/5-code-eval.pdl +++ b/examples/talk/5-code-eval.pdl @@ -7,8 +7,7 @@ defs: read: ./ground_truth.txt text: - "\n${ CODE.source_code }\n" -- model: ibm/granite-8b-instruct-preview-4k - platform: bam +- model: ireplicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 def: EXPLANATION input: | Here is some info about the location of the function in the repo. diff --git a/examples/talk/6-code-json.pdl b/examples/talk/6-code-json.pdl index 1b208dbe4..989dc886c 100644 --- a/examples/talk/6-code-json.pdl +++ b/examples/talk/6-code-json.pdl @@ -6,8 +6,7 @@ defs: TRUTH: read: ./ground_truth.txt text: -- model: ibm/granite-8b-instruct-preview-4k - platform: bam +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 def: EXPLANATION contribute: [] input: diff --git a/examples/talk/7-chatbot-roles.pdl b/examples/talk/7-chatbot-roles.pdl index 5c46e54c8..7e7cb1a9e 100644 --- a/examples/talk/7-chatbot-roles.pdl +++ b/examples/talk/7-chatbot-roles.pdl @@ -1,9 +1,8 @@ description: chatbot, control structures, roles, contribute text: -- include: ../granite/granite_defs.pdl - role: system contribute: [context] - text: ${ SYSTEM_CONTENT_CHAT } + text: You are Granite, an AI language model developed by IBM in 2024. - "Type `quit` to exit this chatbot.\n" - repeat: text: @@ -11,8 +10,7 @@ text: message: ">>> " def: query contribute: [context] - - model: ibm/granite-13b-chat-v2 - platform: bam + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - "\n\n" until: ${ query == 'quit'} join: diff --git a/examples/talk/8-tools.pdl b/examples/talk/8-tools.pdl index 188745c71..8101f9bcf 100644 --- a/examples/talk/8-tools.pdl +++ b/examples/talk/8-tools.pdl @@ -15,14 +15,20 @@ text: Obs: 2.869047619047619 Out of 1400 participants, 400 passed the test. What percentage is that? - Act: -- def: action - model: ibm/granite-8b-code-instruct - platform: bam +- "\n" +- def: rawAction + model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: - stop_sequences: ["\n"] + stop_sequences: "\n" +- def: action + lang: python parser: json - spec: {name: str, arguments: {expr: str}} + spec: {name: str, arguments: obj} + contribute: [context] + code: + | + result = '${ rawAction }'.replace("Act: ", "") +- "\n" - if: ${ action.name == "Calc" } then: - "Obs: " diff --git a/examples/talk/9-react.pdl b/examples/talk/9-react.pdl index f8a852aca..49a3f06ba 100644 --- a/examples/talk/9-react.pdl +++ b/examples/talk/9-react.pdl @@ -18,30 +18,57 @@ text: Tho: Professions of Elia Kazan are director, producer, screenwriter, and actor. So profession Nicholas Ray and Elia Kazan have in common is director, screenwriter, and actor. Act: {"name": "Finish", "arguments": {"topic": "director, screenwriter, actor"}} - + What is 18 + 12 x 3? + Tho: I need to call a calculator. + Act: {"name": "Calc", "arguments": {"expr": "18 + 12 * 3"}} + Obs: 54 + Act: {"name": "Finish", "arguments": {"topic": "54"}} - Find the year when the discoverer of the Hudson River was born? + A total of 252 qualifying matches were played, and 723 goals were scored. What was the average number of goals per match? + Tho: I need to call a calculator. + Act: {"name": "Calc", "arguments": {"expr": "723 / 252"}} + Obs: 2.869047619047619 + Act: {"name": "Finish", "arguments": {"topic": "2.869047619047619"}} + + What is 18 + 12 x 3? + Tho: I need to call a calculator. + Act: {"name": "Calc", "arguments": {"expr": "18 + 12 * 3"}} + Obs: 54 + Act: {"name": "Finish", "arguments": {"topic": "54"}} + + A total of 252 qualifying matches were played, and 723 goals were scored. What was the average number of goals per match? + Tho: I need to call a calculator. + Act: {"name": "Calc", "arguments": {"expr": "723 / 252"}} + Obs: 2.869047619047619 + Act: {"name": "Finish", "arguments": {"topic": "2.869047619047619"}} + + + when was the discoverer of the Hudson River born? - repeat: text: - def: thought - model: ibm/granite-8b-instruct-preview-4k - platform: bam + model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: - stop_sequences: - - "Act:" - include_stop_sequence: true - - def: action - model: ibm/granite-8b-instruct-preview-4k - platform: bam + stop_sequences: "Act:" + temperature: 0 + - def: rawAction + model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: - stop_sequences: - - "\n" + stop_sequences: "\n" + temperature: 0 + - def: action + lang: python parser: json + spec: {name: str, arguments: obj} + contribute: [context] + code: + | + result = '${ rawAction }'.replace("Act: ", "") - def: observation if: ${ action.name == "Search" } then: text: - - "Obs: " + - "\nObs: " - lang: python code: | import warnings, wikipedia @@ -50,5 +77,6 @@ text: result = wikipedia.summary("${ action.arguments.topic }") except wikipedia.WikipediaException as e: result = str(e) + - "\n" until: ${ action.name != "Search" } diff --git a/examples/teacher/teacher.pdl b/examples/teacher/teacher.pdl index ae55d71b6..743684a20 100644 --- a/examples/teacher/teacher.pdl +++ b/examples/teacher/teacher.pdl @@ -1,6 +1,6 @@ defs: teacher_sys_prompt: You are a very knowledgeable AI Assistant that will faithfully assist the user with their task. - teacher_model: mistralai/mixtral-8x7b-instruct-v01 + teacher_model: watsonx/mistralai/mixtral-8x7b-instruct-v01 teacher_template: function: sys_prompt: str @@ -65,7 +65,6 @@ defs: ${prompt_data.generation} teacher_output: model: ${teacher_model} - platform: bam input: ${teacher_input} parameters: stop_sequences: ["${teacher_stop_token}"] @@ -156,7 +155,6 @@ defs: teacher_output: model: ${teacher_model} input: ${teacher_input} - platform: bam parameters: stop_sequences: ["${teacher_stop_token}"] include_stop_sequence: false @@ -252,7 +250,6 @@ defs: teacher_output: model: ${teacher_model} input: ${teacher_input} - platform: bam parameters: stop_sequences: ${ [teacher_stop_token] + prompt_data.additional_stop_tokens } include_stop_sequence: false @@ -340,7 +337,6 @@ defs: teacher_output: model: ${teacher_model} input: ${teacher_input} - platform: bam parameters: stop_sequences: ["${teacher_stop_token}"] include_stop_sequence: false diff --git a/examples/thing/Thing.pdl b/examples/thing/Thing.pdl index 0e65c1562..4786ee094 100644 --- a/examples/thing/Thing.pdl +++ b/examples/thing/Thing.pdl @@ -3,17 +3,11 @@ text: - 'A list of things not to forget when ' - "traveling:\n" - repeat: - - model: ibm/granite-8b-instruct-preview-4k - platform: bam - parameters: - decoding_method: greedy + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 join: with: "\n" num_iterations: 2 - 'The most important of these is ' - def: ITEM - model: ibm/granite-8b-instruct-preview-4k - platform: bam - parameters: - decoding_method: greedy + model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - . diff --git a/examples/tools/calc.pdl b/examples/tools/calc.pdl index 004bdf7f6..8101f9bcf 100644 --- a/examples/tools/calc.pdl +++ b/examples/tools/calc.pdl @@ -15,14 +15,20 @@ text: Obs: 2.869047619047619 Out of 1400 participants, 400 passed the test. What percentage is that? - Act: -- def: action - model: ibm/granite-34b-code-instruct - platform: bam +- "\n" +- def: rawAction + model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: - stop_sequences: ["\n"] + stop_sequences: "\n" +- def: action + lang: python parser: json - spec: {name: str, arguments: {expr: str}} + spec: {name: str, arguments: obj} + contribute: [context] + code: + | + result = '${ rawAction }'.replace("Act: ", "") +- "\n" - if: ${ action.name == "Calc" } then: - "Obs: " diff --git a/examples/tutorial/calling_apis.pdl b/examples/tutorial/calling_apis.pdl index 25cc6a432..66e91bd98 100644 --- a/examples/tutorial/calling_apis.pdl +++ b/examples/tutorial/calling_apis.pdl @@ -4,22 +4,18 @@ text: def: QUERY message: "Ask a query: " contribute: [] -- model: ibm/granite-34b-code-instruct - platform: bam +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 input: | + Extract the location from the question. Question: What is the weather in London? - London + Answer: London Question: What's the weather in Paris? - Paris + Answer: Paris Question: Tell me the weather in Lagos? - Lagos + Answer: Lagos Question: ${ QUERY } parameters: - stop_sequences: - - Question - - What - - '!' - include_stop_sequence: false + stop_sequences: "Question,What,!,\n" def: LOCATION contribute: [] - lang: python @@ -31,8 +27,8 @@ text: parser: json contribute: [] -- model: ibm/granite-34b-code-instruct - platform: bam +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 input: | Explain the weather from the following JSON: ${ WEATHER } + diff --git a/examples/tutorial/calling_llm.pdl b/examples/tutorial/calling_llm.pdl index 65f2352d6..d05fd0260 100644 --- a/examples/tutorial/calling_llm.pdl +++ b/examples/tutorial/calling_llm.pdl @@ -1,10 +1,7 @@ description: Hello world calling a model text: - Hello, -- model: ibm/granite-34b-code-instruct - platform: bam +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: decoding_method: greedy - stop_sequences: - - '!' - include_stop_sequence: true \ No newline at end of file + stop_sequences: '!' \ No newline at end of file diff --git a/examples/tutorial/calling_llm_with_input.pdl b/examples/tutorial/calling_llm_with_input.pdl index 0074df3d6..d7bc84faf 100644 --- a/examples/tutorial/calling_llm_with_input.pdl +++ b/examples/tutorial/calling_llm_with_input.pdl @@ -1,7 +1,6 @@ description: Hello world calling a model text: - "Hello, " -- model: ibm/granite-20b-multilingual - platform: bam +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 input: Translate the word 'world' to French diff --git a/examples/tutorial/data_block.pdl b/examples/tutorial/data_block.pdl index 54952be79..34ec5eb7d 100644 --- a/examples/tutorial/data_block.pdl +++ b/examples/tutorial/data_block.pdl @@ -6,8 +6,7 @@ defs: TRUTH: read: ./ground_truth.txt lastOf: -- model: ibm/granite-34b-code-instruct - platform: bam +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 def: EXPLANATION input: | diff --git a/examples/tutorial/function_definition.pdl b/examples/tutorial/function_definition.pdl index 37f0b3628..ccb06c493 100644 --- a/examples/tutorial/function_definition.pdl +++ b/examples/tutorial/function_definition.pdl @@ -6,10 +6,10 @@ text: language: str return: - "\nTranslate the sentence '${ sentence }' to ${ language }.\n" - - model: ibm/granite-20b-multilingual - platform: bam + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: - stop_sequences: ["\n"] + stop_sequences: "\n" + temperature: 0 - call: translate args: sentence: I love Paris! @@ -18,4 +18,4 @@ text: - call: translate args: sentence: I love Madrid! - language: Spanish \ No newline at end of file + language: Spanish diff --git a/examples/tutorial/gen-data.pdl b/examples/tutorial/gen-data.pdl index d34e9ddd5..224ee4f6c 100644 --- a/examples/tutorial/gen-data.pdl +++ b/examples/tutorial/gen-data.pdl @@ -5,8 +5,7 @@ defs: parser: yaml spec: { questions: [str], answers: [obj] } text: - - model: ibm/granite-20b-code-instruct - platform: bam + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 def: model_output spec: {name: str, age: int} input: diff --git a/examples/tutorial/grouping_definitions.pdl b/examples/tutorial/grouping_definitions.pdl index 135dae3ed..5cf70f0b8 100644 --- a/examples/tutorial/grouping_definitions.pdl +++ b/examples/tutorial/grouping_definitions.pdl @@ -6,10 +6,9 @@ defs: language: str return: - "\nTranslate the sentence '${ sentence }' to ${ language }.\n" - - model: ibm/granite-20b-multilingual - platform: bam + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: - stop_sequences: ["\n"] + stop_sequences: "\n" text: - call: translate args: diff --git a/examples/tutorial/include.pdl b/examples/tutorial/include.pdl index 80a40d99b..b76e15ef8 100644 --- a/examples/tutorial/include.pdl +++ b/examples/tutorial/include.pdl @@ -13,8 +13,7 @@ text: text: - | ${ prompt } - - model: ibm/granite-13b-chat-v2 - platform: bam + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: decoding_method: sample max_new_tokens: 512 diff --git a/examples/tutorial/model_chaining.pdl b/examples/tutorial/model_chaining.pdl index 3dfd12390..a4246d42f 100644 --- a/examples/tutorial/model_chaining.pdl +++ b/examples/tutorial/model_chaining.pdl @@ -1,14 +1,10 @@ description: Model chaining text: - Hello, -- model: ibm/granite-34b-code-instruct - platform: bam +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: - stop_sequences: ["!"] - include_stop_sequence: true + stop_sequences: "!" - "\nTranslate this to French\n" -- model: ibm/granite-20b-multilingual - platform: bam +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: - stop_sequences: ["!"] - include_stop_sequence: true + stop_sequences: "!" diff --git a/examples/tutorial/muting_block_output.pdl b/examples/tutorial/muting_block_output.pdl index f3b04f946..5e3078842 100644 --- a/examples/tutorial/muting_block_output.pdl +++ b/examples/tutorial/muting_block_output.pdl @@ -6,10 +6,9 @@ defs: language: str return: - "\nTranslate the sentence '${ sentence }' to ${ language }.\n" - - model: ibm/granite-20b-multilingual - platform: bam + - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: - stop_sequences: ["\n"] + stop_sequences: "\n" text: - call: translate contribute: [] diff --git a/examples/tutorial/variable_def_use.pdl b/examples/tutorial/variable_def_use.pdl index 1e25018b4..4f86d81b8 100644 --- a/examples/tutorial/variable_def_use.pdl +++ b/examples/tutorial/variable_def_use.pdl @@ -1,12 +1,10 @@ description: Hello world with variable def and use text: - Hello, -- model: ibm/granite-34b-code-instruct +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 def: GEN - platform: bam parameters: decoding_method: greedy - stop_sequences: - - '!' + stop_sequences: '!' include_stop_sequence: true - "\nGEN is equal to: ${ GEN }" \ No newline at end of file diff --git a/examples/weather/weather.pdl b/examples/weather/weather.pdl index 1fdd6d8de..66e91bd98 100644 --- a/examples/weather/weather.pdl +++ b/examples/weather/weather.pdl @@ -4,8 +4,7 @@ text: def: QUERY message: "Ask a query: " contribute: [] -- model: ibm/granite-8b-instruct-preview-4k - platform: bam +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 input: | Extract the location from the question. Question: What is the weather in London? @@ -16,12 +15,7 @@ text: Answer: Lagos Question: ${ QUERY } parameters: - stop_sequences: - - Question - - What - - '!' - - "\n" - include_stop_sequence: false + stop_sequences: "Question,What,!,\n" def: LOCATION contribute: [] - lang: python @@ -33,9 +27,8 @@ text: parser: json contribute: [] -- model: ibm/granite-8b-instruct-preview-4k - platform: bam +- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 input: | Explain the weather from the following JSON: ${ WEATHER } - \ No newline at end of file + From 57c1f870c9b09d1492fb1aa023b8b00d706cb9be Mon Sep 17 00:00:00 2001 From: Mandana Vaziri Date: Tue, 15 Oct 2024 12:12:24 -0400 Subject: [PATCH 16/24] examples Signed-off-by: Mandana Vaziri --- examples/arith/Arith-simple.pdl | 25 ++++++++++--------------- examples/arith/example1.txt | 18 ++++++++++++++---- examples/arith/example2.txt | 18 ++++++++++++++---- examples/arith/example3.txt | 23 +++++++++++++++++++++++ examples/notebooks/demo.ipynb | 8 ++++---- 5 files changed, 65 insertions(+), 27 deletions(-) create mode 100644 examples/arith/example3.txt diff --git a/examples/arith/Arith-simple.pdl b/examples/arith/Arith-simple.pdl index 1243ecdf9..4001c6ecf 100644 --- a/examples/arith/Arith-simple.pdl +++ b/examples/arith/Arith-simple.pdl @@ -2,6 +2,7 @@ description: Math Problems text: - read: ./example1.txt - read: ./example2.txt +- read: ./example3.txt - "\n" - | Question: Noah charges $25 for a large box and $11 for a small box. @@ -12,20 +13,14 @@ text: - def: REASON_OR_CALC model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 parameters: - stop_sequences: '{' + stop_sequences: '=' temperature: 0 - - if: ${ REASON_OR_CALC.endswith("{") } - then: - text: - - def: EXPR - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - parameters: - stop_sequences: "=,\n,Question" - include_stop_sequence: false - - '= ' - - def: RESULT - lang: python - code: result = ${ EXPR } - - '}' + - def: EXPR + model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 + parameters: + stop_sequences: "=,\n,Question" + temperature: 0 + - def: RESULT + lang: python + code: result = ${ EXPR } until: ${ "The answer is" in REASON_OR_CALC } -- "\n" \ No newline at end of file diff --git a/examples/arith/example1.txt b/examples/arith/example1.txt index e0c08f857..a53aa6887 100644 --- a/examples/arith/example1.txt +++ b/examples/arith/example1.txt @@ -5,9 +5,19 @@ 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. +8 large paintings x $60 = +{"name": "Calc", "arguments": {"expr": "8*60"}} +480 +4 small paintings x $30 = +{"name": "Calc", "arguments": {"expr": "4*30"}} +120 +So he sold +{"name": "Calc", "arguments": {"expr": "480+120"}} +600 +paintings last month. +Therefore he sold +{"name": "Calc", "arguments": {"expr": "600*2"}} +1200 +this month. The answer is $1200. diff --git a/examples/arith/example2.txt b/examples/arith/example2.txt index 60d8ad10c..72734dad9 100644 --- a/examples/arith/example2.txt +++ b/examples/arith/example2.txt @@ -5,8 +5,18 @@ 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. +5 large vases x $30 = +{"name": "Calc", "arguments": {"expr": "5*30"}} +150 +3 small vases x $10 = +{"name": "Calc", "arguments": {"expr": "3*10"}} +30 +So he sold +{"name": "Calc", "arguments": {"expr": "150+30"}} +180 +last month. +Therefore he sold +{"name": "Calc", "arguments": {"expr": "180*3"}} +540 this month. The answer is $540. + diff --git a/examples/arith/example3.txt b/examples/arith/example3.txt new file mode 100644 index 000000000..94e174053 --- /dev/null +++ b/examples/arith/example3.txt @@ -0,0 +1,23 @@ +Question: Noah charges $50 for a small vase and $100 for a large vases +Last month he sold four large vases and two small vases. +If he sold two times as much this month, how much is his sales for this month? + +Answer: Let's think step by step. +He sold 4 large vases and 2 small vases last month. +He sold two times as many this month. +4 large vases x $50 = +{"name": "Calc", "arguments": {"expr": "4*50"}} +200 +2 small vases x $100 = +{"name": "Calc", "arguments": {"expr": "2*100"}} +200 +So he sold +{"name": "Calc", "arguments": {"expr": "200+200"}} +400 +last month. +Therefore he sold +{"name": "Calc", "arguments": {"expr": "400*2"}} +800 +this month. +The answer is $800. + diff --git a/examples/notebooks/demo.ipynb b/examples/notebooks/demo.ipynb index 92aaab0a5..3796d741a 100644 --- a/examples/notebooks/demo.ipynb +++ b/examples/notebooks/demo.ipynb @@ -46,7 +46,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 70, "id": "f3c62df1-0347-4711-acd7-3892cfd5df30", "metadata": {}, "outputs": [ @@ -78,7 +78,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 71, "id": "7f6c323b-ad1a-4434-8732-bc19c5c47883", "metadata": {}, "outputs": [ @@ -164,7 +164,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 72, "id": "b61b2e25-72a4-4f70-ae83-40d77bed3f4f", "metadata": {}, "outputs": [ @@ -254,7 +254,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 73, "id": "dfef7096-b7a6-4966-8356-a306e701974b", "metadata": { "scrolled": true From 8f9ca1f7dddb967e8a1e554782178dbc63d66112 Mon Sep 17 00:00:00 2001 From: Mandana Vaziri Date: Wed, 16 Oct 2024 18:19:37 -0400 Subject: [PATCH 17/24] cleanup Signed-off-by: Mandana Vaziri --- examples/arith/Arith-simple.pdl | 26 ----- examples/arith/example1.txt | 23 ----- examples/arith/example2.txt | 22 ----- examples/arith/example3.txt | 23 ----- examples/earth/Earth.pdl | 11 --- examples/gsm8k/gsmhard-bugs.pdl | 11 --- examples/gsm8k/math-base.pdl | 10 -- examples/gsm8k/math-jinja.pdl | 91 ----------------- examples/gsm8k/math-python.pdl | 30 ------ examples/gsm8k/math.pdl | 164 ------------------------------- examples/joke/Joke.pdl | 21 ---- examples/oddOneOut/OddOneOut.pdl | 27 ----- examples/thing/Thing.pdl | 13 --- 13 files changed, 472 deletions(-) delete mode 100644 examples/arith/Arith-simple.pdl delete mode 100644 examples/arith/example1.txt delete mode 100644 examples/arith/example2.txt delete mode 100644 examples/arith/example3.txt delete mode 100644 examples/earth/Earth.pdl delete mode 100644 examples/gsm8k/gsmhard-bugs.pdl delete mode 100644 examples/gsm8k/math-base.pdl delete mode 100644 examples/gsm8k/math-jinja.pdl delete mode 100644 examples/gsm8k/math-python.pdl delete mode 100644 examples/gsm8k/math.pdl delete mode 100644 examples/joke/Joke.pdl delete mode 100644 examples/oddOneOut/OddOneOut.pdl delete mode 100644 examples/thing/Thing.pdl diff --git a/examples/arith/Arith-simple.pdl b/examples/arith/Arith-simple.pdl deleted file mode 100644 index 4001c6ecf..000000000 --- a/examples/arith/Arith-simple.pdl +++ /dev/null @@ -1,26 +0,0 @@ -description: Math Problems -text: -- read: ./example1.txt -- read: ./example2.txt -- read: ./example3.txt -- "\n" -- | - Question: Noah charges $25 for a large box and $11 for a small box. - Last month he sold four large boxes and two small boxes. - If he sold three times as much this month, how much is his sales for this month? -- repeat: - text: - - def: REASON_OR_CALC - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - parameters: - stop_sequences: '=' - temperature: 0 - - def: EXPR - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - parameters: - stop_sequences: "=,\n,Question" - temperature: 0 - - def: RESULT - lang: python - code: result = ${ EXPR } - until: ${ "The answer is" in REASON_OR_CALC } diff --git a/examples/arith/example1.txt b/examples/arith/example1.txt deleted file mode 100644 index a53aa6887..000000000 --- a/examples/arith/example1.txt +++ /dev/null @@ -1,23 +0,0 @@ -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 = -{"name": "Calc", "arguments": {"expr": "8*60"}} -480 -4 small paintings x $30 = -{"name": "Calc", "arguments": {"expr": "4*30"}} -120 -So he sold -{"name": "Calc", "arguments": {"expr": "480+120"}} -600 -paintings last month. -Therefore he sold -{"name": "Calc", "arguments": {"expr": "600*2"}} -1200 -this month. -The answer is $1200. - diff --git a/examples/arith/example2.txt b/examples/arith/example2.txt deleted file mode 100644 index 72734dad9..000000000 --- a/examples/arith/example2.txt +++ /dev/null @@ -1,22 +0,0 @@ -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 = -{"name": "Calc", "arguments": {"expr": "5*30"}} -150 -3 small vases x $10 = -{"name": "Calc", "arguments": {"expr": "3*10"}} -30 -So he sold -{"name": "Calc", "arguments": {"expr": "150+30"}} -180 -last month. -Therefore he sold -{"name": "Calc", "arguments": {"expr": "180*3"}} -540 this month. -The answer is $540. - diff --git a/examples/arith/example3.txt b/examples/arith/example3.txt deleted file mode 100644 index 94e174053..000000000 --- a/examples/arith/example3.txt +++ /dev/null @@ -1,23 +0,0 @@ -Question: Noah charges $50 for a small vase and $100 for a large vases -Last month he sold four large vases and two small vases. -If he sold two times as much this month, how much is his sales for this month? - -Answer: Let's think step by step. -He sold 4 large vases and 2 small vases last month. -He sold two times as many this month. -4 large vases x $50 = -{"name": "Calc", "arguments": {"expr": "4*50"}} -200 -2 small vases x $100 = -{"name": "Calc", "arguments": {"expr": "2*100"}} -200 -So he sold -{"name": "Calc", "arguments": {"expr": "200+200"}} -400 -last month. -Therefore he sold -{"name": "Calc", "arguments": {"expr": "400*2"}} -800 -this month. -The answer is $800. - diff --git a/examples/earth/Earth.pdl b/examples/earth/Earth.pdl deleted file mode 100644 index 85fdacc95..000000000 --- a/examples/earth/Earth.pdl +++ /dev/null @@ -1,11 +0,0 @@ -description: Earth circumference question -text: -- 'What is the circumference of the earth? I believe the best person to answer this question is ' -- def: EXPERT - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - parameters: - stop_sequences: "." -- '. Indeed, ' -- get: EXPERT -- ' addressed this question: ' -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 \ No newline at end of file diff --git a/examples/gsm8k/gsmhard-bugs.pdl b/examples/gsm8k/gsmhard-bugs.pdl deleted file mode 100644 index a4daff720..000000000 --- a/examples/gsm8k/gsmhard-bugs.pdl +++ /dev/null @@ -1,11 +0,0 @@ -description: GSM Hard Bug Finder -text: -- ${ question } -- "\n" -- "Does the following code accurately solve this problem?\n\n" -- ${ code } -- model: meta-llama/llama-3-70b-instruct - platform: bam - parameters: - stop_sequences: ["def"] - include_stop_sequence: false \ No newline at end of file diff --git a/examples/gsm8k/math-base.pdl b/examples/gsm8k/math-base.pdl deleted file mode 100644 index 76fd03792..000000000 --- a/examples/gsm8k/math-base.pdl +++ /dev/null @@ -1,10 +0,0 @@ -description: math problem -text: - -- model: meta-llama/llama-3-70b-instruct - platform: bam - def: PDL - input: "Question: ${ question }" - parameters: - stop_sequences: ["Question"] - include_stop_sequence: false diff --git a/examples/gsm8k/math-jinja.pdl b/examples/gsm8k/math-jinja.pdl deleted file mode 100644 index 0ccccf17e..000000000 --- a/examples/gsm8k/math-jinja.pdl +++ /dev/null @@ -1,91 +0,0 @@ -description: math problem -text: - -- model: meta-llama/llama-3-70b-instruct - def: PDL - input: - text: - - | - Question: A deep-sea monster rises from the waters once every hundred years to feast on a ship and sate its hunger. - Over three hundred years, it has consumed 847 people. Ships have been built larger over time, - so each new ship has twice as many people as the last ship. How many people were on the ship the - monster ate in the first hundred years? - - Answer: - ``` - description: my answer - text: - - Let's call the number of people on the first ship x. - - lang: python - def: equation - code: - - | - from sympy import * - x = symbols('x') - result = x + 2*x + 4*x - - "The equation is ${ equation } = 847.\n" - - "Solving for x, we get " - - lang: python - def: RESULT - code: - - | - from sympy import * - x = symbols('x') - result = solve(${ equation } - 847, x)[0] - - "\nThe answer is ${RESULT}." - - lang: python - def: FINAL - code: - - | - result = ${ RESULT } - - "\n#### " - - ${ FINAL } - ``` - Question: Roger has 5 tennis balls. He buys 2 more cans of tennis balls. - Each can has 3 tennis balls. How many tennis balls does he have now? - - Answer: - ``` - description: my answer - text: - - Roger started with 5 tennis balls - - def: tennis_balls - data: 5 - - "\n2 cans of 3 tennis balls each is\n" - - def: bought_balls - data: ${ 2 * 3 } - - "\ntennis balls. The answer is\n" - - def: RESULT - data: ${ tennis_balls + bought_balls } - - lang: python - def: FINAL - code: - - | - result = ${ RESULT } - - "\n#### " - - ${ FINAL } - ``` - - - - - "Question: ${ question }" - parameters: - stop_sequences: ["Question"] - include_stop_sequence: false -- lang: python - code: | - from pdl import pdl_ast, pdl_interpreter - from pdl.pdl_ast import Program - from pdl.pdl_interpreter import process_prog - from pdl.pdl_interpreter import InterpreterState - from pdl.pdl_interpreter import empty_scope - import re - import yaml - s = """'${ PDL }'""" - pdl = s.split("```")[1] - obj = yaml.safe_load(pdl) - state = InterpreterState() - data = Program.model_validate(obj) - - result, _, _, _ = process_prog(state, empty_scope, data) - def: RESULT diff --git a/examples/gsm8k/math-python.pdl b/examples/gsm8k/math-python.pdl deleted file mode 100644 index cae793a19..000000000 --- a/examples/gsm8k/math-python.pdl +++ /dev/null @@ -1,30 +0,0 @@ -description: math problem -text: - -- model: meta-llama/llama-3-70b-instruct - platform: bam - def: PROGRAM - input: - text: - - | - - Question: Roger has 5 tennis balls. He buys 2 more cans of tennis balls. - Each can has 3 tennis balls. How many tennis balls does he have now? - - Answer: - ``` - # Roger started with 5 tennis balls - tennis_balls = 5 - # 2 cans of 3 tennis balls each is - bought_balls = 2 * 3 - # tennis balls. The answer is - result = tennis_balls + bought_balls - print("#### " + str(result)) - ``` - - - - - "Question: ${ question }" - parameters: - stop_sequences: ["Question"] - include_stop_sequence: false diff --git a/examples/gsm8k/math.pdl b/examples/gsm8k/math.pdl deleted file mode 100644 index b2e52ee78..000000000 --- a/examples/gsm8k/math.pdl +++ /dev/null @@ -1,164 +0,0 @@ -description: math problem -text: - -- model: meta-llama/llama-3-70b-instruct - platform: bam - def: PDL - input: - text: - - | - Question: A deep-sea monster rises from the waters once every hundred years to feast on a ship and sate its hunger. - Over three hundred years, it has consumed 847 people. Ships have been built larger over time, - so each new ship has twice as many people as the last ship. How many people were on the ship the - monster ate in the first hundred years? - - Answer: - ``` - description: my answer - text: - - Let's call the number of people on the first ship x. - - lang: python - def: equation - code: - - | - from sympy import * - x = symbols('x') - result = x + 2*x + 4*x - - "The equation is ${ '${' } equation ${ '}' } = 847.\n" - - "Solving for x, we get " - - lang: python - def: RESULT - code: - - | - from sympy import * - x = symbols('x') - result = solve(${ '${' } equation ${ '}' } - 847, x)[0] - - "\nThe answer is ${ '${' } RESULT ${ '}' }." - - lang: python - def: FINAL - code: - - | - result = ${ '${' } RESULT ${ '}' } - - "\n#### " - - ${ '${' } FINAL ${ '}' }" - ``` - Question: Roger has 5 tennis balls. He buys 2 more cans of tennis balls. - Each can has 3 tennis balls. How many tennis balls does he have now? - - Answer: - ``` - description: my answer - text: - - Roger started with 5 tennis balls - - lang: python - def: tennis_balls - code: - - | - result = 5 - - "\n2 cans of 3 tennis balls each is\n" - - lang: python - def: bought_balls - code: - - | - result = 2 * 3 - - "\ntennis balls. The answer is\n" - - lang: python - def: RESULT - code: - - | - result = ${ '${' } tennis_balls ${ '}' } + ${ '${' } bought_balls ${ '}' } - - lang: python - def: FINAL - code: - - | - result = ${ '${' } RESULT ${ '}' } - - "\n#### " - - "${ '${' } FINAL ${ '}' }" - ``` - - Question: Betty is saving money for a new wallet which costs $100. Betty has only half of the money she needs. - Her parents decided to give her $15 for that purpose, - and her grandparents twice as much as her parents. How much more money does Betty need to buy the wallet? - - Answer: - ``` - description: my answer - text: - - Betty needs $100 for the wallet. - - lang: python - def: cost - code: - - | - result = 100 - - "Betty already has:\n" - - lang: python - def: betty_already_has - code: - - | - result = ${ '${' } cost ${ '}' } / 2 - - "\nHalf of the money she needs is\n" - - lang: python - def: half_cost - code: - - | - result = ${ '${' } cost ${ '}' } / 2 - - "\nBetty's parents gave her:\n" - - lang: python - def: money_from_parents - code: - - | - result = 15 - - "\nBetty's grandparents gave her:\n" - - lang: python - def: money_from_grandparents - code: - - | - result = ${ '${' } money_from_parents ${ '}' } * 2 - - "\nSo Betty has:\n" - - lang: python - def: money_betty_has - code: - - | - result = ${ '${' } betty_already_has ${ '}' } + ${ '${' } money_from_parents ${ '}' } + ${ '${' } money_from_grandparents ${ '}' } - - "\nTo buy the wallet, Betty needs\n" - - lang: python - def: money_needed - code: - - | - result = ${ '${' } cost ${ '}' } - ${ '${' } money_betty_has ${ '}' } - - "\nThe answer is ${ '${' } money_needed ${ '}' }." - - lang: python - def: FINAL - code: - - | - result = ${ '${' } money_needed ${ '}' } - - "\n#### " - - "${ '${' } FINAL ${ '}' }" - ``` - - - - "Question: ${ question }" - - If numbers are very large, do not modify them. - - Please pay attention when using the sympy library to import and use it correctly. - - The answer final line should be ${ '${' } FINAL ${ '}' }. - - parameters: - stop_sequences: ["Question"] - include_stop_sequence: false -- lang: python - code: | - from pdl import pdl_ast, pdl_interpreter - from pdl.pdl_ast import Program - from pdl.pdl_interpreter import process_prog - from pdl.pdl_interpreter import InterpreterState - from pdl.pdl_interpreter import empty_scope - import re - import yaml - s = """'${ PDL }'""" - pdl = s.split("```")[1] - obj = yaml.safe_load(pdl) - state = InterpreterState() - data = Program.model_validate(obj) - - result, _, _, _ = process_prog(state, empty_scope, data) - def: RESULT diff --git a/examples/joke/Joke.pdl b/examples/joke/Joke.pdl deleted file mode 100644 index 0501416f2..000000000 --- a/examples/joke/Joke.pdl +++ /dev/null @@ -1,21 +0,0 @@ -description: Joke example -text: -- | - A list of good dad jokes. A indicates the punchline - Q: How does a penguin build its house? - A: Igloos it together. END - Q: Which knight invented King Arthur''s Round Table? - A: Sir Cumference. END -- repeat: - text: - - 'Q: ' - - def: JOKE - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - parameters: - stop_sequences: "?,\n" - - "\nA: " - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - parameters: - stop_sequences: "END,\n" - - "\n" - num_iterations: 2 diff --git a/examples/oddOneOut/OddOneOut.pdl b/examples/oddOneOut/OddOneOut.pdl deleted file mode 100644 index 5f0edc85a..000000000 --- a/examples/oddOneOut/OddOneOut.pdl +++ /dev/null @@ -1,27 +0,0 @@ -description: Odd one out -text: -- "Question: Pick the odd word out:\n" -- "skirt, dress, pen, jacket.\n" -- "Reasoning: skirt is clothing, dress is clothing, pen is an object, jacket is clothing.\n" -- "Answer: So the odd one is pen.\n\n" -- "Question: Pick the odd word out:\n" -- "Spain, France, German, England, Singapore.\n" -- "Reasoning: Spain is a country, France is a country, German is a language, ...\n" -- "Answer: So the odd one is German.\n\n" -- repeat: - text: - - "Question: Pick the odd word out:\n" - - def: OPTIONS - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - parameters: - stop_sequences: "." - - "\nReasoning:\n" - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - parameters: - stop_sequences: "Pick the odd word,\n,So the odd one,." - - "\nResult:\n" - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - parameters: - stop_sequences: "Pick the odd word" - - "\n\n" - num_iterations: 2 diff --git a/examples/thing/Thing.pdl b/examples/thing/Thing.pdl deleted file mode 100644 index 4786ee094..000000000 --- a/examples/thing/Thing.pdl +++ /dev/null @@ -1,13 +0,0 @@ -description: Things not to forget -text: -- 'A list of things not to forget when ' -- "traveling:\n" -- repeat: - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - join: - with: "\n" - num_iterations: 2 -- 'The most important of these is ' -- def: ITEM - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 -- . From 40c28e23da64f2da735b7519a7e66afbb72a2175 Mon Sep 17 00:00:00 2001 From: Mandana Vaziri Date: Wed, 16 Oct 2024 21:07:01 -0400 Subject: [PATCH 18/24] examples Signed-off-by: Mandana Vaziri --- README.md | 10 +- docs/README.md | 8 +- examples/chatbot/chatbot.pdl | 2 +- examples/cldk/cldk-assistant.pdl | 221 +++++++------- examples/code/code-eval.pdl | 2 +- examples/code/code-json.pdl | 2 +- examples/code/code.pdl | 2 +- examples/demo/1-gen-data.pdl | 2 +- examples/demo/3-weather.pdl | 4 +- examples/demo/4-translator.pdl | 4 +- examples/fibonacci/fib.pdl | 4 +- examples/granite/multi_round_chat.pdl | 8 +- examples/granite/single_round_chat.pdl | 10 +- examples/hello/hello-def-use.pdl | 2 +- examples/hello/hello-model-chaining.pdl | 4 +- examples/hello/hello-model-input.pdl | 2 +- examples/hello/hello-parser-json.pdl | 4 +- examples/hello/hello-parser-regex.pdl | 2 +- examples/hello/hello-roles-array.pdl | 2 +- examples/hello/hello-type.pdl | 13 +- examples/hello/hello.pdl | 2 +- examples/hello/test.pdl | 7 - examples/meta/pdl-gen.pdl | 295 ------------------- examples/rag/rag.pdl | 2 +- examples/react/demo.pdl | 4 +- examples/react/demonstrations.txt | 7 +- examples/react/multi-agent.pdl | 2 +- examples/react/react_call.pdl | 4 +- examples/react/react_fun.pdl | 7 + examples/react/wikipedia.pdl | 4 +- examples/talk/1-hello.pdl | 2 +- examples/talk/2-model-chaining.pdl | 4 +- examples/talk/3-def-use.pdl | 4 +- examples/talk/4-function.pdl | 2 +- examples/talk/5-code-eval.pdl | 2 +- examples/talk/6-code-json.pdl | 2 +- examples/talk/7-chatbot-roles.pdl | 2 +- examples/talk/8-tools.pdl | 2 +- examples/talk/9-react.pdl | 4 +- examples/tools/calc.pdl | 2 +- examples/tutorial/calling_apis.pdl | 4 +- examples/tutorial/calling_llm.pdl | 2 +- examples/tutorial/calling_llm_with_input.pdl | 2 +- examples/tutorial/data_block.pdl | 2 +- examples/tutorial/function_definition.pdl | 2 +- examples/tutorial/gen-data.pdl | 8 +- examples/tutorial/grouping_definitions.pdl | 2 +- examples/tutorial/include.pdl | 4 +- examples/tutorial/model_chaining.pdl | 4 +- examples/tutorial/muting_block_output.pdl | 2 +- examples/tutorial/variable_def_use.pdl | 2 +- examples/weather/weather.pdl | 4 +- 52 files changed, 200 insertions(+), 506 deletions(-) delete mode 100644 examples/hello/test.pdl delete mode 100644 examples/meta/pdl-gen.pdl diff --git a/README.md b/README.md index 8fe245290..c58b92537 100644 --- a/README.md +++ b/README.md @@ -44,8 +44,12 @@ pip install 'prompt-declaration-language[examples]' pip install 'prompt-declaration-language[docs]' ``` -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: -- `WATSONX_URL`, the API url (set to `https://{region}.ml.cloud.ibm.com`) of your watsonx instance +In order to run the examples that use foundation models hosted on [Replicate](https://replicate.com/) via LiteLLM, you need to create a free account +on Replicate, get an API key and store it in the environment variable: +- `REPLICATE_API_TOKEN` + +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: +- `WATSONX_URL`, the API url (set to `https://{region}.ml.cloud.ibm.com`) of your WatsonX instance - `WATSONX_APIKEY`, the API key (see information on [key creation](https://cloud.ibm.com/docs/account?topic=account-userapikey&interface=ui#create_user_key)) - `WATSONX_PROJECT_ID`, the project hosting the resources (see information about [project creation](https://www.ibm.com/docs/en/watsonx/saas?topic=projects-creating-project) and [finding project ID](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-project-id.html?context=wx)). @@ -78,8 +82,6 @@ you can use the `--sandbox` flag which runs the interpreter in a docker containe and all code is executed locally. To use the `--sandbox` flag, you need to have a docker daemon running, such as [Rancher Desktop](https://rancherdesktop.io). -Note that the `--sandbox` flag is currently not available to BAM users. - 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 useful for debugging. diff --git a/docs/README.md b/docs/README.md index e673543e5..4bdd5075f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -49,8 +49,12 @@ pip install 'prompt-declaration-language[examples]' pip install 'prompt-declaration-language[docs]' ``` -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: -- `WATSONX_URL`, the API url (set to `https://{region}.ml.cloud.ibm.com`) of your watsonx instance +In order to run the examples that use foundation models hosted on [Replicate](https://replicate.com/) via LiteLLM, you need to create a free account +on Replicate, get an API key and store it in the environment variable: +- `REPLICATE_API_TOKEN` + +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: +- `WATSONX_URL`, the API url (set to `https://{region}.ml.cloud.ibm.com`) of your WatsonX instance - `WATSONX_APIKEY`, the API key (see information on [key creation](https://cloud.ibm.com/docs/account?topic=account-userapikey&interface=ui#create_user_key)) - `WATSONX_PROJECT_ID`, the project hosting the resources (see information about [project creation](https://www.ibm.com/docs/en/watsonx/saas?topic=projects-creating-project) and [finding project ID](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-project-id.html?context=wx)). diff --git a/examples/chatbot/chatbot.pdl b/examples/chatbot/chatbot.pdl index cbea4c720..02e980838 100644 --- a/examples/chatbot/chatbot.pdl +++ b/examples/chatbot/chatbot.pdl @@ -5,7 +5,7 @@ text: contribute: [context] - repeat: text: - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 + - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e - read: def: eval message: "\nIs this a good answer[yes/no]?\n" diff --git a/examples/cldk/cldk-assistant.pdl b/examples/cldk/cldk-assistant.pdl index 05c739064..90b14a227 100644 --- a/examples/cldk/cldk-assistant.pdl +++ b/examples/cldk/cldk-assistant.pdl @@ -14,11 +14,11 @@ text: from cldk import CLDK from cldk.models.java.models import * - # Initialize the Codellm-DevKit object with the project directory, language, and backend. + # Initialize the Codellm-DevKit object with the project directory, langguage, and backend. cldk = CLDK("java") cldk_state = cldk.analysis( project_path="${ project }", # Change this to the path of the project you want to analyze. - # language="java", # The language of the project. + # langguage="java", # The langguage of the project. # backend="codeanalyzer", # The backend to use for the analysis. # analysis_db="/tmp", # A temporary directory to store the analysis results. # sdg=True, # Generate the System Dependence Graph (SDG) for the project. @@ -35,130 +35,121 @@ text: - "\n***Generating PDL code for your query:\n" - if: ${ query != 'quit'} then: - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - def: PDL - input: - - | - Question: What are all the classes? - Answer: - ``` - text: - - lan: python - code: + text: + - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + def: PDL + input: - | - classes = PDL_SESSION.cldk_state.get_classes().keys() - result = ", ".join(classes) - ``` + Question: What are all the classes? + Answer: + ``` + text: + - lang: python + code: + - | + classes = PDL_SESSION.cldk_state.get_classes().keys() + result = ", ".join(classes) + ``` - Question: What are all the constructors of class org.ibm.App? - Answer: - ``` - text: - - lan: python - code: - - | - constructors = PDL_SESSION.cldk_state.get_constructors("org.ibm.App") - result = ", ".join(constructors) - ``` + Question: What are all the constructors of class org.ibm.App? + Answer: + ``` + text: + - lang: python + code: + - | + constructors = PDL_SESSION.cldk_state.get_constructors("org.ibm.App") + result = ", ".join(constructors) + ``` - Question: What are all the fields of class org.ibm.App? - Answer: - ``` - text: - - lan: python - code: - - | - fields = PDL_SESSION.cldk_state.get_fields("org.ibm.App") - names = sum([f.variables for f in fields], []) - result = ", ".join(names) - ``` + Question: What are all the fields of class org.ibm.App? + Answer: + ``` + text: + - lang: python + code: + - | + fields = PDL_SESSION.cldk_state.get_fields("org.ibm.App") + names = sum([f.variables for f in fields], []) + result = ", ".join(names) + ``` - Question: What are all the methods of class org.ibm.App? - Answer: - ``` - text: - - lan: python - code: - - | - methods = PDL_SESSION.cldk_state.get_methods_in_class("org.ibm.App") - result = ", ".join(methods) - ``` + Question: What are all the methods of class org.ibm.App? + Answer: + ``` + text: + - lang: python + code: + - | + methods = PDL_SESSION.cldk_state.get_methods_in_class("org.ibm.App") + result = ", ".join(methods) + ``` - Question: Show me the call graph of class "org.ibm.App" - Answer: - ``` - text: - - lan: python - code: - - | - graph = PDL_SESSION.cldk_state.get_class_call_graph("org.ibm.App", method_name=None) - result = graph - ``` + Question: Show me the call graph of class "org.ibm.App" + Answer: + ``` + text: + - lang: python + code: + - | + graph = PDL_SESSION.cldk_state.get_class_call_graph("org.ibm.App", method_name=None) + result = graph + ``` - Question: What is the code of method Foo(string) of class org.ibm.App? - Answer: - ``` - text: - - lan: python - code: - - | - method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") - result = method.code - ``` + Question: What is the code of method Foo(string) of class org.ibm.App? + Answer: + ``` + text: + - lang: python + code: + - | + method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") + result = method.code + ``` - Question: Generate a summary for method Foo(string) of class org.ibm.App - Answer: - ``` - text: - - lan: python - code: - - | - method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") - result = method - - "\n\nGenerate a summary of method Foo\n\n" - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - ``` + Question: Generate a summary for method Foo(string) of class org.ibm.App + Answer: + ``` + text: + - lang: python + code: + - | + method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") + result = method + - "\n\nGenerate a summary of method Foo\n\n" + - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + ``` - Question: Generate a different comment for method Foo(string) in class org.ibm.App? - Answer: - ``` - text: - - lan: python - code: - - | - method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") - result = method - - "\n\nGenerate a different comment for method Foo(string)\n\n" - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - ``` + Question: Generate a different comment for method Foo(string) in class org.ibm.App? + Answer: + ``` + text: + - lang: python + code: + - | + method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") + result = method + - "\n\nGenerate a different comment for method Foo(string)\n\n" + - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + ``` - If the query contains something about a field be sure to call a model. - - Question: ${ query } + If the query contains something about a field be sure to call a model. + + Question: ${ query } - parameters: - stop_sequences: "Question" - include_stop_sequence: false - - "\n\n***Executing the above PDL code:\n\n" - - lang: python - contribute: [result] - code: | - from pdl import pdl_ast, pdl_interpreter - from pdl.pdl_ast import Program - from pdl.pdl_interpreter import process_prog - from pdl.pdl_interpreter import InterpreterState - from pdl.pdl_interpreter import empty_scope - import re - import yaml - s = """'${ PDL }'""" - print(s) - pdl = s.split("```")[1] - obj = yaml.safe_load(pdl) - state = InterpreterState() - data = Program.model_validate(obj) - - result, _, _, _ = process_prog(state, empty_scope, data) + parameters: + stop_sequences: "Question" + include_stop_sequence: false + - "\n\n***Executing the above PDL code:\n\n" + - lang: python + contribute: [result] + code: | + from pdl.pdl import exec_str + s = """${ PDL }""" + pdl = s.split("```")[1] + result = exec_str(pdl) + until: ${ query == 'quit' } diff --git a/examples/code/code-eval.pdl b/examples/code/code-eval.pdl index f92c27f06..074ce0081 100644 --- a/examples/code/code-eval.pdl +++ b/examples/code/code-eval.pdl @@ -7,7 +7,7 @@ defs: read: ./ground_truth.txt text: - "\n${ CODE.source_code }\n" -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e def: EXPLANATION input: | Here is some info about the location of the function in the repo. diff --git a/examples/code/code-json.pdl b/examples/code/code-json.pdl index 58d778c06..328aa8387 100644 --- a/examples/code/code-json.pdl +++ b/examples/code/code-json.pdl @@ -6,7 +6,7 @@ defs: TRUTH: read: ./ground_truth.txt text: -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e def: EXPLANATION contribute: [] input: diff --git a/examples/code/code.pdl b/examples/code/code.pdl index 86df57407..d1a3320de 100644 --- a/examples/code/code.pdl +++ b/examples/code/code.pdl @@ -5,7 +5,7 @@ defs: parser: yaml text: - "\n${ CODE.source_code }\n" -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e input: - | Here is some info about the location of the function in the repo. diff --git a/examples/demo/1-gen-data.pdl b/examples/demo/1-gen-data.pdl index 73b3697ae..3b7cad2cf 100644 --- a/examples/demo/1-gen-data.pdl +++ b/examples/demo/1-gen-data.pdl @@ -5,7 +5,7 @@ defs: parser: yaml spec: { questions: [str], answers: [obj] } text: - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 + - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e def: model_output spec: {name: str, age: int} input: diff --git a/examples/demo/3-weather.pdl b/examples/demo/3-weather.pdl index 66e91bd98..37d1d790b 100644 --- a/examples/demo/3-weather.pdl +++ b/examples/demo/3-weather.pdl @@ -4,7 +4,7 @@ text: def: QUERY message: "Ask a query: " contribute: [] -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e input: | Extract the location from the question. Question: What is the weather in London? @@ -27,7 +27,7 @@ text: parser: json contribute: [] -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e input: | Explain the weather from the following JSON: ${ WEATHER } diff --git a/examples/demo/4-translator.pdl b/examples/demo/4-translator.pdl index 222b0b9ce..51517d42a 100644 --- a/examples/demo/4-translator.pdl +++ b/examples/demo/4-translator.pdl @@ -1,7 +1,7 @@ description: PDL program text: - "What is APR?\n" -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e - repeat: text: - read: @@ -11,5 +11,5 @@ text: then: text: - "\n\nTranslate the above to ${ language }\n" - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 + - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e until: ${ language == 'stop' } diff --git a/examples/fibonacci/fib.pdl b/examples/fibonacci/fib.pdl index b27eec7a9..9d9fd6d5a 100644 --- a/examples/fibonacci/fib.pdl +++ b/examples/fibonacci/fib.pdl @@ -1,7 +1,7 @@ description: Fibonacci text: - def: CODE - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 + model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e input: "Write a Python function to compute the Fibonacci sequence. Do not include a doc string.\n\n" parameters: temperature: 0 @@ -26,5 +26,5 @@ text: contribute: [] - 'The result is: ${ RESULT }' - "\n\nExplain what the above code does and what the result means\n\n" -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e \ No newline at end of file diff --git a/examples/granite/multi_round_chat.pdl b/examples/granite/multi_round_chat.pdl index d65b1514a..bb3529cc2 100644 --- a/examples/granite/multi_round_chat.pdl +++ b/examples/granite/multi_round_chat.pdl @@ -6,16 +6,14 @@ text: def: prompts spec: {prompts: [str]} contribute: [] -- ${ SYSTEM_CONTENT_CHAT } - for: prompt: ${ prompts.prompts } repeat: text: - | + ${ prompt } - - model: ibm/granite-13b-chat-v2 - platform: bam + - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: - decoding_method: sample - max_new_tokens: 512 + temperature: 0 role: user \ No newline at end of file diff --git a/examples/granite/single_round_chat.pdl b/examples/granite/single_round_chat.pdl index a1b4e2686..caa975f85 100644 --- a/examples/granite/single_round_chat.pdl +++ b/examples/granite/single_round_chat.pdl @@ -1,12 +1,8 @@ description: Granite Single-Round Chat text: - include: ./granite_defs.pdl -- role: system - content: ${ SYSTEM_CONTENT_CHAT } -- ${ PROMPT } -- model: ibm/granite-13b-chat-v2 - platform: bam +- "${ PROMPT }\n" +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: - decoding_method: sample - max_new_tokens: 512 + temperature: 0 role: user diff --git a/examples/hello/hello-def-use.pdl b/examples/hello/hello-def-use.pdl index bee6b6cb3..a5e4e29e7 100644 --- a/examples/hello/hello-def-use.pdl +++ b/examples/hello/hello-def-use.pdl @@ -1,7 +1,7 @@ description: Hello world with variable use text: - Hello, -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: decoding_method: greedy stop_sequences: '!' diff --git a/examples/hello/hello-model-chaining.pdl b/examples/hello/hello-model-chaining.pdl index 7db8e698d..020e16368 100644 --- a/examples/hello/hello-model-chaining.pdl +++ b/examples/hello/hello-model-chaining.pdl @@ -1,7 +1,7 @@ description: Hello world showing model chaining text: - Hello, -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: decoding_method: greedy stop_sequences: '!' @@ -10,7 +10,7 @@ text: ! Who is${ NAME }? - "\n" -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: decoding_method: greedy stop_sequences: '.' diff --git a/examples/hello/hello-model-input.pdl b/examples/hello/hello-model-input.pdl index 3ebc842f1..16d21f3fb 100644 --- a/examples/hello/hello-model-input.pdl +++ b/examples/hello/hello-model-input.pdl @@ -1,6 +1,6 @@ description: Hello world with model input text: -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e input: "Hello," parameters: stop_sequences: '!' diff --git a/examples/hello/hello-parser-json.pdl b/examples/hello/hello-parser-json.pdl index a14d5112f..8dcd9c454 100644 --- a/examples/hello/hello-parser-json.pdl +++ b/examples/hello/hello-parser-json.pdl @@ -5,7 +5,7 @@ defs: parser: yaml spec: { questions: [str], answers: [obj] } text: - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 + - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e def: model_output spec: {name: str, age: int} input: @@ -19,7 +19,7 @@ text: ${ answer } - > Question: Create a JSON object with fields 'name' and 'age' - and set them appropriately. + and set them appropriately. Write the age in letters. parser: yaml parameters: stop_sequences: "\n" diff --git a/examples/hello/hello-parser-regex.pdl b/examples/hello/hello-parser-regex.pdl index ede4d8474..c9f724d8f 100644 --- a/examples/hello/hello-parser-regex.pdl +++ b/examples/hello/hello-parser-regex.pdl @@ -1,6 +1,6 @@ description: Hello world with parser using regex text: -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e input: "Hello," parameters: stop_sequences: '!' diff --git a/examples/hello/hello-roles-array.pdl b/examples/hello/hello-roles-array.pdl index 1c3be4509..63375c222 100644 --- a/examples/hello/hello-roles-array.pdl +++ b/examples/hello/hello-roles-array.pdl @@ -7,6 +7,6 @@ text: - role: user content: Write a Python function that implement merge sort. contribute: [] -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e input: ${ prompt } diff --git a/examples/hello/hello-type.pdl b/examples/hello/hello-type.pdl index 1ad94085d..69563ed3f 100644 --- a/examples/hello/hello-type.pdl +++ b/examples/hello/hello-type.pdl @@ -1,10 +1,7 @@ description: Hello world with type specification text: -- Hello, -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - def: GEN - parameters: - stop_sequences: "!" +- def: GEN + text: "What is the meaning of life" - def: translate function: sentence: str @@ -12,16 +9,16 @@ text: spec: int return: - "\nTranslate the sentence '${ sentence }' to ${ language }\n" - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 + - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: stop_sequences: "\n" - call: translate spec: str args: - sentence: Hello,${ GEN } + sentence: ${ GEN } language: French - call: translate args: - sentence: Bye,${ GEN } + sentence: ${ GEN } language: Spanish diff --git a/examples/hello/hello.pdl b/examples/hello/hello.pdl index ef1036d6a..43b793206 100644 --- a/examples/hello/hello.pdl +++ b/examples/hello/hello.pdl @@ -1,4 +1,4 @@ description: Hello world text: - "Hello\n" -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e diff --git a/examples/hello/test.pdl b/examples/hello/test.pdl deleted file mode 100644 index 1af38fdda..000000000 --- a/examples/hello/test.pdl +++ /dev/null @@ -1,7 +0,0 @@ -description: Hello world with iteration -text: -- Hello, world! -- "\n" -- repeat: - "This is your first PDL program\n" - num_iterations: 3 diff --git a/examples/meta/pdl-gen.pdl b/examples/meta/pdl-gen.pdl deleted file mode 100644 index 68e2d748a..000000000 --- a/examples/meta/pdl-gen.pdl +++ /dev/null @@ -1,295 +0,0 @@ -description: Teaching PDL -text: -- lang: python - code: - - | - print("Enter/Paste your content. Ctrl-D to save it.") - contents = [] - while True: - try: - line = input() - except EOFError: - break - contents.append(line + "\n") - result = ''.join(contents) - def: QUERY - contribute: [] -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - input: - text: - - |- - Question: Write the following prompts in PDL: - Hello world! - This is your first prompt descriptor! - - Answer: - ``` - description: Hello world! - text: - - "Hello, world!\n" - - "This is your first prompt descriptor!\n" - ``` - - Question: Turn the code into PDL: - contents = [] - while True: - try: - line = input() - except EOFError: - break - contents.append(line + "\n") - result = ''.join(contents) - - Answer: - ``` - description: Example of PDL code block - text: - - lang: python - code: - - | - contents = [] - while True: - try: - line = input() - except EOFError: - break - contents.append(line + "\n") - result = ''.join(contents) - ``` - - Question: Write a PDL script with the following text: - Hello world! - This is your first prompt descriptor! - - and with the following nested block that repeats 3 times: - This sentence repeats! - - Answer: - ``` - description: Hello world with a nested block - text: - - | - Hello, world! - This is your first prompt descriptor! - - text: - - | - This sentence repeats! - repeats: 3 - ``` - - Question: Write a PDL script with the following text: - Hello world! - This is your first prompt descriptor! - - and with the following nested block that repeats 4 times: - This sentence repeats! - - Answer: - ``` - description: Hello world with a nested block - text: - - | - Hello, world! - This is your first prompt descriptor! - - text: - - | - This sentence repeats! - repeats: 4 - ``` - - Question: Write a PDL script that makes a call to a granite model - - Answer: - ``` - description: PDL with model call - text: - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - ``` - - Question: Write a PDL script that makes a call to a model with stop sequence '!' and stop sequences included - - Answer: - ``` - description: PDL with model call - text: - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - ``` - - - Question: Write a PDL script that makes a call to a flan model - - Answer: - ``` - description: PDL with model call - text: - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - ``` - - Question: Write a PDL script that makes a call to a model with stop sequence '\n' and stop sequences not included - - Answer: - ``` - description: PDL with model call - text: - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - ``` - - Question: Write a PDL script with a block that has an assignment to variable NAME - - Answer: - ``` - description: PDL with model call - text: - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - def: NAME - ``` - - Question: Write a PDL program with a block that has show results false - - Answer: - ``` - description: PDL with model call - text: - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - contribute: [] - ``` - - Question: Write a PDL program with a block that does not show its results - - Answer: - ``` - description: Example of PDL code block - text: - - lang: python - code: - - | - contents = [] - while True: - try: - line = input() - except EOFError: - break - contents.append(line + "\n") - result = ''.join(contents) - contribute: [] - ``` - - Question: Write a PDL script with a block that has an assignment to variable QUERY - - Answer: - ``` - description: Example of PDL code block - text: - - lang: python - code: - - | - contents = [] - while True: - try: - line = input() - except EOFError: - break - contents.append(line + "\n") - result = ''.join(contents) - def: QUERY - ``` - - Question: Write a PDL program that calls into a model with the following few-shot examples: - "Hello Bob" - "Bye Bob" - - Answer: - ``` - description: PDL with model call - text: - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - parameters: - decoding_method: greedy - input: - text: - - |- - Hello Bob - Bye Bob - ``` - - Question: Write a PDL script that calls into a model with some few-shot examples: - "The sound of music" - "OK Corral" - "The man without a name" - - Answer: - ``` - description: PDL with model call - text: - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - parameters: - decoding_method: greedy - input: - text: - - |- - The sound of music - OK Corral - The man without a name - ``` - - Question: Write a PDL program that calls into a model with the following few-shot examples followed by a query value: - "The wide world" - "Apples and oranges are fruit" - "one more prompt is here" - - Answer: - ``` - description: PDL with model call - text: - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - parameters: - decoding_method: greedy - input: - text: - - |- - The wide world - Apples and oranges are fruit - one more prompt is here - - get: QUERY - ``` - - Question: Write a PDL program that calls into a model with the following examples followed by a location value: - "The singer sings a song" - "The dancer dances to a song" - "A bird sings a song too" - "But the birst does not dance" - - Answer: - ``` - description: PDL with model call - text: - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 - parameters: - decoding_method: greedy - input: - text: - - |- - The singer sings a song - The dancer dances to a song - A bird sings a song too - But the birst does not dance - - get: LOCATION - ``` - - Question: Write a PDL program that contains some Python code to prompt the user for a query. - - Answer: - ``` - description: Using a weather API and LLM to make a small weather app - text: - - lang: python - code: - - | - result = input("How can I help you?: ") - def: QUERY - ``` - - Question: - - get: QUERY - - "\n\n" - def: PDL diff --git a/examples/rag/rag.pdl b/examples/rag/rag.pdl index a61d70fdc..17bf5079e 100644 --- a/examples/rag/rag.pdl +++ b/examples/rag/rag.pdl @@ -43,4 +43,4 @@ text: Q: ${ TEST_PROMPT } A: -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e diff --git a/examples/react/demo.pdl b/examples/react/demo.pdl index 169eb599a..4a8e10dc2 100644 --- a/examples/react/demo.pdl +++ b/examples/react/demo.pdl @@ -35,12 +35,12 @@ text: - repeat: text: - def: thought - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 + model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: stop_sequences: "Act:" temperature: 0 - def: rawAction - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 + model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: stop_sequences: "\n" temperature: 0 diff --git a/examples/react/demonstrations.txt b/examples/react/demonstrations.txt index 8879d2804..f073befea 100644 --- a/examples/react/demonstrations.txt +++ b/examples/react/demonstrations.txt @@ -1,4 +1,5 @@ -"What is the elevation range for the area that the eastern sector of the Colorado orogeny extends into? +| +What is the elevation range for the area that the eastern sector of the Colorado orogeny extends into? Tho: I need to search Colorado orogeny, find the area that the eastern sector of the Colorado ... Act: {"name": "Search", "arguments": {"topic": "Colorado orogeny"}} Obs: The Colorado orogeny was an episode of mountain building (an orogeny) ... @@ -24,4 +25,6 @@ Act: {"name": "Finish", "arguments": {"topic": "54"}} A total of 252 qualifying matches were played, and 723 goals were scored. What was the average number of goals per match? Act: {"name": "Calc", "arguments": {"expr": "723 / 252"}} Obs: 2.869047619047619 -Act: {"name": "Finish", "arguments": {"topic": "2.869047619047619"}}" \ No newline at end of file +Act: {"name": "Finish", "arguments": {"topic": "2.869047619047619"}}" + + diff --git a/examples/react/multi-agent.pdl b/examples/react/multi-agent.pdl index 5c5a95b13..7973c612f 100644 --- a/examples/react/multi-agent.pdl +++ b/examples/react/multi-agent.pdl @@ -12,7 +12,7 @@ text: call: react args: question: ${ question } - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 + model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e - "\n" - if: ${ proposed.split('Act:') | last == verified.split('Act:') | last } then: diff --git a/examples/react/react_call.pdl b/examples/react/react_call.pdl index a3393d6dc..cdac66de3 100644 --- a/examples/react/react_call.pdl +++ b/examples/react/react_call.pdl @@ -3,7 +3,7 @@ text: - include: ./react_fun.pdl - call: react args: - question: How many years ago was the discoverer of the Hudson River born? - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 + question: How many years ago was the discoverer of the Hudson River born? Keep in mind we are in 2024. + model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e diff --git a/examples/react/react_fun.pdl b/examples/react/react_fun.pdl index ca07f2843..ef0bdd883 100644 --- a/examples/react/react_fun.pdl +++ b/examples/react/react_fun.pdl @@ -91,6 +91,7 @@ defs: Tho: High Plains rise in elevation from around 1,800 to 7,000 ft, so the answer is 1,800 to 7,000 ft. Act: {"name": "Finish", "arguments": {"topic": "1,800 to 7,000 ft"}} + - text: | What profession does Nicholas Ray and Elia Kazan have in common? @@ -103,19 +104,25 @@ defs: Tho: Professions of Elia Kazan are director, producer, screenwriter, and actor. So profession Nicholas Ray and Elia Kazan have in common is director, screenwriter, and actor. Act: {"name": "Finish", "arguments": {"topic": "director, screenwriter, actor"}} + - text: | What is 18 + 12 x 3? + Tho: I need to call a calculator. Act: {"name": "Calc", "arguments": {"expr": "18 + 12 * 3"}} Obs: 54 Act: {"name": "Finish", "arguments": {"topic": "54"}} + - text: | A total of 252 qualifying matches were played, and 723 goals were scored. What was the average number of goals per match? + Tho: I need to call a calculator. Act: {"name": "Calc", "arguments": {"expr": "723 / 252"}} Obs: 2.869047619047619 Act: {"name": "Finish", "arguments": {"topic": "2.869047619047619"}} + + - call: react_inner args: pdl_context: [] diff --git a/examples/react/wikipedia.pdl b/examples/react/wikipedia.pdl index 49a3f06ba..ef4423150 100644 --- a/examples/react/wikipedia.pdl +++ b/examples/react/wikipedia.pdl @@ -47,12 +47,12 @@ text: - repeat: text: - def: thought - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 + model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: stop_sequences: "Act:" temperature: 0 - def: rawAction - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 + model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: stop_sequences: "\n" temperature: 0 diff --git a/examples/talk/1-hello.pdl b/examples/talk/1-hello.pdl index 3786fb557..35ad74ba5 100644 --- a/examples/talk/1-hello.pdl +++ b/examples/talk/1-hello.pdl @@ -1,7 +1,7 @@ description: Model call text: - "Hello\n" -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: stop_sequences: "!" include_stop_sequence: true diff --git a/examples/talk/2-model-chaining.pdl b/examples/talk/2-model-chaining.pdl index bfc517468..550014187 100644 --- a/examples/talk/2-model-chaining.pdl +++ b/examples/talk/2-model-chaining.pdl @@ -1,11 +1,11 @@ description: Model chaining text: - "Hello\n" -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: stop_sequences: "!" - "\nTranslate this to French\n" -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: stop_sequences: "!" \ No newline at end of file diff --git a/examples/talk/3-def-use.pdl b/examples/talk/3-def-use.pdl index ca2328f3f..b157f4d03 100644 --- a/examples/talk/3-def-use.pdl +++ b/examples/talk/3-def-use.pdl @@ -1,12 +1,12 @@ description: Variable def and use, model input text: - "Hello,\n" -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e def: name parameters: stop_sequences: "!" - "\n" -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e input: - "Translate the word ${ name | trim } to French\n" parameters: diff --git a/examples/talk/4-function.pdl b/examples/talk/4-function.pdl index ccb06c493..a297a7c5c 100644 --- a/examples/talk/4-function.pdl +++ b/examples/talk/4-function.pdl @@ -6,7 +6,7 @@ text: language: str return: - "\nTranslate the sentence '${ sentence }' to ${ language }.\n" - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 + - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: stop_sequences: "\n" temperature: 0 diff --git a/examples/talk/5-code-eval.pdl b/examples/talk/5-code-eval.pdl index d6d0f6101..d29aec449 100644 --- a/examples/talk/5-code-eval.pdl +++ b/examples/talk/5-code-eval.pdl @@ -7,7 +7,7 @@ defs: read: ./ground_truth.txt text: - "\n${ CODE.source_code }\n" -- model: ireplicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: ireplicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e def: EXPLANATION input: | Here is some info about the location of the function in the repo. diff --git a/examples/talk/6-code-json.pdl b/examples/talk/6-code-json.pdl index 989dc886c..e5dbc79d9 100644 --- a/examples/talk/6-code-json.pdl +++ b/examples/talk/6-code-json.pdl @@ -6,7 +6,7 @@ defs: TRUTH: read: ./ground_truth.txt text: -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e def: EXPLANATION contribute: [] input: diff --git a/examples/talk/7-chatbot-roles.pdl b/examples/talk/7-chatbot-roles.pdl index 7e7cb1a9e..c0f4ebcad 100644 --- a/examples/talk/7-chatbot-roles.pdl +++ b/examples/talk/7-chatbot-roles.pdl @@ -10,7 +10,7 @@ text: message: ">>> " def: query contribute: [context] - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 + - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e - "\n\n" until: ${ query == 'quit'} join: diff --git a/examples/talk/8-tools.pdl b/examples/talk/8-tools.pdl index 8101f9bcf..80f5d7f87 100644 --- a/examples/talk/8-tools.pdl +++ b/examples/talk/8-tools.pdl @@ -17,7 +17,7 @@ text: Out of 1400 participants, 400 passed the test. What percentage is that? - "\n" - def: rawAction - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 + model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: stop_sequences: "\n" - def: action diff --git a/examples/talk/9-react.pdl b/examples/talk/9-react.pdl index 49a3f06ba..ef4423150 100644 --- a/examples/talk/9-react.pdl +++ b/examples/talk/9-react.pdl @@ -47,12 +47,12 @@ text: - repeat: text: - def: thought - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 + model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: stop_sequences: "Act:" temperature: 0 - def: rawAction - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 + model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: stop_sequences: "\n" temperature: 0 diff --git a/examples/tools/calc.pdl b/examples/tools/calc.pdl index 8101f9bcf..80f5d7f87 100644 --- a/examples/tools/calc.pdl +++ b/examples/tools/calc.pdl @@ -17,7 +17,7 @@ text: Out of 1400 participants, 400 passed the test. What percentage is that? - "\n" - def: rawAction - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 + model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: stop_sequences: "\n" - def: action diff --git a/examples/tutorial/calling_apis.pdl b/examples/tutorial/calling_apis.pdl index 66e91bd98..37d1d790b 100644 --- a/examples/tutorial/calling_apis.pdl +++ b/examples/tutorial/calling_apis.pdl @@ -4,7 +4,7 @@ text: def: QUERY message: "Ask a query: " contribute: [] -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e input: | Extract the location from the question. Question: What is the weather in London? @@ -27,7 +27,7 @@ text: parser: json contribute: [] -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e input: | Explain the weather from the following JSON: ${ WEATHER } diff --git a/examples/tutorial/calling_llm.pdl b/examples/tutorial/calling_llm.pdl index d05fd0260..f06960ac4 100644 --- a/examples/tutorial/calling_llm.pdl +++ b/examples/tutorial/calling_llm.pdl @@ -1,7 +1,7 @@ description: Hello world calling a model text: - Hello, -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: decoding_method: greedy stop_sequences: '!' \ No newline at end of file diff --git a/examples/tutorial/calling_llm_with_input.pdl b/examples/tutorial/calling_llm_with_input.pdl index d7bc84faf..548fa2e60 100644 --- a/examples/tutorial/calling_llm_with_input.pdl +++ b/examples/tutorial/calling_llm_with_input.pdl @@ -1,6 +1,6 @@ description: Hello world calling a model text: - "Hello, " -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e input: Translate the word 'world' to French diff --git a/examples/tutorial/data_block.pdl b/examples/tutorial/data_block.pdl index 34ec5eb7d..068e54bd2 100644 --- a/examples/tutorial/data_block.pdl +++ b/examples/tutorial/data_block.pdl @@ -6,7 +6,7 @@ defs: TRUTH: read: ./ground_truth.txt lastOf: -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e def: EXPLANATION input: | diff --git a/examples/tutorial/function_definition.pdl b/examples/tutorial/function_definition.pdl index ccb06c493..a297a7c5c 100644 --- a/examples/tutorial/function_definition.pdl +++ b/examples/tutorial/function_definition.pdl @@ -6,7 +6,7 @@ text: language: str return: - "\nTranslate the sentence '${ sentence }' to ${ language }.\n" - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 + - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: stop_sequences: "\n" temperature: 0 diff --git a/examples/tutorial/gen-data.pdl b/examples/tutorial/gen-data.pdl index 224ee4f6c..86033040b 100644 --- a/examples/tutorial/gen-data.pdl +++ b/examples/tutorial/gen-data.pdl @@ -5,7 +5,7 @@ defs: parser: yaml spec: { questions: [str], answers: [obj] } text: - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 + - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e def: model_output spec: {name: str, age: int} input: @@ -22,7 +22,5 @@ text: and set them appropriately. Write the age in letters. parser: yaml parameters: - stop_sequences: - - '}' - include_stop_sequence: true - \ No newline at end of file + stop_sequences: "\n" + temperature: 0 diff --git a/examples/tutorial/grouping_definitions.pdl b/examples/tutorial/grouping_definitions.pdl index 5cf70f0b8..db34dfaaa 100644 --- a/examples/tutorial/grouping_definitions.pdl +++ b/examples/tutorial/grouping_definitions.pdl @@ -6,7 +6,7 @@ defs: language: str return: - "\nTranslate the sentence '${ sentence }' to ${ language }.\n" - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 + - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: stop_sequences: "\n" text: diff --git a/examples/tutorial/include.pdl b/examples/tutorial/include.pdl index b76e15ef8..866880268 100644 --- a/examples/tutorial/include.pdl +++ b/examples/tutorial/include.pdl @@ -6,14 +6,14 @@ text: def: prompts spec: {prompts: [str]} contribute: [] -- ${ SYSTEM_CONTENT_CHAT } - for: prompt: ${ prompts.prompts } repeat: text: - | + ${ prompt } - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 + - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: decoding_method: sample max_new_tokens: 512 diff --git a/examples/tutorial/model_chaining.pdl b/examples/tutorial/model_chaining.pdl index a4246d42f..e295b6fb1 100644 --- a/examples/tutorial/model_chaining.pdl +++ b/examples/tutorial/model_chaining.pdl @@ -1,10 +1,10 @@ description: Model chaining text: - Hello, -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: stop_sequences: "!" - "\nTranslate this to French\n" -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: stop_sequences: "!" diff --git a/examples/tutorial/muting_block_output.pdl b/examples/tutorial/muting_block_output.pdl index 5e3078842..84d42c81b 100644 --- a/examples/tutorial/muting_block_output.pdl +++ b/examples/tutorial/muting_block_output.pdl @@ -6,7 +6,7 @@ defs: language: str return: - "\nTranslate the sentence '${ sentence }' to ${ language }.\n" - - model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 + - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: stop_sequences: "\n" text: diff --git a/examples/tutorial/variable_def_use.pdl b/examples/tutorial/variable_def_use.pdl index 4f86d81b8..6dc36df61 100644 --- a/examples/tutorial/variable_def_use.pdl +++ b/examples/tutorial/variable_def_use.pdl @@ -1,7 +1,7 @@ description: Hello world with variable def and use text: - Hello, -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e def: GEN parameters: decoding_method: greedy diff --git a/examples/weather/weather.pdl b/examples/weather/weather.pdl index 66e91bd98..37d1d790b 100644 --- a/examples/weather/weather.pdl +++ b/examples/weather/weather.pdl @@ -4,7 +4,7 @@ text: def: QUERY message: "Ask a query: " contribute: [] -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e input: | Extract the location from the question. Question: What is the weather in London? @@ -27,7 +27,7 @@ text: parser: json contribute: [] -- model: replicate/ibm-granite/granite-8b-instruct-preview-4k-r240917a:ffcea6d0e64d9959d9f6b82a426680f2604b047a5ec18d4c386c26e56a71d746 +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e input: | Explain the weather from the following JSON: ${ WEATHER } From ede4130af3366ebfbf4e497ea3b5b646c3849c01 Mon Sep 17 00:00:00 2001 From: Mandana Vaziri Date: Thu, 17 Oct 2024 18:57:41 -0400 Subject: [PATCH 19/24] updates to examples Signed-off-by: Mandana Vaziri --- README.md | 80 +++++--- docs/README.md | 76 +++++--- examples/callback/repair_prompt.pdl | 5 +- examples/demo/2-teacher.pdl | 22 +-- examples/hello/hello-def-use.pdl | 6 +- examples/hello/hello-model-chaining.pdl | 9 +- examples/notebooks/demo.ipynb | 243 +++++++++++++++++------- examples/notebooks/demonstrations.txt | 7 +- examples/notebooks/notebook.ipynb | 53 +++--- examples/notebooks/notebook_debug.ipynb | 6 +- examples/notebooks/pdl.ipynb | 118 +++++------- examples/react/demonstrations.txt | 7 +- examples/sdk/hello.pdl | 10 +- examples/sdk/hello_dict.py | 7 +- examples/sdk/hello_prog.py | 6 +- examples/sdk/hello_str.py | 8 +- examples/talk/11-sdg.pdl | 22 +-- examples/talk/3-def-use.pdl | 2 +- examples/teacher/teacher.pdl | 21 +- examples/tutorial/calling_llm.pdl | 2 +- examples/tutorial/model_chaining.pdl | 2 +- 21 files changed, 428 insertions(+), 284 deletions(-) diff --git a/README.md b/README.md index c58b92537..dbc97216f 100644 --- a/README.md +++ b/README.md @@ -39,16 +39,15 @@ pip install prompt-declaration-language To install the dependencies for development of PDL and execute all the example, execute the command: ``` -pip install 'prompt-declaration-language[dev]' pip install 'prompt-declaration-language[examples]' -pip install 'prompt-declaration-language[docs]' ``` -In order to run the examples that use foundation models hosted on [Replicate](https://replicate.com/) via LiteLLM, you need to create a free account +Most examples in this repository use IBM Granite models on [Replicate](https://replicate.com/). +In order to run these examples, you need to create a free account on Replicate, get an API key and store it in the environment variable: - `REPLICATE_API_TOKEN` -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: +In order to 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: - `WATSONX_URL`, the API url (set to `https://{region}.ml.cloud.ibm.com`) of your WatsonX instance - `WATSONX_APIKEY`, the API key (see information on [key creation](https://cloud.ibm.com/docs/account?topic=account-userapikey&interface=ui#create_user_key)) - `WATSONX_PROJECT_ID`, the project hosting the resources (see information about [project creation](https://www.ibm.com/docs/en/watsonx/saas?topic=projects-creating-project) and [finding project ID](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-project-id.html?context=wx)). @@ -121,17 +120,14 @@ In PDL, we can write some YAML to create a prompt and call an LLM: ```yaml description: Hello world text: -- Hello, -- model: ibm/granite-34b-code-instruct - platform: bam +- "Hello\n" +- model: replicate/ibm-granite/granite-20b-code-instruct-8k parameters: - decoding_method: greedy - stop_sequences: - - '!' - include_stop_sequence: true + stop_sequences: '!' + temperature: 0 ``` -The `description` field is a description for the program. Field `text` contains a list of either strings or *block*s which together form the text to be produced. In this example, the text starts with the string `"Hello"` followed by a block that calls out to a model. In this case, it is model with id `watsonx/ibm/granite-34b-code-instruct` from [watsonx](https://www.ibm.com/watsonx), via LiteLLM, with the indicated parameters: the stop sequence is `!`, which is to be included in the output. The input to the model call is everything that has been produced so far in the document (here `Hello`). +The `description` field is a description for the program. Field `text` contains a list of either strings or *block*s which together form the text to be produced. In this example, the text starts with the string `"Hello\n"` followed by a block that calls out to a model. In this case, it is model with id `replicate/ibm-granite/granite-20b-code-instruct-8k` on Replicate, via LiteLLM, with the indicated parameters: the stop sequence is `!`, and temperature set to `0`. Stop sequences are provided with a comman separated list of strings. The input to the model call is everything that has been produced so far in the program (here `"Hello\n"`). When we execute this program using the PDL interpreter: @@ -139,13 +135,29 @@ When we execute this program using the PDL interpreter: pdl examples/hello/hello.pdl ``` -we obtain the following document: +we obtain the following: ``` -Hello, World! +Hello +Hello ``` -where the portion `, World!` was produced by granite. In general, PDL provides blocks for calling models, Python code, and makes it easy to compose them together with control structures (sequencing, conditions, loops). +where the second `Hello` was produced by Granite. In general, PDL provides blocks for calling models, Python code, and makes it easy to compose them together with control structures (sequencing, conditions, loops). + +A similar example on WatsonX would look as follows: + +```yaml +description: Hello world +text: +- Hello, +- model: watsonx/ibm/granite-34b-code-instruct + parameters: + decoding_method: greedy + stop: + - '!' +``` + +Notice the syntactic differences. Model ids on WatsonX start with `watsonx`. The `decoding_method` can be set to `greedy`, rather than setting the temperature to `0`. Also, `stop_sequences` are indicated with the keyword `stop` instead as a list of strings. A PDL program computes 2 data structures. The first is a JSON corresponding to the result of the overall program, obtained by aggregating the results of each block. This is what is printed by default when we run the interpreter. The second is a conversational background context, which is a list of role/content pairs, where we implicitly keep track of roles and content for the purpose of communicating with models that support chat APIs. The contents in the latter correspond to the results of each block. The conversational background context is what is used to make calls to LLMs via LiteLLM. @@ -215,8 +227,7 @@ defs: parser: yaml text: - "\n${ CODE.source_code }\n" -- model: ibm/granite-34b-code-instruct - platform: bam +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e input: - | Here is some info about the location of the function in the repo. @@ -254,11 +265,19 @@ public static Map deserializeOffsetMap(String lastSourceOffset) return offsetMap; } +This Java function, `deserializeOffsetMap`, is designed to deserialize a JSON string into a `Map`. Here's a breakdown of what it does: + +1. It takes a single argument, `lastSourceOffset`, which is expected to be a JSON string. + +2. It initializes a `Map` called `offsetMap`. +3. If `lastSourceOffset` is either `null` or an empty string, it creates a new `HashMap` and assigns it to `offsetMap`. -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. +4. If `lastSourceOffset` is not `null` or an empty string, it uses the `JSON_MAPPER` object (which is presumably an instance of a JSON deserialization library like Jackson) to deserialize the JSON string into a `Map` and assigns it to `offsetMap`. -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. +5. Finally, it returns the `offsetMap`. + +The `@SuppressWarnings("unchecked")` annotation is used to suppress a compile-time warning about the raw use of the `Map` type. This is because the `JSON_MAPPER.readValue` method returns a `Map` object, but the compiler doesn't know that this `Map` will be a `Map`. The `unchecked` warning is suppressed to avoid this compile-time warning. ``` 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): @@ -273,8 +292,7 @@ defs: read: ./ground_truth.txt text: - "\n${ CODE.source_code }\n" -- model: ibm/granite-34b-code-instruct - platform: bam +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e def: EXPLANATION input: | Here is some info about the location of the function in the repo. @@ -323,14 +341,23 @@ public static Map deserializeOffsetMap(String lastSourceOffset) return offsetMap; } +This Java method, `deserializeOffsetMap`, is designed to convert a JSON string into a `Map`. Here's a breakdown of the code: + +1. The method takes a single argument, `lastSourceOffset`, which is expected to be a JSON string. + +2. It initializes a `Map` called `offsetMap`. + +3. If `lastSourceOffset` is either `null` or an empty string, it creates a new `HashMap` and assigns it to `offsetMap`. + +4. If `lastSourceOffset` is not `null` or empty, it uses the `JSON_MAPPER` object (which is presumably an instance of `ObjectMapper` from the Jackson library) to convert the JSON string into a `Map` and assigns it to `offsetMap`. -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. +5. Finally, it returns the `offsetMap`. -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. +The `@SuppressWarnings("unchecked")` annotation is used to suppress a potential unchecked warning that might occur if the JSON string does not match the expected `Map` type. EVALUATION: The similarity (Levenshtein) between this answer and the ground truth is: -0.9967637540453075 +0.30199115044247793 ``` PDL allows rapid prototyping of prompts by allowing the user to change prompts and see their immediate effects on metrics. Try it! @@ -346,8 +373,7 @@ defs: TRUTH: read: ./ground_truth.txt text: -- model: ibm/granite-34b-code-instruct - platform: bam +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e def: EXPLANATION contribute: [] input: @@ -409,7 +435,7 @@ This is similar to a spreadsheet for tabular data, where data is in the forefron ## Additional Notes -When using Granite models on watsonx, we use the following defaults for model parameters (except `granite-20b-code-instruct-r1.1`): +When using Granite models, we use the following defaults for model parameters (except `granite-20b-code-instruct-r1.1`): - `decoding_method`: `greedy` - `max_new_tokens`: 1024 - `min_new_tokens`: 1 diff --git a/docs/README.md b/docs/README.md index 4bdd5075f..44308d49a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -44,16 +44,15 @@ pip install prompt-declaration-language To install the dependencies for development of PDL and execute all the example, execute the command: ``` -pip install 'prompt-declaration-language[dev]' pip install 'prompt-declaration-language[examples]' -pip install 'prompt-declaration-language[docs]' ``` -In order to run the examples that use foundation models hosted on [Replicate](https://replicate.com/) via LiteLLM, you need to create a free account +Most examples in this repository use IBM Granite models on [Replicate](https://replicate.com/). +In order to run these examples, you need to create a free account on Replicate, get an API key and store it in the environment variable: - `REPLICATE_API_TOKEN` -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: +In order to 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: - `WATSONX_URL`, the API url (set to `https://{region}.ml.cloud.ibm.com`) of your WatsonX instance - `WATSONX_APIKEY`, the API key (see information on [key creation](https://cloud.ibm.com/docs/account?topic=account-userapikey&interface=ui#create_user_key)) - `WATSONX_PROJECT_ID`, the project hosting the resources (see information about [project creation](https://www.ibm.com/docs/en/watsonx/saas?topic=projects-creating-project) and [finding project ID](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-project-id.html?context=wx)). @@ -126,16 +125,14 @@ In PDL, we can write some YAML to create a prompt and call an LLM: ```yaml description: Hello world text: -- Hello, -- model: watsonx/ibm/granite-34b-code-instruct +- "Hello\n" +- model: replicate/ibm-granite/granite-20b-code-instruct-8k parameters: - decoding_method: greedy - stop: - - '!' - include_stop_sequence: true + stop_sequences: '!' + temperature: 0 ``` -The `description` field is a description for the program. Field `text` contains a list of either strings or *block*s which together form the text to be produced. In this example, the text starts with the string `"Hello"` followed by a block that calls out to a model. In this case, it is model with id `watsonx/ibm/granite-34b-code-instruct` from [watsonx](https://www.ibm.com/watsonx), via LiteLLM, with the indicated parameters: the stop sequence is `!`, which is to be included in the output. The input to the model call is everything that has been produced so far in the document (here `Hello`). +The `description` field is a description for the program. Field `text` contains a list of either strings or *block*s which together form the text to be produced. In this example, the text starts with the string `"Hello\n"` followed by a block that calls out to a model. In this case, it is model with id `replicate/ibm-granite/granite-20b-code-instruct-8k` on Replicate, via LiteLLM, with the indicated parameters: the stop sequence is `!`, and temperature set to `0`. Stop sequences are provided with a comman separated list of strings. The input to the model call is everything that has been produced so far in the program (here `"Hello\n"`). When we execute this program using the PDL interpreter: @@ -143,13 +140,29 @@ When we execute this program using the PDL interpreter: pdl examples/hello/hello.pdl ``` -we obtain the following document: +we obtain the following: ``` -Hello, World! +Hello +Hello +``` + +where the second `Hello` was produced by Granite. In general, PDL provides blocks for calling models, Python code, and makes it easy to compose them together with control structures (sequencing, conditions, loops). + +A similar example on WatsonX would look as follows: + +```yaml +description: Hello world +text: +- Hello, +- model: watsonx/ibm/granite-34b-code-instruct + parameters: + decoding_method: greedy + stop: + - '!' ``` -where the portion `, World!` was produced by granite. In general, PDL provides blocks for calling models, Python code, and makes it easy to compose them together with control structures (sequencing, conditions, loops). +Notice the syntactic differences. Model ids on WatsonX start with `watsonx`. The `decoding_method` can be set to `greedy`, rather than setting the temperature to `0`. Also, `stop_sequences` are indicated with the keyword `stop` instead as a list of strings. A PDL program computes 2 data structures. The first is a JSON corresponding to the result of the overall program, obtained by aggregating the results of each block. This is what is printed by default when we run the interpreter. The second is a conversational background context, which is a list of role/content pairs, where we implicitly keep track of roles and content for the purpose of communicating with models that support chat APIs. The contents in the latter correspond to the results of each block. The conversational background context is what is used to make calls to LLMs via LiteLLM. @@ -219,7 +232,7 @@ defs: parser: yaml text: - "\n${ CODE.source_code }\n" -- model: watsonx/ibm/granite-34b-code-instruct +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e input: - | Here is some info about the location of the function in the repo. @@ -257,11 +270,19 @@ public static Map deserializeOffsetMap(String lastSourceOffset) return offsetMap; } +This Java function, `deserializeOffsetMap`, is designed to deserialize a JSON string into a `Map`. Here's a breakdown of what it does: + +1. It takes a single argument, `lastSourceOffset`, which is expected to be a JSON string. + +2. It initializes a `Map` called `offsetMap`. +3. If `lastSourceOffset` is either `null` or an empty string, it creates a new `HashMap` and assigns it to `offsetMap`. -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. +4. If `lastSourceOffset` is not `null` or an empty string, it uses the `JSON_MAPPER` object (which is presumably an instance of a JSON deserialization library like Jackson) to deserialize the JSON string into a `Map` and assigns it to `offsetMap`. -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. +5. Finally, it returns the `offsetMap`. + +The `@SuppressWarnings("unchecked")` annotation is used to suppress a compile-time warning about the raw use of the `Map` type. This is because the `JSON_MAPPER.readValue` method returns a `Map` object, but the compiler doesn't know that this `Map` will be a `Map`. The `unchecked` warning is suppressed to avoid this compile-time warning. ``` 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): @@ -276,7 +297,7 @@ defs: read: ./ground_truth.txt text: - "\n${ CODE.source_code }\n" -- model: watsonx/ibm/granite-34b-code-instruct +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e def: EXPLANATION input: | Here is some info about the location of the function in the repo. @@ -325,14 +346,23 @@ public static Map deserializeOffsetMap(String lastSourceOffset) return offsetMap; } +This Java method, `deserializeOffsetMap`, is designed to convert a JSON string into a `Map`. Here's a breakdown of the code: + +1. The method takes a single argument, `lastSourceOffset`, which is expected to be a JSON string. + +2. It initializes a `Map` called `offsetMap`. -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. +3. If `lastSourceOffset` is either `null` or an empty string, it creates a new `HashMap` and assigns it to `offsetMap`. -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. +4. If `lastSourceOffset` is not `null` or empty, it uses the `JSON_MAPPER` object (which is presumably an instance of `ObjectMapper` from the Jackson library) to convert the JSON string into a `Map` and assigns it to `offsetMap`. + +5. Finally, it returns the `offsetMap`. + +The `@SuppressWarnings("unchecked")` annotation is used to suppress a potential unchecked warning that might occur if the JSON string does not match the expected `Map` type. EVALUATION: The similarity (Levenshtein) between this answer and the ground truth is: -0.9967637540453075 +0.30199115044247793 ``` PDL allows rapid prototyping of prompts by allowing the user to change prompts and see their immediate effects on metrics. Try it! @@ -348,7 +378,7 @@ defs: TRUTH: read: ./ground_truth.txt text: -- model: watsonx/ibm/granite-34b-code-instruct +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e def: EXPLANATION contribute: [] input: @@ -410,7 +440,7 @@ This is similar to a spreadsheet for tabular data, where data is in the forefron ## Additional Notes -When using Granite models on watsonx, we use the following defaults for model parameters (except `granite-20b-code-instruct-r1.1`): +When using Granite models, we use the following defaults for model parameters (except `granite-20b-code-instruct-r1.1`): - `decoding_method`: `greedy` - `max_new_tokens`: 1024 - `min_new_tokens`: 1 diff --git a/examples/callback/repair_prompt.pdl b/examples/callback/repair_prompt.pdl index 41601a65c..306117f6d 100644 --- a/examples/callback/repair_prompt.pdl +++ b/examples/callback/repair_prompt.pdl @@ -9,9 +9,10 @@ contribute: [context] - def: raw_output - model: watsonx/ibm/granite-34b-code-instruct + model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: - stop: ["\n\n"] + stop_sequences: "\n\n" + temperature: 0 - lang: python def: parsed_output diff --git a/examples/demo/2-teacher.pdl b/examples/demo/2-teacher.pdl index 7cb787450..2ac8c8887 100644 --- a/examples/demo/2-teacher.pdl +++ b/examples/demo/2-teacher.pdl @@ -1,6 +1,6 @@ defs: teacher_sys_prompt: You are a very knowledgeable AI Assistant that will faithfully assist the user with their task. - teacher_model: mistralai/mixtral-8x7b-instruct-v01 + teacher_model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e teacher_template: function: sys_prompt: str @@ -65,11 +65,10 @@ defs: ${prompt_data.generation} teacher_output: model: ${teacher_model} - platform: bam input: ${teacher_input} parameters: - stop_sequences: ["${teacher_stop_token}"] - include_stop_sequence: false + temperature: 0 + stop_sequences: "${teacher_stop_token}" max_new_tokens: ${prompt_data.max_new_tokens} parser: regex: '### Question [0-9]+:\s*([^#\n]+)' @@ -155,12 +154,11 @@ defs: ${prompt_data.generation} teacher_output: model: ${teacher_model} - platform: bam input: ${teacher_input} parameters: - stop_sequences: ["${teacher_stop_token}"] - include_stop_sequence: false + stop_sequences: "${teacher_stop_token}" max_new_tokens: ${prompt_data.max_new_tokens} + temperature: 0 parser: spec: { "rating": str } # regex: "Rating.*\\[\\[(?P\\d+\\.?\\d*)\\]\\]" @@ -251,12 +249,11 @@ defs: ${prompt_data.generation} teacher_output: model: ${teacher_model} - platform: bam input: ${teacher_input} parameters: - stop_sequences: ${ [teacher_stop_token] + prompt_data.additional_stop_tokens } - include_stop_sequence: false + stop_sequences: ${ ([teacher_stop_token] + prompt_data.additional_stop_tokens) | join(',') } max_new_tokens: ${prompt_data.max_new_tokens} + temperature: 0 parsed_answer: lang: python code: | # parse model output @@ -339,12 +336,11 @@ defs: ${prompt_data.generation} teacher_output: model: ${teacher_model} - platform: bam input: ${teacher_input} parameters: - stop_sequences: ["${teacher_stop_token}"] - include_stop_sequence: false + stop_sequences: "${teacher_stop_token}" max_new_tokens: ${prompt_data.max_new_tokens} + temperature: 0 parser: spec: { "rating": str } regex: 'Rating.*\[\[(?P\d+\.?\d*)\]\]' diff --git a/examples/hello/hello-def-use.pdl b/examples/hello/hello-def-use.pdl index a5e4e29e7..09662f40c 100644 --- a/examples/hello/hello-def-use.pdl +++ b/examples/hello/hello-def-use.pdl @@ -1,11 +1,11 @@ description: Hello world with variable use text: -- Hello, +- "Hello\n" - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: decoding_method: greedy stop_sequences: '!' - def: NAME + def: GEN - | - Who is${ NAME }? \ No newline at end of file + You said ${ GEN }. \ No newline at end of file diff --git a/examples/hello/hello-model-chaining.pdl b/examples/hello/hello-model-chaining.pdl index 020e16368..aeb42c02f 100644 --- a/examples/hello/hello-model-chaining.pdl +++ b/examples/hello/hello-model-chaining.pdl @@ -1,15 +1,12 @@ description: Hello world showing model chaining text: -- Hello, +- "Hello\n" - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: decoding_method: greedy stop_sequences: '!' - def: NAME -- |- - ! - Who is${ NAME }? -- "\n" + def: GEN +- "\nDid you say ${ GEN }?\n" - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: decoding_method: greedy diff --git a/examples/notebooks/demo.ipynb b/examples/notebooks/demo.ipynb index 3796d741a..236c9ea1e 100644 --- a/examples/notebooks/demo.ipynb +++ b/examples/notebooks/demo.ipynb @@ -16,17 +16,108 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "ca2e7ba6-e0f0-4d88-a083-5ff257ed2c34", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: prompt-declaration-language[examples] in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (0.0.7)\n", + "Requirement already satisfied: pydantic~=2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (2.9.1)\n", + "Requirement already satisfied: ibm-generative-ai~=3.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (3.0.0)\n", + "Requirement already satisfied: requests~=2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (2.32.3)\n", + "Requirement already satisfied: python-dotenv~=1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (1.0.1)\n", + "Requirement already satisfied: jinja2~=3.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (3.1.4)\n", + "Requirement already satisfied: PyYAML~=6.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (6.0.2)\n", + "Requirement already satisfied: jsonschema~=4.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (4.23.0)\n", + "Requirement already satisfied: litellm~=1.49 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (1.49.2)\n", + "Requirement already satisfied: termcolor~=2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (2.4.0)\n", + "Requirement already satisfied: ipython~=8.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (8.27.0)\n", + "Requirement already satisfied: wikipedia~=1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (1.4.0)\n", + "Requirement already satisfied: textdistance~=4.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (4.6.3)\n", + "Requirement already satisfied: faiss-cpu~=1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (1.8.0.post1)\n", + "Requirement already satisfied: datasets<4,>2 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (3.0.1)\n", + "Requirement already satisfied: sympy~=1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-declaration-language[examples]) (1.13.2)\n", + "Requirement already satisfied: filelock in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (3.16.0)\n", + "Requirement already satisfied: numpy>=1.17 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (1.26.4)\n", + "Requirement already satisfied: pyarrow>=15.0.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (17.0.0)\n", + "Requirement already satisfied: dill<0.3.9,>=0.3.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (0.3.8)\n", + "Requirement already satisfied: pandas in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (2.2.2)\n", + "Requirement already satisfied: tqdm>=4.66.3 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (4.66.5)\n", + "Requirement already satisfied: xxhash in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (3.5.0)\n", + "Requirement already satisfied: multiprocess in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (0.70.16)\n", + "Requirement already satisfied: fsspec<=2024.6.1,>=2023.1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from fsspec[http]<=2024.6.1,>=2023.1.0->datasets<4,>2->prompt-declaration-language[examples]) (2024.6.1)\n", + "Requirement already satisfied: aiohttp in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (3.10.5)\n", + "Requirement already satisfied: huggingface-hub>=0.22.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (0.24.7)\n", + "Requirement already satisfied: packaging in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from datasets<4,>2->prompt-declaration-language[examples]) (24.1)\n", + "Requirement already satisfied: aiolimiter<2.0.0,>=1.1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ibm-generative-ai~=3.0->prompt-declaration-language[examples]) (1.1.0)\n", + "Requirement already satisfied: deprecated<2.0.0,>=1.2.14 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ibm-generative-ai~=3.0->prompt-declaration-language[examples]) (1.2.14)\n", + "Requirement already satisfied: httpx<0.28.0,>=0.27.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ibm-generative-ai~=3.0->prompt-declaration-language[examples]) (0.27.2)\n", + "Requirement already satisfied: httpx-sse<0.5.0,>=0.4.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ibm-generative-ai~=3.0->prompt-declaration-language[examples]) (0.4.0)\n", + "Requirement already satisfied: decorator in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language[examples]) (5.1.1)\n", + "Requirement already satisfied: jedi>=0.16 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language[examples]) (0.19.1)\n", + "Requirement already satisfied: matplotlib-inline in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language[examples]) (0.1.7)\n", + "Requirement already satisfied: prompt-toolkit<3.1.0,>=3.0.41 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language[examples]) (3.0.47)\n", + "Requirement already satisfied: pygments>=2.4.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language[examples]) (2.18.0)\n", + "Requirement already satisfied: stack-data in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language[examples]) (0.6.3)\n", + "Requirement already satisfied: traitlets>=5.13.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language[examples]) (5.14.3)\n", + "Requirement already satisfied: pexpect>4.3 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from ipython~=8.0->prompt-declaration-language[examples]) (4.9.0)\n", + "Requirement already satisfied: MarkupSafe>=2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jinja2~=3.0->prompt-declaration-language[examples]) (2.1.5)\n", + "Requirement already satisfied: attrs>=22.2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jsonschema~=4.0->prompt-declaration-language[examples]) (24.2.0)\n", + "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jsonschema~=4.0->prompt-declaration-language[examples]) (2023.12.1)\n", + "Requirement already satisfied: referencing>=0.28.4 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jsonschema~=4.0->prompt-declaration-language[examples]) (0.35.1)\n", + "Requirement already satisfied: rpds-py>=0.7.1 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jsonschema~=4.0->prompt-declaration-language[examples]) (0.20.0)\n", + "Requirement already satisfied: click in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from litellm~=1.49->prompt-declaration-language[examples]) (8.1.7)\n", + "Requirement already satisfied: importlib-metadata>=6.8.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from litellm~=1.49->prompt-declaration-language[examples]) (8.4.0)\n", + "Requirement already satisfied: openai>=1.51.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from litellm~=1.49->prompt-declaration-language[examples]) (1.51.0)\n", + "Requirement already satisfied: tiktoken>=0.7.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from litellm~=1.49->prompt-declaration-language[examples]) (0.7.0)\n", + "Requirement already satisfied: tokenizers in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from litellm~=1.49->prompt-declaration-language[examples]) (0.19.1)\n", + "Requirement already satisfied: annotated-types>=0.6.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pydantic~=2.0->prompt-declaration-language[examples]) (0.7.0)\n", + "Requirement already satisfied: pydantic-core==2.23.3 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pydantic~=2.0->prompt-declaration-language[examples]) (2.23.3)\n", + "Requirement already satisfied: typing-extensions>=4.6.1 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pydantic~=2.0->prompt-declaration-language[examples]) (4.12.2)\n", + "Requirement already satisfied: charset-normalizer<4,>=2 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from requests~=2.0->prompt-declaration-language[examples]) (3.3.2)\n", + "Requirement already satisfied: idna<4,>=2.5 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from requests~=2.0->prompt-declaration-language[examples]) (3.10)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from requests~=2.0->prompt-declaration-language[examples]) (1.26.20)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from requests~=2.0->prompt-declaration-language[examples]) (2024.8.30)\n", + "Requirement already satisfied: mpmath<1.4,>=1.1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from sympy~=1.0->prompt-declaration-language[examples]) (1.3.0)\n", + "Requirement already satisfied: beautifulsoup4 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from wikipedia~=1.0->prompt-declaration-language[examples]) (4.12.3)\n", + "Requirement already satisfied: wrapt<2,>=1.10 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from deprecated<2.0.0,>=1.2.14->ibm-generative-ai~=3.0->prompt-declaration-language[examples]) (1.16.0)\n", + "Requirement already satisfied: aiohappyeyeballs>=2.3.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from aiohttp->datasets<4,>2->prompt-declaration-language[examples]) (2.4.0)\n", + "Requirement already satisfied: aiosignal>=1.1.2 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from aiohttp->datasets<4,>2->prompt-declaration-language[examples]) (1.3.1)\n", + "Requirement already satisfied: frozenlist>=1.1.1 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from aiohttp->datasets<4,>2->prompt-declaration-language[examples]) (1.4.1)\n", + "Requirement already satisfied: multidict<7.0,>=4.5 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from aiohttp->datasets<4,>2->prompt-declaration-language[examples]) (6.1.0)\n", + "Requirement already satisfied: yarl<2.0,>=1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from aiohttp->datasets<4,>2->prompt-declaration-language[examples]) (1.11.1)\n", + "Requirement already satisfied: anyio in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from httpx<0.28.0,>=0.27.0->ibm-generative-ai~=3.0->prompt-declaration-language[examples]) (4.4.0)\n", + "Requirement already satisfied: httpcore==1.* in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from httpx<0.28.0,>=0.27.0->ibm-generative-ai~=3.0->prompt-declaration-language[examples]) (1.0.5)\n", + "Requirement already satisfied: sniffio in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from httpx<0.28.0,>=0.27.0->ibm-generative-ai~=3.0->prompt-declaration-language[examples]) (1.3.1)\n", + "Requirement already satisfied: h11<0.15,>=0.13 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from httpcore==1.*->httpx<0.28.0,>=0.27.0->ibm-generative-ai~=3.0->prompt-declaration-language[examples]) (0.14.0)\n", + "Requirement already satisfied: zipp>=0.5 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from importlib-metadata>=6.8.0->litellm~=1.49->prompt-declaration-language[examples]) (3.20.1)\n", + "Requirement already satisfied: parso<0.9.0,>=0.8.3 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from jedi>=0.16->ipython~=8.0->prompt-declaration-language[examples]) (0.8.4)\n", + "Requirement already satisfied: distro<2,>=1.7.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from openai>=1.51.0->litellm~=1.49->prompt-declaration-language[examples]) (1.9.0)\n", + "Requirement already satisfied: jiter<1,>=0.4.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from openai>=1.51.0->litellm~=1.49->prompt-declaration-language[examples]) (0.5.0)\n", + "Requirement already satisfied: ptyprocess>=0.5 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pexpect>4.3->ipython~=8.0->prompt-declaration-language[examples]) (0.7.0)\n", + "Requirement already satisfied: wcwidth in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from prompt-toolkit<3.1.0,>=3.0.41->ipython~=8.0->prompt-declaration-language[examples]) (0.2.13)\n", + "Requirement already satisfied: regex>=2022.1.18 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from tiktoken>=0.7.0->litellm~=1.49->prompt-declaration-language[examples]) (2024.7.24)\n", + "Requirement already satisfied: soupsieve>1.2 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from beautifulsoup4->wikipedia~=1.0->prompt-declaration-language[examples]) (2.6)\n", + "Requirement already satisfied: python-dateutil>=2.8.2 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pandas->datasets<4,>2->prompt-declaration-language[examples]) (2.9.0.post0)\n", + "Requirement already satisfied: pytz>=2020.1 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pandas->datasets<4,>2->prompt-declaration-language[examples]) (2024.2)\n", + "Requirement already satisfied: tzdata>=2022.7 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from pandas->datasets<4,>2->prompt-declaration-language[examples]) (2024.1)\n", + "Requirement already satisfied: executing>=1.2.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from stack-data->ipython~=8.0->prompt-declaration-language[examples]) (2.1.0)\n", + "Requirement already satisfied: asttokens>=2.1.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from stack-data->ipython~=8.0->prompt-declaration-language[examples]) (2.4.1)\n", + "Requirement already satisfied: pure-eval in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from stack-data->ipython~=8.0->prompt-declaration-language[examples]) (0.2.3)\n", + "Requirement already satisfied: six>=1.12.0 in /Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages (from asttokens>=2.1.0->stack-data->ipython~=8.0->prompt-declaration-language[examples]) (1.16.0)\n" + ] + } + ], "source": [ "! pip install 'prompt-declaration-language[examples]'" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "e25a6874-54d9-4167-82ed-ab2f4fdc0a6f", "metadata": {}, "outputs": [], @@ -46,7 +137,7 @@ }, { "cell_type": "code", - "execution_count": 70, + "execution_count": 2, "id": "f3c62df1-0347-4711-acd7-3892cfd5df30", "metadata": {}, "outputs": [ @@ -55,7 +146,15 @@ "output_type": "stream", "text": [ "What is the meaning of life?\n", - "\u001b[32mThe\u001b[0m\u001b[32m meaning\u001b[0m\u001b[32m of\u001b[0m\u001b[32m life\u001b[0m\u001b[32m is\u001b[0m\u001b[32m a\u001b[0m\u001b[32m ph\u001b[0m\u001b[32milo\u001b[0m\u001b[32msop\u001b[0m\u001b[32mh\u001b[0m\u001b[32mical\u001b[0m\u001b[32m and\u001b[0m\u001b[32m met\u001b[0m\u001b[32maph\u001b[0m\u001b[32mysical\u001b[0m\u001b[32m question\u001b[0m\u001b[32m related\u001b[0m\u001b[32m to\u001b[0m\u001b[32m the\u001b[0m\u001b[32m purpose\u001b[0m\u001b[32m or\u001b[0m\u001b[32m signific\u001b[0m\u001b[32mance\u001b[0m\u001b[32m of\u001b[0m\u001b[32m life\u001b[0m\u001b[32m or\u001b[0m\u001b[32m existence\u001b[0m\u001b[32m in\u001b[0m\u001b[32m general\u001b[0m\u001b[32m.\u001b[0m\u001b[32m This\u001b[0m\u001b[32m question\u001b[0m\u001b[32m has\u001b[0m\u001b[32m been\u001b[0m\u001b[32m asked\u001b[0m\u001b[32m for\u001b[0m\u001b[32m cent\u001b[0m\u001b[32mur\u001b[0m\u001b[32mies\u001b[0m\u001b[32m and\u001b[0m\u001b[32m does\u001b[0m\u001b[32m not\u001b[0m\u001b[32m have\u001b[0m\u001b[32m a\u001b[0m\u001b[32m def\u001b[0m\u001b[32minit\u001b[0m\u001b[32mive\u001b[0m\u001b[32m answer\u001b[0m\u001b[32m.\u001b[0m\u001b[32m Some\u001b[0m\u001b[32m people\u001b[0m\u001b[32m find\u001b[0m\u001b[32m meaning\u001b[0m\u001b[32m through\u001b[0m\u001b[32m personal\u001b[0m\u001b[32m growth\u001b[0m\u001b[32m,\u001b[0m\u001b[32m relationships\u001b[0m\u001b[32m,\u001b[0m\u001b[32m love\u001b[0m\u001b[32m,\u001b[0m\u001b[32m or\u001b[0m\u001b[32m through\u001b[0m\u001b[32m contributing\u001b[0m\u001b[32m to\u001b[0m\u001b[32m the\u001b[0m\u001b[32m better\u001b[0m\u001b[32mment\u001b[0m\u001b[32m of\u001b[0m\u001b[32m human\u001b[0m\u001b[32mity\u001b[0m\u001b[32m.\u001b[0m\u001b[32m U\u001b[0m\u001b[32mlt\u001b[0m\u001b[32mimately\u001b[0m\u001b[32m,\u001b[0m\u001b[32m the\u001b[0m\u001b[32m meaning\u001b[0m\u001b[32m of\u001b[0m\u001b[32m life\u001b[0m\u001b[32m may\u001b[0m\u001b[32m be\u001b[0m\u001b[32m a\u001b[0m\u001b[32m personal\u001b[0m\u001b[32m and\u001b[0m\u001b[32m subject\u001b[0m\u001b[32mive\u001b[0m\u001b[32m concept\u001b[0m\u001b[32m.\u001b[0m" + "\u001b[32mThe meaning of life is a philosophical and metaphysical question related to the purpose or significance of life or existence in general. This question has been asked for centuries and does not have a definitive answer. Some people find meaning through personal growth, relationships, love, or through contributing to the betterment of humanity. Others may find\u001b[0m\u001b[32m it through spirituality or religious beliefs. Ultimately, the meaning of life may be something personal and subjective.\u001b[0m" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", + " from .autonotebook import tqdm as notebook_tqdm\n" ] } ], @@ -63,8 +162,7 @@ "%%pdl --reset-context\n", "text: \n", "- \"What is the meaning of life?\\n\"\n", - "- model: ibm/granite-8b-instruct-preview-4k\n", - " platform: bam" + "- model: \"replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e\"" ] }, { @@ -78,7 +176,7 @@ }, { "cell_type": "code", - "execution_count": 71, + "execution_count": 5, "id": "7f6c323b-ad1a-4434-8732-bc19c5c47883", "metadata": {}, "outputs": [ @@ -88,26 +186,26 @@ "text": [ "\n", "Say it like a poem\n", - "\u001b[32mLife\u001b[0m\u001b[32m's\u001b[0m\u001b[32m meaning\u001b[0m\u001b[32m,\u001b[0m\u001b[32m a\u001b[0m\u001b[32m question\u001b[0m\u001b[32m vast\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mIn\u001b[0m\u001b[32m ph\u001b[0m\u001b[32milo\u001b[0m\u001b[32msophy\u001b[0m\u001b[32m,\u001b[0m\u001b[32m it\u001b[0m\u001b[32m's\u001b[0m\u001b[32m often\u001b[0m\u001b[32m cast\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mPersonal\u001b[0m\u001b[32m growth\u001b[0m\u001b[32m,\u001b[0m\u001b[32m love\u001b[0m\u001b[32m,\u001b[0m\u001b[32m or\u001b[0m\u001b[32m de\u001b[0m\u001b[32meds\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mSome\u001b[0m\u001b[32m find\u001b[0m\u001b[32m purpose\u001b[0m\u001b[32m in\u001b[0m\u001b[32m these\u001b[0m\u001b[32m cre\u001b[0m\u001b[32meds\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mA\u001b[0m\u001b[32m subject\u001b[0m\u001b[32mive\u001b[0m\u001b[32m concept\u001b[0m\u001b[32m,\u001b[0m\u001b[32m it\u001b[0m\u001b[32m may\u001b[0m\u001b[32m be\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mY\u001b[0m\u001b[32met\u001b[0m\u001b[32m,\u001b[0m\u001b[32m each\u001b[0m\u001b[32m soul\u001b[0m\u001b[32m see\u001b[0m\u001b[32mks\u001b[0m\u001b[32m its\u001b[0m\u001b[32m dec\u001b[0m\u001b[32mree\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mIn\u001b[0m\u001b[32m the\u001b[0m\u001b[32m end\u001b[0m\u001b[32m,\u001b[0m\u001b[32m it\u001b[0m\u001b[32m's\u001b[0m\u001b[32m up\u001b[0m\u001b[32m to\u001b[0m\u001b[32m you\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mTo\u001b[0m\u001b[32m find\u001b[0m\u001b[32m your\u001b[0m\u001b[32m own\u001b[0m\u001b[32m meaning\u001b[0m\u001b[32m an\u001b[0m\u001b[32mew\u001b[0m\u001b[32m.\u001b[0m\n", + "\u001b[32mLife's meaning, a question vast,\n", + "In philosophy, it's often cast.\n", + "Personal growth, love, or a cause,\n", + "Some find meaning in life's applause.\n", + "\n", + "Spirituality, faith, or belief,\n", + "Can guide us, like a gentle relief.\n", + "Meaning may be subjective,\n", + "\u001b[0m\u001b[32mYet, in our hearts, it's subjective.\u001b[0m\n", "\n", "Translate it to French\n", - "\u001b[32mLa\u001b[0m\u001b[32m sign\u001b[0m\u001b[32mification\u001b[0m\u001b[32m de\u001b[0m\u001b[32m la\u001b[0m\u001b[32m v\u001b[0m\u001b[32mie\u001b[0m\u001b[32m,\u001b[0m\u001b[32m une\u001b[0m\u001b[32m question\u001b[0m\u001b[32m imm\u001b[0m\u001b[32mense\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mD\u001b[0m\u001b[32mans\u001b[0m\u001b[32m la\u001b[0m\u001b[32m ph\u001b[0m\u001b[32milo\u001b[0m\u001b[32msop\u001b[0m\u001b[32mh\u001b[0m\u001b[32mie\u001b[0m\u001b[32m,\u001b[0m\u001b[32m el\u001b[0m\u001b[32mle\u001b[0m\u001b[32m est\u001b[0m\u001b[32m sou\u001b[0m\u001b[32mvent\u001b[0m\u001b[32m pos\u001b[0m\u001b[32mée\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mLe\u001b[0m\u001b[32m dé\u001b[0m\u001b[32mvelop\u001b[0m\u001b[32mpe\u001b[0m\u001b[32mment\u001b[0m\u001b[32m person\u001b[0m\u001b[32mnel\u001b[0m\u001b[32m,\u001b[0m\u001b[32m l\u001b[0m\u001b[32m'\u001b[0m\u001b[32mam\u001b[0m\u001b[32mour\u001b[0m\u001b[32m ou\u001b[0m\u001b[32m les\u001b[0m\u001b[32m act\u001b[0m\u001b[32mes\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mCert\u001b[0m\u001b[32mains\u001b[0m\u001b[32m tro\u001b[0m\u001b[32mu\u001b[0m\u001b[32mvent\u001b[0m\u001b[32m un\u001b[0m\u001b[32m sens\u001b[0m\u001b[32m dans\u001b[0m\u001b[32m ces\u001b[0m\u001b[32m cré\u001b[0m\u001b[32md\u001b[0m\u001b[32mules\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mUn\u001b[0m\u001b[32m concept\u001b[0m\u001b[32m subject\u001b[0m\u001b[32mif\u001b[0m\u001b[32m,\u001b[0m\u001b[32m il\u001b[0m\u001b[32m peut\u001b[0m\u001b[32m être\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mM\u001b[0m\u001b[32mais\u001b[0m\u001b[32m chaque\u001b[0m\u001b[32m â\u001b[0m\u001b[32mme\u001b[0m\u001b[32m ch\u001b[0m\u001b[32mer\u001b[0m\u001b[32mche\u001b[0m\u001b[32m sa\u001b[0m\u001b[32m pro\u001b[0m\u001b[32mpre\u001b[0m\u001b[32m dé\u001b[0m\u001b[32mcision\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mEn\u001b[0m\u001b[32m fin\u001b[0m\u001b[32m de\u001b[0m\u001b[32m compte\u001b[0m\u001b[32m,\u001b[0m\u001b[32m c\u001b[0m\u001b[32m'\u001b[0m\u001b[32mest\u001b[0m\u001b[32m à\u001b[0m\u001b[32m vous\u001b[0m\u001b[32m,\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mDe\u001b[0m\u001b[32m tro\u001b[0m\u001b[32mu\u001b[0m\u001b[32mver\u001b[0m\u001b[32m votre\u001b[0m\u001b[32m pro\u001b[0m\u001b[32mpre\u001b[0m\u001b[32m sens\u001b[0m\u001b[32m de\u001b[0m\u001b[32m nou\u001b[0m\u001b[32mveau\u001b[0m\u001b[32m.\u001b[0m" + "\u001b[32mLa signification de la vie, une question vaste,\n", + "Dans la philosophie, elle est souvent lancée.\n", + "La croissance personnelle, l'amour, ou une cause,\n", + "Certains trouvent une signification dans la vie's applaudissement.\u001b[0m\u001b[32m\n", + "\n", + "Spiritualité, foi, ou croyance,\n", + "Pouvant nous guider, comme une douce répit.\n", + "La signification peut être subjective,\n", + "Yet, dans nos cœurs, elle est subjective.\u001b[0m" ] } ], @@ -115,11 +213,9 @@ "%%pdl\n", "text:\n", "- \"\\nSay it like a poem\\n\"\n", - "- model: ibm/granite-8b-instruct-preview-4k\n", - " platform: bam\n", + "- model: \"replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e\"\n", "- \"\\n\\nTranslate it to French\\n\"\n", - "- model: ibm/granite-8b-instruct-preview-4k\n", - " platform: bam" + "- model: \"replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e\"" ] }, { @@ -164,7 +260,7 @@ }, { "cell_type": "code", - "execution_count": 72, + "execution_count": 3, "id": "b61b2e25-72a4-4f70-ae83-40d77bed3f4f", "metadata": {}, "outputs": [ @@ -184,20 +280,18 @@ " return offsetMap;\n", "}\n", "\n", - "\u001b[32mThis\u001b[0m\u001b[32m Java\u001b[0m\u001b[32m method\u001b[0m\u001b[32m,\u001b[0m\u001b[32m `\u001b[0m\u001b[32mdeserialize\u001b[0m\u001b[32mOffset\u001b[0m\u001b[32mMap\u001b[0m\u001b[32m`,\u001b[0m\u001b[32m is\u001b[0m\u001b[32m designed\u001b[0m\u001b[32m to\u001b[0m\u001b[32m convert\u001b[0m\u001b[32m a\u001b[0m\u001b[32m JSON\u001b[0m\u001b[32m string\u001b[0m\u001b[32m into\u001b[0m\u001b[32m a\u001b[0m\u001b[32m `\u001b[0m\u001b[32mMap\u001b[0m\u001b[32m<\u001b[0m\u001b[32mString\u001b[0m\u001b[32m,\u001b[0m\u001b[32m String\u001b[0m\u001b[32m>`.\u001b[0m\u001b[32m Here\u001b[0m\u001b[32m's\u001b[0m\u001b[32m a\u001b[0m\u001b[32m break\u001b[0m\u001b[32mdown\u001b[0m\u001b[32m of\u001b[0m\u001b[32m the\u001b[0m\u001b[32m code\u001b[0m\u001b[32m:\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32m1\u001b[0m\u001b[32m.\u001b[0m\u001b[32m The\u001b[0m\u001b[32m method\u001b[0m\u001b[32m takes\u001b[0m\u001b[32m a\u001b[0m\u001b[32m single\u001b[0m\u001b[32m parameter\u001b[0m\u001b[32m,\u001b[0m\u001b[32m `\u001b[0m\u001b[32mlast\u001b[0m\u001b[32mSource\u001b[0m\u001b[32mOffset\u001b[0m\u001b[32m`,\u001b[0m\u001b[32m which\u001b[0m\u001b[32m is\u001b[0m\u001b[32m expected\u001b[0m\u001b[32m to\u001b[0m\u001b[32m be\u001b[0m\u001b[32m a\u001b[0m\u001b[32m JSON\u001b[0m\u001b[32m string\u001b[0m\u001b[32m representing\u001b[0m\u001b[32m a\u001b[0m\u001b[32m map\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32m2\u001b[0m\u001b[32m.\u001b[0m\u001b[32m It\u001b[0m\u001b[32m first\u001b[0m\u001b[32m checks\u001b[0m\u001b[32m if\u001b[0m\u001b[32m `\u001b[0m\u001b[32mlast\u001b[0m\u001b[32mSource\u001b[0m\u001b[32mOffset\u001b[0m\u001b[32m`\u001b[0m\u001b[32m is\u001b[0m\u001b[32m either\u001b[0m\u001b[32m `\u001b[0m\u001b[32mnull\u001b[0m\u001b[32m`\u001b[0m\u001b[32m or\u001b[0m\u001b[32m an\u001b[0m\u001b[32m empty\u001b[0m\u001b[32m string\u001b[0m\u001b[32m.\u001b[0m\u001b[32m If\u001b[0m\u001b[32m true\u001b[0m\u001b[32m,\u001b[0m\u001b[32m it\u001b[0m\u001b[32m initializes\u001b[0m\u001b[32m a\u001b[0m\u001b[32m new\u001b[0m\u001b[32m `\u001b[0m\u001b[32mHashMap\u001b[0m\u001b[32m`\u001b[0m\u001b[32m and\u001b[0m\u001b[32m assigns\u001b[0m\u001b[32m it\u001b[0m\u001b[32m to\u001b[0m\u001b[32m `\u001b[0m\u001b[32moffset\u001b[0m\u001b[32mMap\u001b[0m\u001b[32m`.\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32m3\u001b[0m\u001b[32m.\u001b[0m\u001b[32m If\u001b[0m\u001b[32m `\u001b[0m\u001b[32mlast\u001b[0m\u001b[32mSource\u001b[0m\u001b[32mOffset\u001b[0m\u001b[32m`\u001b[0m\u001b[32m is\u001b[0m\u001b[32m not\u001b[0m\u001b[32m `\u001b[0m\u001b[32mnull\u001b[0m\u001b[32m`\u001b[0m\u001b[32m or\u001b[0m\u001b[32m empty\u001b[0m\u001b[32m,\u001b[0m\u001b[32m it\u001b[0m\u001b[32m uses\u001b[0m\u001b[32m Jack\u001b[0m\u001b[32mson\u001b[0m\u001b[32m's\u001b[0m\u001b[32m `\u001b[0m\u001b[32mJSON\u001b[0m\u001b[32m_\u001b[0m\u001b[32mMAP\u001b[0m\u001b[32mPER\u001b[0m\u001b[32m`\u001b[0m\u001b[32m to\u001b[0m\u001b[32m deserialize\u001b[0m\u001b[32m the\u001b[0m\u001b[32m JSON\u001b[0m\u001b[32m string\u001b[0m\u001b[32m into\u001b[0m\u001b[32m a\u001b[0m\u001b[32m `\u001b[0m\u001b[32mMap\u001b[0m\u001b[32m<\u001b[0m\u001b[32mString\u001b[0m\u001b[32m,\u001b[0m\u001b[32m String\u001b[0m\u001b[32m>`\u001b[0m\u001b[32m and\u001b[0m\u001b[32m assigns\u001b[0m\u001b[32m it\u001b[0m\u001b[32m to\u001b[0m\u001b[32m `\u001b[0m\u001b[32moffset\u001b[0m\u001b[32mMap\u001b[0m\u001b[32m`.\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32m4\u001b[0m\u001b[32m.\u001b[0m\u001b[32m Finally\u001b[0m\u001b[32m,\u001b[0m\u001b[32m it\u001b[0m\u001b[32m returns\u001b[0m\u001b[32m the\u001b[0m\u001b[32m `\u001b[0m\u001b[32moffset\u001b[0m\u001b[32mMap\u001b[0m\u001b[32m`.\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mThe\u001b[0m\u001b[32m `@\u001b[0m\u001b[32mSuppressWarnings\u001b[0m\u001b[32m(\"\u001b[0m\u001b[32munchecked\u001b[0m\u001b[32m\")\u001b[0m\u001b[32m`\u001b[0m\u001b[32m annotation\u001b[0m\u001b[32m is\u001b[0m\u001b[32m used\u001b[0m\u001b[32m to\u001b[0m\u001b[32m suppress\u001b[0m\u001b[32m a\u001b[0m\u001b[32m potential\u001b[0m\u001b[32m unchecked\u001b[0m\u001b[32m warning\u001b[0m\u001b[32m that\u001b[0m\u001b[32m might\u001b[0m\u001b[32m occur\u001b[0m\u001b[32m due\u001b[0m\u001b[32m to\u001b[0m\u001b[32m the\u001b[0m\u001b[32m raw\u001b[0m\u001b[32m type\u001b[0m\u001b[32m usage\u001b[0m\u001b[32m in\u001b[0m\u001b[32m the\u001b[0m\u001b[32m `\u001b[0m\u001b[32mJSON\u001b[0m\u001b[32m_\u001b[0m\u001b[32mMAP\u001b[0m\u001b[32mPER\u001b[0m\u001b[32m.\u001b[0m\u001b[32mreadValue\u001b[0m\u001b[32m`\u001b[0m\u001b[32m method\u001b[0m\u001b[32m.\u001b[0m\u001b[32m This\u001b[0m\u001b[32m is\u001b[0m\u001b[32m because\u001b[0m\u001b[32m the\u001b[0m\u001b[32m method\u001b[0m\u001b[32m expects\u001b[0m\u001b[32m a\u001b[0m\u001b[32m `\u001b[0m\u001b[32mMap\u001b[0m\u001b[32m.\u001b[0m\u001b[32mclass\u001b[0m\u001b[32m`\u001b[0m\u001b[32m as\u001b[0m\u001b[32m the\u001b[0m\u001b[32m second\u001b[0m\u001b[32m argument\u001b[0m\u001b[32m,\u001b[0m\u001b[32m but\u001b[0m\u001b[32m the\u001b[0m\u001b[32m actual\u001b[0m\u001b[32m type\u001b[0m\u001b[32m of\u001b[0m\u001b[32m the\u001b[0m\u001b[32m map\u001b[0m\u001b[32m is\u001b[0m\u001b[32m not\u001b[0m\u001b[32m known\u001b[0m\u001b[32m at\u001b[0m\u001b[32m compile\u001b[0m\u001b[32m time\u001b[0m\u001b[32m.\u001b[0m\n", + "\u001b[32mThis Java function, `deserializeOffsetMap`, is designed to convert a JSON string into a `Map`. Here's a breakdown of what it does:\n", + "\n", + "1. It takes a single argument, `lastSourceOffset`, which is expected to be a JSON string.\n", + "2. It initializes a `Map` called `offsetMap`.\n", + "3. If `lastSourceOffset` is either `null` or an empty string, it creates a new `HashMap` and assigns it to `offsetMap`.\n", + "4. If `lastSourceOffset` is not `null` or empty, it uses Jackson's `JSON_MAPPER` to convert the JSON string into a `Map\u001b[0m\u001b[32m` and assigns it to `offsetMap`.\n", + "5. Finally, it returns the `offsetMap`.\n", + "\n", + "The `@SuppressWarnings(\"unchecked\")` annotation is used to suppress a compile-time warning about the raw use of the `Map` type. This is because the `JSON_MAPPER.readValue` method returns a `Map` of `Object` and\u001b[0m\u001b[32m `Object`, which is then cast to `Map`.\u001b[0m\n", "Evaluation:\n", "The similarity (Levenshtein) between this answer and the ground truth is:\n", - "\u001b[35m0.34468085106382984\u001b[0m" + "\u001b[35m0.3113839285714286\u001b[0m" ] } ], @@ -211,8 +305,7 @@ " read: ./ground_truth.txt\n", "text:\n", "- \"\\n${ code.source_code }\\n\"\n", - "- model: ibm/granite-8b-instruct-preview-4k\n", - " platform: bam\n", + "- model: \"replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e\"\n", " def: explanation\n", " input: |\n", " Here is some info about the location of the function in the repo.\n", @@ -254,7 +347,7 @@ }, { "cell_type": "code", - "execution_count": 73, + "execution_count": 3, "id": "dfef7096-b7a6-4966-8356-a306e701974b", "metadata": { "scrolled": true @@ -265,14 +358,29 @@ "output_type": "stream", "text": [ "How many years ago was the discoverer of the Hudson River born? Keep in mind we are in 2024.\n", - "Tho:\u001b[32mI\u001b[0m\u001b[32m need\u001b[0m\u001b[32m to\u001b[0m\u001b[32m search\u001b[0m\u001b[32m Hen\u001b[0m\u001b[32mry\u001b[0m\u001b[32m H\u001b[0m\u001b[32mudson\u001b[0m\u001b[32m,\u001b[0m\u001b[32m find\u001b[0m\u001b[32m out\u001b[0m\u001b[32m when\u001b[0m\u001b[32m he\u001b[0m\u001b[32m was\u001b[0m\u001b[32m born\u001b[0m\u001b[32m,\u001b[0m\u001b[32m then\u001b[0m\u001b[32m calculate\u001b[0m\u001b[32m how\u001b[0m\u001b[32m many\u001b[0m\u001b[32m years\u001b[0m\u001b[32m ago\u001b[0m\u001b[32m it\u001b[0m\u001b[32m was\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mAct\u001b[0m\u001b[32m:\u001b[0m\u001b[32m{\"\u001b[0m\u001b[32mname\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m \"\u001b[0m\u001b[32mSearch\u001b[0m\u001b[32m\",\u001b[0m\u001b[32m \"\u001b[0m\u001b[32marguments\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m {\"\u001b[0m\u001b[32mtopic\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m \"\u001b[0m\u001b[32mH\u001b[0m\u001b[32men\u001b[0m\u001b[32mry\u001b[0m\u001b[32m H\u001b[0m\u001b[32mudson\u001b[0m\u001b[32m\"}}\u001b[0m\u001b[32m\n", - "\u001b[0mObs: \u001b[35mHenry Hudson (c. 1565 – disappeared 23 June 1611) was an English sea explorer and navigator during the early 17th century, best known for his explorations of present-day Canada and parts of the Northeastern United States.\n", + "\u001b[32mTho: I need to search Henry Hudson, find out when he was born, and then calculate how many years ago that was.\n", + "\u001b[0m" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", + " from .autonotebook import tqdm as notebook_tqdm\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[32mAct: {\"name\": \"Search\", \"arguments\": {\"topic\": \"Henry Hudson\"}}\u001b[0m\n", + "Obs: \u001b[35mHenry Hudson (c. 1565 – disappeared 23 June 1611) was an English sea explorer and navigator during the early 17th century, best known for his explorations of present-day Canada and parts of the Northeastern United States.\n", "In 1607 and 1608, Hudson made two attempts on behalf of English merchants to find a rumoured Northeast Passage to Cathay via a route above the Arctic Circle. In 1609, he landed in North America on behalf of the Dutch East India Company and explored the region around the modern New York metropolitan area. Looking for a Northwest Passage to Asia on his ship Halve Maen (\"Half Moon\"), he sailed up the Hudson River, which was later named after him, and thereby laid the foundation for Dutch colonization of the region. His contributions to the exploration of the New World were significant and lasting. His voyages helped to establish European contact with the native peoples of North America and contributed to the development of trade and commerce. \n", "On his final expedition, while still searching for the Northwest Passage, Hudson became the first European to see Hudson Strait and the immense Hudson Bay. In 1611, after wintering on the shore of James Bay, Hudson wanted to press on to the west, but most of his crew mutinied. The mutineers cast Hudson, his son, and six others adrift; the Hudsons and their companions were never seen again.\u001b[0m\n", - "Tho:\u001b[32mH\u001b[0m\u001b[32men\u001b[0m\u001b[32mry\u001b[0m\u001b[32m H\u001b[0m\u001b[32mudson\u001b[0m\u001b[32m was\u001b[0m\u001b[32m born\u001b[0m\u001b[32m around\u001b[0m\u001b[32m \u001b[0m\u001b[32m1\u001b[0m\u001b[32m5\u001b[0m\u001b[32m6\u001b[0m\u001b[32m5\u001b[0m\u001b[32m.\u001b[0m\u001b[32m To\u001b[0m\u001b[32m find\u001b[0m\u001b[32m out\u001b[0m\u001b[32m how\u001b[0m\u001b[32m many\u001b[0m\u001b[32m years\u001b[0m\u001b[32m ago\u001b[0m\u001b[32m it\u001b[0m\u001b[32m was\u001b[0m\u001b[32m,\u001b[0m\u001b[32m I\u001b[0m\u001b[32m need\u001b[0m\u001b[32m to\u001b[0m\u001b[32m subtract\u001b[0m\u001b[32m his\u001b[0m\u001b[32m birth\u001b[0m\u001b[32m year\u001b[0m\u001b[32m from\u001b[0m\u001b[32m the\u001b[0m\u001b[32m current\u001b[0m\u001b[32m year\u001b[0m\u001b[32m,\u001b[0m\u001b[32m which\u001b[0m\u001b[32m is\u001b[0m\u001b[32m \u001b[0m\u001b[32m2\u001b[0m\u001b[32m0\u001b[0m\u001b[32m2\u001b[0m\u001b[32m4\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mAct\u001b[0m\u001b[32m:\u001b[0m\u001b[32m{\"\u001b[0m\u001b[32mname\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m \"\u001b[0m\u001b[32mCalc\u001b[0m\u001b[32m\",\u001b[0m\u001b[32m \"\u001b[0m\u001b[32marguments\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m {\"\u001b[0m\u001b[32mexpr\u001b[0m\u001b[32m\":\u001b[0m\u001b[32m \"\u001b[0m\u001b[32m2\u001b[0m\u001b[32m0\u001b[0m\u001b[32m2\u001b[0m\u001b[32m4\u001b[0m\u001b[32m -\u001b[0m\u001b[32m \u001b[0m\u001b[32m1\u001b[0m\u001b[32m5\u001b[0m\u001b[32m6\u001b[0m\u001b[32m5\u001b[0m\u001b[32m\"}}\u001b[0m\u001b[32m\n", - "\u001b[0mObs: \u001b[35m459\u001b[0m\n" + "\u001b[32mTho: Henry Hudson was born around 1565.\n", + "\u001b[0m\u001b[32mAct: {\"name\": \"Calc\", \"arguments\": {\"expr\": \"2024 - 1565\"}}\u001b[0m\n", + "Obs: \u001b[35m459\u001b[0m\n" ] } ], @@ -284,31 +392,35 @@ "- \"How many years ago was the discoverer of the Hudson River born? Keep in mind we are in 2024.\\n\"\n", "- repeat:\n", " text:\n", - " - \"Tho:\"\n", " - def: thought\n", - " model: ibm/granite-8b-instruct-preview-4k\n", - " platform: bam\n", + " model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e\n", " parameters:\n", - " stop_sequences: [\"Act:\"]\n", - " include_stop_sequence: true\n", - " - def: action\n", - " model: ibm/granite-8b-instruct-preview-4k\n", - " platform: bam\n", + " stop_sequences: \"Act:\"\n", + " temperature: 0\n", + " - def: rawAction\n", + " model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e\n", " parameters:\n", - " stop_sequences: [\"\\n\"]\n", + " stop_sequences: \"\\n\"\n", + " temperature: 0\n", + " - def: action\n", + " lang: python\n", " parser: json\n", " spec: {name: str, arguments: obj}\n", + " contribute: [context]\n", + " code:\n", + " |\n", + " result = '${ rawAction }'.replace(\"Act: \", \"\")\n", " - def: observation\n", " if: ${ action.name == \"Search\" }\n", " then:\n", " text:\n", - " - \"Obs: \"\n", + " - \"\\nObs: \"\n", " - lang: python\n", " code: |\n", " import warnings, wikipedia\n", " warnings.simplefilter(\"ignore\")\n", " try:\n", - " result = wikipedia.summary(\"${ action.arguments.topic }\", auto_suggest=False)\n", + " result = wikipedia.summary(\"${ action.arguments.topic }\")\n", " except wikipedia.WikipediaException as e:\n", " result = str(e)\n", " - \"\\n\"\n", @@ -316,11 +428,12 @@ " - if: ${ action.name == \"Calc\" }\n", " then:\n", " text:\n", - " - \"Obs: \"\n", + " - \"\\nObs: \"\n", " - lang: python\n", " code: result = ${ action.arguments.expr }\n", " - \"\\n\"\n", - " until: ${ action.name != \"Search\" }" + " until: ${ action.name != \"Search\" }\n", + "\n" ] }, { diff --git a/examples/notebooks/demonstrations.txt b/examples/notebooks/demonstrations.txt index 72d75c9c1..7503f04b9 100644 --- a/examples/notebooks/demonstrations.txt +++ b/examples/notebooks/demonstrations.txt @@ -1,4 +1,4 @@ -| + What is the elevation range for the area that the eastern sector of the Colorado orogeny extends into? Tho: I need to search Colorado orogeny, find the area that the eastern sector of the Colorado ... Act: {"name": "Search", "arguments": {"topic": "Colorado orogeny"}} @@ -18,11 +18,14 @@ Tho: Professions of Elia Kazan are director, producer, screenwriter, and actor. Act: {"name": "Finish", "arguments": {"topic": "director, screenwriter, actor"}} What is 18 + 12 x 3? +Tho: I need to call a calculator. Act: {"name": "Calc", "arguments": {"expr": "18 + 12 * 3"}} Obs: 54 Act: {"name": "Finish", "arguments": {"topic": "54"}} A total of 252 qualifying matches were played, and 723 goals were scored. What was the average number of goals per match? +Tho: I need to call a calculator. Act: {"name": "Calc", "arguments": {"expr": "723 / 252"}} Obs: 2.869047619047619 -Act: {"name": "Finish", "arguments": {"topic": "2.869047619047619"}} \ No newline at end of file +Act: {"name": "Finish", "arguments": {"topic": "2.869047619047619"}} + diff --git a/examples/notebooks/notebook.ipynb b/examples/notebooks/notebook.ipynb index 6bcb698c2..fc6930ff9 100644 --- a/examples/notebooks/notebook.ipynb +++ b/examples/notebooks/notebook.ipynb @@ -2,26 +2,17 @@ "cells": [ { "cell_type": "code", - "execution_count": 12, + "execution_count": 2, "id": "e25a6874-54d9-4167-82ed-ab2f4fdc0a6f", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "The pdl.pdl_notebook_ext extension is already loaded. To reload it, use:\n", - " %reload_ext pdl.pdl_notebook_ext\n" - ] - } - ], + "outputs": [], "source": [ "%load_ext pdl.pdl_notebook_ext" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 4, "id": "f3c62df1-0347-4711-acd7-3892cfd5df30", "metadata": {}, "outputs": [ @@ -29,7 +20,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "Hello,\u001b[32m world\u001b[0m\u001b[32m!\u001b[0m" + "Hello\n", + "\u001b[32mHello\u001b[0m" ] } ], @@ -37,17 +29,16 @@ "%%pdl\n", "description: Model call\n", "text: \n", - "- Hello,\n", - "- model: ibm/granite-34b-code-instruct\n", - " platform: bam\n", + "- \"Hello\\n\"\n", + "- model: \"replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e\"\n", " parameters:\n", - " stop_sequences: [\"!\"]\n", - " include_stop_sequence: true" + " stop_sequences: \"!\"\n", + " " ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 5, "id": "7f6c323b-ad1a-4434-8732-bc19c5c47883", "metadata": {}, "outputs": [ @@ -67,14 +58,23 @@ " return offsetMap;\n", "}\n", "\n", - "\u001b[32m\n", - "\u001b[0m\u001b[32mThe\u001b[0m\u001b[32m function\u001b[0m\u001b[32m `\u001b[0m\u001b[32mdeserialize\u001b[0m\u001b[32mOffset\u001b[0m\u001b[32mMap\u001b[0m\u001b[32m`\u001b[0m\u001b[32m takes\u001b[0m\u001b[32m a\u001b[0m\u001b[32m string\u001b[0m\u001b[32m as\u001b[0m\u001b[32m input\u001b[0m\u001b[32m and\u001b[0m\u001b[32m returns\u001b[0m\u001b[32m a\u001b[0m\u001b[32m map\u001b[0m\u001b[32m.\u001b[0m\u001b[32m It\u001b[0m\u001b[32m first\u001b[0m\u001b[32m checks\u001b[0m\u001b[32m if\u001b[0m\u001b[32m the\u001b[0m\u001b[32m input\u001b[0m\u001b[32m string\u001b[0m\u001b[32m is\u001b[0m\u001b[32m null\u001b[0m\u001b[32m or\u001b[0m\u001b[32m empty\u001b[0m\u001b[32m.\u001b[0m\u001b[32m If\u001b[0m\u001b[32m it\u001b[0m\u001b[32m is\u001b[0m\u001b[32m,\u001b[0m\u001b[32m it\u001b[0m\u001b[32m creates\u001b[0m\u001b[32m a\u001b[0m\u001b[32m new\u001b[0m\u001b[32m empty\u001b[0m\u001b[32m map\u001b[0m\u001b[32m and\u001b[0m\u001b[32m returns\u001b[0m\u001b[32m it\u001b[0m\u001b[32m.\u001b[0m\u001b[32m Otherwise\u001b[0m\u001b[32m,\u001b[0m\u001b[32m it\u001b[0m\u001b[32m uses\u001b[0m\u001b[32m the\u001b[0m\u001b[32m Jack\u001b[0m\u001b[32mson\u001b[0m\u001b[32m library\u001b[0m\u001b[32m to\u001b[0m\u001b[32m parse\u001b[0m\u001b[32m the\u001b[0m\u001b[32m input\u001b[0m\u001b[32m string\u001b[0m\u001b[32m into\u001b[0m\u001b[32m a\u001b[0m\u001b[32m map\u001b[0m\u001b[32m and\u001b[0m\u001b[32m returns\u001b[0m\u001b[32m it\u001b[0m\u001b[32m.\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32m\n", - "\u001b[0m\u001b[32mThe\u001b[0m\u001b[32m `@\u001b[0m\u001b[32mSuppressWarnings\u001b[0m\u001b[32m(\"\u001b[0m\u001b[32munchecked\u001b[0m\u001b[32m\")\u001b[0m\u001b[32m`\u001b[0m\u001b[32m annotation\u001b[0m\u001b[32m is\u001b[0m\u001b[32m used\u001b[0m\u001b[32m to\u001b[0m\u001b[32m suppress\u001b[0m\u001b[32m the\u001b[0m\u001b[32m warning\u001b[0m\u001b[32m that\u001b[0m\u001b[32m the\u001b[0m\u001b[32m type\u001b[0m\u001b[32m of\u001b[0m\u001b[32m the\u001b[0m\u001b[32m parsed\u001b[0m\u001b[32m map\u001b[0m\u001b[32m is\u001b[0m\u001b[32m not\u001b[0m\u001b[32m checked\u001b[0m\u001b[32m.\u001b[0m\u001b[32m This\u001b[0m\u001b[32m is\u001b[0m\u001b[32m because\u001b[0m\u001b[32m the\u001b[0m\u001b[32m Jack\u001b[0m\u001b[32mson\u001b[0m\u001b[32m library\u001b[0m\u001b[32m is\u001b[0m\u001b[32m used\u001b[0m\u001b[32m to\u001b[0m\u001b[32m parse\u001b[0m\u001b[32m the\u001b[0m\u001b[32m input\u001b[0m\u001b[32m string\u001b[0m\u001b[32m into\u001b[0m\u001b[32m a\u001b[0m\u001b[32m map\u001b[0m\u001b[32m,\u001b[0m\u001b[32m but\u001b[0m\u001b[32m the\u001b[0m\u001b[32m specific\u001b[0m\u001b[32m type\u001b[0m\u001b[32m of\u001b[0m\u001b[32m the\u001b[0m\u001b[32m map\u001b[0m\u001b[32m is\u001b[0m\u001b[32m not\u001b[0m\u001b[32m known\u001b[0m\u001b[32m at\u001b[0m\u001b[32m compile\u001b[0m\u001b[32m time\u001b[0m\u001b[32m.\u001b[0m\u001b[32m Therefore\u001b[0m\u001b[32m,\u001b[0m\u001b[32m the\u001b[0m\u001b[32m warning\u001b[0m\u001b[32m is\u001b[0m\u001b[32m supp\u001b[0m\u001b[32mressed\u001b[0m\u001b[32m to\u001b[0m\u001b[32m avoid\u001b[0m\u001b[32m potential\u001b[0m\u001b[32m issues\u001b[0m\u001b[32m.\u001b[0m\n", + "\u001b[32mThis Java function, `deserializeOffsetMap`, is designed to convert a JSON string into a `Map`. Here's a breakdown of what it does:\n", + "\n", + "1. It takes a single argument, `lastSourceOffset`, which is expected to be a JSON string.\n", + "\n", + "2. It initializes a `Map` called `offsetMap`.\n", + "\n", + "3. If `lastSourceOffset` is either `null` or an empty string, it creates a new `HashMap` and assigns it to `offsetMap`.\n", + "\n", + "4. If `lastSourceOffset` is not `null` or an empty string, it uses the `JSON_MAPPER` object (presumably an\u001b[0m\u001b[32m instance of `ObjectMapper` from the Jackson library) to convert the JSON string into a `Map` and assigns it to `offsetMap`.\n", + "\n", + "5. Finally, it returns the `offsetMap`.\n", + "\n", + "The `@SuppressWarnings(\"unchecked\")` annotation is used to suppress a compile-time warning about the raw use of the `Map` type. This is\u001b[0m\u001b[32m because the `JSON_MAPPER.readValue` method returns a `Map`, but the compiler doesn't know that this `Map` will be a `Map`. The `unchecked` warning is suppressed to avoid cluttering the output with this warning.\u001b[0m\n", "\n", "EVALUATION:\n", "The similarity (Levenshtein) between this answer and the ground truth is:\n", - "\u001b[35m0.9983818770226537\u001b[0m" + "\u001b[35m0.3671003717472119\u001b[0m" ] } ], @@ -89,8 +89,7 @@ " read: ./ground_truth.txt\n", "text:\n", "- \"\\n${ CODE.source_code }\\n\"\n", - "- model: ibm/granite-34b-code-instruct\n", - " platform: bam\n", + "- model: \"replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e\"\n", " def: EXPLANATION\n", " input: |\n", " Here is some info about the location of the function in the repo.\n", @@ -146,7 +145,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.3" + "version": "3.12.5" } }, "nbformat": 4, diff --git a/examples/notebooks/notebook_debug.ipynb b/examples/notebooks/notebook_debug.ipynb index bb913f60f..f94556c75 100644 --- a/examples/notebooks/notebook_debug.ipynb +++ b/examples/notebooks/notebook_debug.ipynb @@ -164,11 +164,9 @@ "description: Model call\n", "text: \n", "- Hello,\n", - "- model: ibm/granite-34b-code-instruct\n", - " platform: bam\n", + "- model: \"replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e\"\n", " parameters:\n", - " stop_sequences: [\"!\"]\n", - " include_stop_sequence: true" + " stop_sequences: \"!\"" ] }, { diff --git a/examples/notebooks/pdl.ipynb b/examples/notebooks/pdl.ipynb index 2269339bf..e6d43298f 100644 --- a/examples/notebooks/pdl.ipynb +++ b/examples/notebooks/pdl.ipynb @@ -21,13 +21,12 @@ "metadata": {}, "outputs": [], "source": [ - "! pip install prompt-declaration-language\n", "! pip install 'prompt-declaration-language[examples]'" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "id": "e25a6874-54d9-4167-82ed-ab2f4fdc0a6f", "metadata": {}, "outputs": [], @@ -47,7 +46,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 2, "id": "f3c62df1-0347-4711-acd7-3892cfd5df30", "metadata": {}, "outputs": [ @@ -56,9 +55,17 @@ "output_type": "stream", "text": [ "What is the meaning of life?\n", - "\u001b[32mThe meaning of life is a philosophical question that has been debated by many thinkers throughout history. There is no one definitive answer, as the answer may vary depending on one's personal beliefs, values, and experiences.\n", + "\u001b[32mThe meaning of life is a philosophical question that has been debated by many thinkers throughout history and is still a subject of discussion today. The answer to this question can vary greatly depending on one's personal beliefs, values, and experiences.\n", "\u001b[0m" ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Users/mvaziri/.pyenv/versions/3.12.5/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", + " from .autonotebook import tqdm as notebook_tqdm\n" + ] } ], "source": [ @@ -83,7 +90,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 3, "id": "d7149b3f", "metadata": {}, "outputs": [ @@ -93,60 +100,22 @@ "text": [ "\n", "Say it like a poem\n", - "\u001b[32mThe meaning of life, a question so profound,\n", - "A mystery that has puzzled men and women for so long,\n", - "A path that we must tread, a goal to reach,\n", - "A journey that will bring us joy and pain,\n", - "\n", - "A road that twists and turns, a fork in the road,\u001b[0m\u001b[32m\n", - "Where we must choose, which way to go,\n", - "A decision that we must make, with our souls at stake,\n", - "A choice that will shape our destiny,\n", - "\n", - "The meaning of life, a question so grand,\n", - "A goal that we must strive for, to find,\n", - "A purpose that gives our hearts meaning,\n", - "A reason to live, a\u001b[0m\u001b[32m reason to die,\n", - "\n", - "A journey that will take us far, a journey that will bring,\n", - "A new understanding of the world we live in,\n", - "A new perspective on life, a new way of thinking,\n", - "A new path to follow, a new way to live,\n", - "\n", - "The meaning of life, a question so deep,\n", - "A mystery that will never be solved,\n", - "A journey that will\u001b[0m\u001b[32m take us far, a journey that will bring,\n", - "A new understanding of the world we live in,\n", - "\n", - "A road that twists and turns, a fork in the road,\n", - "Where we must choose, which way to go,\n", - "A decision that we must make, with our souls at stake,\n", - "A choice that will shape our destiny\u001b[0m\u001b[32m,\n", - "\n", - "The meaning of life, a question so grand,\n", - "A goal that we must strive for, to find,\n", - "A purpose that gives our hearts meaning,\n", - "A reason to live, a reason to die,\n", - "\n", - "A journey that will take us far, a journey that will bring,\n", - "A new understanding of the world we live in,\n", - "A new perspective on life, a new way of thinking,\n", - "A new\u001b[0m\u001b[32m path to follow, a new way to live,\n", - "\n", - "The meaning of life, a question so deep,\n", - "A mystery that will never be solved,\n", - "A journey that will take us far, a journey that will bring,\n", - "A new understanding of the world we live in,\n", - "\n", - "A road that twists and turns, a fork in the road,\n", - "Where we must choose, which way to go\u001b[0m\u001b[32m,\n", - "A decision that we must make, with our souls at stake,\n", - "A choice that will shape our destiny,\n", - "\n", - "The meaning of life, a question\u001b[0m\n", + "\u001b[32mThe meaning of life,\n", + "A question that we all ask,\n", + "A mystery that still defies,\n", + "The answer that we all seek.\n", + "It's a question that's been asked,\n", + "Throughout history, by many,\n", + "And yet, it remains,\n", + "A mystery that we'll never know.\n", + "But, we can try to\u001b[0m\u001b[32m find,\n", + "The meaning of life,\n", + "And in doing so,\n", + "We can find our own way.\n", + "\u001b[0m\n", "\n", "What is the most important verse in this poem?\n", - "\u001b[32mThe most important verse in this poem is the first one: \"The meaning of life, a question so profound.\" This line sets the tone for the entire poem and emphasizes the central theme of the question of what gives life meaning. It also highlights the idea that the answer to this question is not straightforward\u001b[0m\u001b[32m and may vary depending on one's personal beliefs and experiences.\n", + "\u001b[32mThe most important verse in this poem is \"But, we can try to find, The meaning of life.\" This verse emphasizes the importance of trying to find the meaning of life, even though it may still be a mystery. It suggests that the search for meaning is an ongoing process, and that we can each find our own\u001b[0m\u001b[32m way to discover it.\n", "\u001b[0m" ] } @@ -172,7 +141,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 4, "id": "455b2dbc-69fb-4164-9b8b-5817b3f33e9b", "metadata": {}, "outputs": [ @@ -194,7 +163,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "\u001b[32mAPR stands for Annual Percentage Rate. It is a measure of the total cost of borrowing money, including interest and fees, expressed as a yearly rate. It is commonly used in the lending industry to compare the cost of different loans and credit products.\n", + "\u001b[32mAPR stands for Annual Percentage Rate, which is a measure of the total cost of borrowing money. It is the total amount of interest that a borrower pays over the life of a loan, expressed as a percentage of the loan amount. APR includes both the interest rate and any fees or charges associated with the loan, such as orig\u001b[0m\u001b[32mination fees or prepayment penalties. It is a useful tool for comparing the cost of different loans and for understanding the true cost of borrowing money.\n", "\u001b[0m\n", "\n" ] @@ -203,14 +172,29 @@ "name": "stdin", "output_type": "stream", "text": [ - ">>> Say it like I'm 5 years old\n" + ">>> say it like a poem\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "\u001b[32mThe meaning of life is like a big, big, big question mark. It's a question that has been asked for as long as people can remember, and it's still a question that people don't always know the answer to. Some people think the answer is to have fun and make friends, while others think the answer is to work hard\u001b[0m\u001b[32m and be smart. But no matter what the answer is, the question of what gives life meaning is a question that will always be with us.\n", + "\u001b[32mAPR stands for Annual Percentage Rate,\n", + "A measure of the total cost of borrowing,\n", + "It's the total amount of interest you pay,\n", + "Over the life of your loan, expressed in percentage.\n", + "APR includes fees and charges,\n", + " origination fees, prepayment penalties, and more,\n", + "It's a useful\u001b[0m\u001b[32m tool for comparing loans,\n", + "And for understanding the true cost of borrowing.\n", + "But remember, not all loans are created equal,\n", + "APR doesn't tell the whole story,\n", + "It's important to read the fine print,\n", + "And understand all the terms and conditions.\n", + "So, before you sign on the dotted line,\n", + "Make sure you understand what you're getting,\n", + "APR is just\u001b[0m\u001b[32m one of many factors,\n", + "To consider when choosing a loan.\n", "\u001b[0m\n", "\n" ] @@ -226,7 +210,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "\u001b[32mThank you for chatting with me! If you have any more questions or need further assistance, feel free to ask.\n", + "\u001b[32mThank you for using my services. If you have any further questions or need additional assistance, please don't hesitate to ask.\n", "\u001b[0m" ] } @@ -278,7 +262,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 5, "id": "7f6c323b-ad1a-4434-8732-bc19c5c47883", "metadata": {}, "outputs": [ @@ -298,18 +282,18 @@ " return offsetMap;\n", "}\n", "\n", - "\u001b[32mThe function `deserializeOffsetMap` is a method that takes a string `lastSourceOffset` as input and returns a `Map` of `String` keys and `String` values. The function is used to deserialize a JSON string into a `Map` object.\n", + "\u001b[32mThe code is a method in the `OffsetUtil` class that takes a string `lastSourceOffset` as input and returns a `Map` of `String` keys and `String` values. The method is annotated with `@SuppressWarnings(\"unchecked\")` to suppress a warning about the unchecked conversion of the JSON string to a `Map` object.\n", " \n", "\n", - " The function first checks if the `lastSourceOffset` is null or empty.\u001b[0m\u001b[32m If it is, it creates a new `HashMap` object and assigns it to the `offsetMap` variable. If the `lastSourceOffset` is not null or empty, the function uses the `JSON_MAPPER` object to read the JSON string and deserialize it into a `Map` object. The `JSON_MAPPER` object is assumed to be a pre-defined\u001b[0m\u001b[32m object that is used for JSON serialization and deserialization.\n", + " The method first checks if `\u001b[0m\u001b[32mlastSourceOffset` is `null` or empty. If it is, it creates a new empty `HashMap` and assigns it to the `offsetMap` variable. If `lastSourceOffset` is not `null` or empty, it uses the `JSON_MAPPER` object to deserialize the JSON string into a `Map` object. The `JSON_MAPPER` object\u001b[0m\u001b[32m is assumed to be a pre-defined object that can deserialize JSON strings into Java objects.\n", " \n", "\n", - " Finally, the function returns the `offsetMap` object.\n", + " Finally, the method returns the `offsetMap` object.\n", "\u001b[0m\n", "\n", "EVALUATION:\n", "The similarity (Levenshtein) between this answer and the ground truth is:\n", - "\u001b[35m0.31163434903047094\u001b[0m" + "\u001b[35m0.3046875\u001b[0m" ] } ], diff --git a/examples/react/demonstrations.txt b/examples/react/demonstrations.txt index f073befea..14ca31ad8 100644 --- a/examples/react/demonstrations.txt +++ b/examples/react/demonstrations.txt @@ -1,4 +1,4 @@ -| + What is the elevation range for the area that the eastern sector of the Colorado orogeny extends into? Tho: I need to search Colorado orogeny, find the area that the eastern sector of the Colorado ... Act: {"name": "Search", "arguments": {"topic": "Colorado orogeny"}} @@ -18,13 +18,16 @@ Tho: Professions of Elia Kazan are director, producer, screenwriter, and actor. Act: {"name": "Finish", "arguments": {"topic": "director, screenwriter, actor"}} What is 18 + 12 x 3? +Tho: I need to call a calculator. Act: {"name": "Calc", "arguments": {"expr": "18 + 12 * 3"}} Obs: 54 Act: {"name": "Finish", "arguments": {"topic": "54"}} A total of 252 qualifying matches were played, and 723 goals were scored. What was the average number of goals per match? +Tho: I need to call a calculator. Act: {"name": "Calc", "arguments": {"expr": "723 / 252"}} Obs: 2.869047619047619 -Act: {"name": "Finish", "arguments": {"topic": "2.869047619047619"}}" +Act: {"name": "Finish", "arguments": {"topic": "2.869047619047619"}} + diff --git a/examples/sdk/hello.pdl b/examples/sdk/hello.pdl index 221c505d3..ba88cc7aa 100644 --- a/examples/sdk/hello.pdl +++ b/examples/sdk/hello.pdl @@ -1,9 +1,5 @@ text: -- Hello, -- model: ibm/granite-34b-code-instruct - platform: bam +- "Hello\n" +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: - stop_sequences: - - '!' - include_stop_sequence: true - + stop_sequences: '!' diff --git a/examples/sdk/hello_dict.py b/examples/sdk/hello_dict.py index a1ce9651e..2f537074f 100644 --- a/examples/sdk/hello_dict.py +++ b/examples/sdk/hello_dict.py @@ -2,11 +2,10 @@ hello = { "text": [ - "Hello,", + "Hello\n", { - "model": "ibm/granite-34b-code-instruct", - "platform": "bam", - "parameters": {"stop_sequences": ["!"], "include_stop_sequence": True}, + "model": "replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e", + "parameters": {"stop_sequences": "!"}, }, ] } diff --git a/examples/sdk/hello_prog.py b/examples/sdk/hello_prog.py index 73c4542ff..ad094422b 100644 --- a/examples/sdk/hello_prog.py +++ b/examples/sdk/hello_prog.py @@ -4,11 +4,11 @@ hello = Program( TextBlock( text=[ - "Hello,", + "Hello\n", LitellmModelBlock( - model="watsonx/ibm/granite-34b-code-instruct", + model="replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e", parameters=LitellmParameters( - stop=["!"], include_stop_sequence=True # pyright: ignore + stop_sequences="!" # pyright: ignore ), ), ] diff --git a/examples/sdk/hello_str.py b/examples/sdk/hello_str.py index 4d521076f..315ee82ba 100644 --- a/examples/sdk/hello_str.py +++ b/examples/sdk/hello_str.py @@ -2,12 +2,10 @@ HELLO = """ text: -- Hello, -- model: watsonx/ibm/granite-34b-code-instruct +- "Hello\n" +- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: - stop: - - '!' - include_stop_sequence: true + stop_sequences: '!' """ diff --git a/examples/talk/11-sdg.pdl b/examples/talk/11-sdg.pdl index 7fe1dce08..2ac8c8887 100644 --- a/examples/talk/11-sdg.pdl +++ b/examples/talk/11-sdg.pdl @@ -1,7 +1,6 @@ -description: Real-world Synthetic Data Generation (SDG) pipeline defs: teacher_sys_prompt: You are a very knowledgeable AI Assistant that will faithfully assist the user with their task. - teacher_model: watsonx/mistralai/mixtral-8x7b-instruct-v01 + teacher_model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e teacher_template: function: sys_prompt: str @@ -68,8 +67,8 @@ defs: model: ${teacher_model} input: ${teacher_input} parameters: - stop_sequences: ["${teacher_stop_token}"] - include_stop_sequence: false + temperature: 0 + stop_sequences: "${teacher_stop_token}" max_new_tokens: ${prompt_data.max_new_tokens} parser: regex: '### Question [0-9]+:\s*([^#\n]+)' @@ -157,9 +156,9 @@ defs: model: ${teacher_model} input: ${teacher_input} parameters: - stop_sequences: ["${teacher_stop_token}"] - include_stop_sequence: false + stop_sequences: "${teacher_stop_token}" max_new_tokens: ${prompt_data.max_new_tokens} + temperature: 0 parser: spec: { "rating": str } # regex: "Rating.*\\[\\[(?P\\d+\\.?\\d*)\\]\\]" @@ -191,7 +190,7 @@ defs: filtered: lang: python code: | # keep only if "keep" column is non-zero - result = [p["question"] for p in ${list_of_pairs} if p["keep"]] + result = [p["question"] for p in ${ list_of_pairs } if p["keep"]] - ${filtered} @@ -252,9 +251,9 @@ defs: model: ${teacher_model} input: ${teacher_input} parameters: - stop_sequences: ${ [teacher_stop_token] + prompt_data.additional_stop_tokens } - include_stop_sequence: false + stop_sequences: ${ ([teacher_stop_token] + prompt_data.additional_stop_tokens) | join(',') } max_new_tokens: ${prompt_data.max_new_tokens} + temperature: 0 parsed_answer: lang: python code: | # parse model output @@ -339,9 +338,9 @@ defs: model: ${teacher_model} input: ${teacher_input} parameters: - stop_sequences: ["${teacher_stop_token}"] - include_stop_sequence: false + stop_sequences: "${teacher_stop_token}" max_new_tokens: ${prompt_data.max_new_tokens} + temperature: 0 parser: spec: { "rating": str } regex: 'Rating.*\[\[(?P\d+\.?\d*)\]\]' @@ -405,3 +404,4 @@ text: - call: filter_question_answer_pair args: qa_pairs: ${qa_pairs} + diff --git a/examples/talk/3-def-use.pdl b/examples/talk/3-def-use.pdl index b157f4d03..7ba93f278 100644 --- a/examples/talk/3-def-use.pdl +++ b/examples/talk/3-def-use.pdl @@ -1,6 +1,6 @@ description: Variable def and use, model input text: -- "Hello,\n" +- "Hello\n" - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e def: name parameters: diff --git a/examples/teacher/teacher.pdl b/examples/teacher/teacher.pdl index 743684a20..2ac8c8887 100644 --- a/examples/teacher/teacher.pdl +++ b/examples/teacher/teacher.pdl @@ -1,6 +1,6 @@ defs: teacher_sys_prompt: You are a very knowledgeable AI Assistant that will faithfully assist the user with their task. - teacher_model: watsonx/mistralai/mixtral-8x7b-instruct-v01 + teacher_model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e teacher_template: function: sys_prompt: str @@ -67,8 +67,8 @@ defs: model: ${teacher_model} input: ${teacher_input} parameters: - stop_sequences: ["${teacher_stop_token}"] - include_stop_sequence: false + temperature: 0 + stop_sequences: "${teacher_stop_token}" max_new_tokens: ${prompt_data.max_new_tokens} parser: regex: '### Question [0-9]+:\s*([^#\n]+)' @@ -156,9 +156,9 @@ defs: model: ${teacher_model} input: ${teacher_input} parameters: - stop_sequences: ["${teacher_stop_token}"] - include_stop_sequence: false + stop_sequences: "${teacher_stop_token}" max_new_tokens: ${prompt_data.max_new_tokens} + temperature: 0 parser: spec: { "rating": str } # regex: "Rating.*\\[\\[(?P\\d+\\.?\\d*)\\]\\]" @@ -190,7 +190,7 @@ defs: filtered: lang: python code: | # keep only if "keep" column is non-zero - result = [p["question"] for p in ${list_of_pairs} if p["keep"]] + result = [p["question"] for p in ${ list_of_pairs } if p["keep"]] - ${filtered} @@ -251,9 +251,9 @@ defs: model: ${teacher_model} input: ${teacher_input} parameters: - stop_sequences: ${ [teacher_stop_token] + prompt_data.additional_stop_tokens } - include_stop_sequence: false + stop_sequences: ${ ([teacher_stop_token] + prompt_data.additional_stop_tokens) | join(',') } max_new_tokens: ${prompt_data.max_new_tokens} + temperature: 0 parsed_answer: lang: python code: | # parse model output @@ -338,9 +338,9 @@ defs: model: ${teacher_model} input: ${teacher_input} parameters: - stop_sequences: ["${teacher_stop_token}"] - include_stop_sequence: false + stop_sequences: "${teacher_stop_token}" max_new_tokens: ${prompt_data.max_new_tokens} + temperature: 0 parser: spec: { "rating": str } regex: 'Rating.*\[\[(?P\d+\.?\d*)\]\]' @@ -404,3 +404,4 @@ text: - call: filter_question_answer_pair args: qa_pairs: ${qa_pairs} + diff --git a/examples/tutorial/calling_llm.pdl b/examples/tutorial/calling_llm.pdl index f06960ac4..82053ee3e 100644 --- a/examples/tutorial/calling_llm.pdl +++ b/examples/tutorial/calling_llm.pdl @@ -1,6 +1,6 @@ description: Hello world calling a model text: -- Hello, +- "Hello\n" - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: decoding_method: greedy diff --git a/examples/tutorial/model_chaining.pdl b/examples/tutorial/model_chaining.pdl index e295b6fb1..9c067db0c 100644 --- a/examples/tutorial/model_chaining.pdl +++ b/examples/tutorial/model_chaining.pdl @@ -1,6 +1,6 @@ description: Model chaining text: -- Hello, +- "Hello\n" - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e parameters: stop_sequences: "!" From 1852f102d079d0fe729eabc5ab2b29597e0ebf30 Mon Sep 17 00:00:00 2001 From: Mandana Vaziri Date: Thu, 17 Oct 2024 21:02:13 -0400 Subject: [PATCH 20/24] updates Signed-off-by: Mandana Vaziri --- .github/workflows/run-examples.yml | 1 + README.md | 2 +- docs/README.md | 2 +- examples/cldk/cldk-assistant.pdl | 2 +- examples/code/code-eval.pdl | 2 + examples/code/code-json.pdl | 2 + examples/code/code.pdl | 4 +- examples/react/multi-agent.pdl | 21 --- examples/talk/10-multi-agent.pdl | 22 ---- examples/talk/{11-sdg.pdl => 10-sdg.pdl} | 0 .../talk/{12-repeat.pdl => 11-repeat.pdl} | 0 examples/talk/def-use.pdl | 13 -- examples/talk/react_fun.pdl | 123 ------------------ examples/tutorial/conditionals_loops.pdl | 2 +- src/pdl/pdl_ast.py | 6 +- tests/results/examples/chatbot/chatbot.result | 4 +- tests/results/examples/code/code-eval.result | 10 +- tests/results/examples/code/code-json.result | 2 +- tests/results/examples/code/code.result | 9 +- tests/results/examples/demo/3-weather.result | 3 +- .../results/examples/demo/4-translator.result | 4 +- tests/results/examples/fibonacci/fib.result | 50 +++---- .../examples/granite/multi_round_chat.result | 42 ++---- .../examples/granite/single_round_chat.result | 4 +- .../examples/hello/hello-def-use.result | 5 +- .../hello/hello-model-chaining.result | 7 +- .../examples/hello/hello-model-input.result | 2 +- .../examples/hello/hello-parser-regex.result | 2 +- .../examples/hello/hello-roles-array.result | 68 +++++----- tests/results/examples/hello/hello.result | 3 +- tests/results/examples/react/demo.result | 41 ++++++ tests/results/examples/react/wikipedia.result | 41 ++++-- tests/results/examples/sdk/hello.result | 3 +- tests/results/examples/talk/1-hello.result | 3 +- tests/results/examples/talk/11-repeat.result | 8 ++ .../examples/talk/2-model-chaining.result | 5 +- tests/results/examples/talk/3-def-use.result | 5 +- tests/results/examples/talk/4-function.result | 4 +- .../results/examples/talk/5-code-eval.result | 10 +- .../results/examples/talk/6-code-json.result | 2 +- .../examples/talk/7-chatbot-roles.result | 6 +- tests/results/examples/talk/9-react.result | 41 ++++-- .../examples/tutorial/calling_llm.result | 3 +- .../tutorial/calling_llm_with_input.result | 3 +- .../tutorial/conditionals_loops.result | 21 +-- .../examples/tutorial/data_block.result | 2 +- .../tutorial/function_definition.result | 4 +- .../tutorial/grouping_definitions.result | 4 +- .../results/examples/tutorial/include.result | 45 ++----- .../examples/tutorial/model_chaining.result | 5 +- .../tutorial/muting_block_output.result | 2 +- .../examples/tutorial/variable_def_use.result | 4 +- tests/results/examples/weather/weather.result | 3 +- tests/test_examples_run.py | 7 +- 54 files changed, 297 insertions(+), 392 deletions(-) delete mode 100644 examples/react/multi-agent.pdl delete mode 100644 examples/talk/10-multi-agent.pdl rename examples/talk/{11-sdg.pdl => 10-sdg.pdl} (100%) rename examples/talk/{12-repeat.pdl => 11-repeat.pdl} (100%) delete mode 100644 examples/talk/def-use.pdl delete mode 100644 examples/talk/react_fun.pdl create mode 100644 tests/results/examples/react/demo.result create mode 100644 tests/results/examples/talk/11-repeat.result diff --git a/.github/workflows/run-examples.yml b/.github/workflows/run-examples.yml index 58d5aa751..42f68fa59 100644 --- a/.github/workflows/run-examples.yml +++ b/.github/workflows/run-examples.yml @@ -44,4 +44,5 @@ jobs: WATSONX_PROJECT_ID: ${{ secrets.WATSONX_PROJECT_ID }} WATSONX_APIKEY: ${{ secrets.WATSONX_APIKEY }} WATSONX_URL: ${{ secrets.WATSONX_URL }} + REPLICATE_API_TOKEN: ${{ secrets.REPLICATE_API_TOKEN }} run: py.test -v --capture=tee-sys tests/test_examples_run.py diff --git a/README.md b/README.md index dbc97216f..0a4c98d7c 100644 --- a/README.md +++ b/README.md @@ -436,7 +436,7 @@ This is similar to a spreadsheet for tabular data, where data is in the forefron ## Additional Notes When using Granite models, we use the following defaults for model parameters (except `granite-20b-code-instruct-r1.1`): - - `decoding_method`: `greedy` + - `decoding_method`: `greedy`, (`temperature`: 0) - `max_new_tokens`: 1024 - `min_new_tokens`: 1 - `repetition_penalty`: 1.05 diff --git a/docs/README.md b/docs/README.md index 44308d49a..0a3de7421 100644 --- a/docs/README.md +++ b/docs/README.md @@ -441,7 +441,7 @@ This is similar to a spreadsheet for tabular data, where data is in the forefron ## Additional Notes When using Granite models, we use the following defaults for model parameters (except `granite-20b-code-instruct-r1.1`): - - `decoding_method`: `greedy` + - `decoding_method`: `greedy`, (`temperature`: 0) - `max_new_tokens`: 1024 - `min_new_tokens`: 1 - `repetition_penalty`: 1.05 diff --git a/examples/cldk/cldk-assistant.pdl b/examples/cldk/cldk-assistant.pdl index 90b14a227..5e7f6a7d2 100644 --- a/examples/cldk/cldk-assistant.pdl +++ b/examples/cldk/cldk-assistant.pdl @@ -140,7 +140,7 @@ text: parameters: stop_sequences: "Question" - include_stop_sequence: false + temperature: 0 - "\n\n***Executing the above PDL code:\n\n" - lang: python contribute: [result] diff --git a/examples/code/code-eval.pdl b/examples/code/code-eval.pdl index 074ce0081..c4595f551 100644 --- a/examples/code/code-eval.pdl +++ b/examples/code/code-eval.pdl @@ -20,6 +20,8 @@ text: Explain the following code: ``` ${ CODE.source_code }``` + parameters: + temperature: 0 - | diff --git a/examples/code/code-json.pdl b/examples/code/code-json.pdl index 328aa8387..095117b00 100644 --- a/examples/code/code-json.pdl +++ b/examples/code/code-json.pdl @@ -21,6 +21,8 @@ text: Explain the following code: ``` ${ CODE.source_code }``` + parameters: + temperature: 0 - def: EVAL contribute: [] lang: python diff --git a/examples/code/code.pdl b/examples/code/code.pdl index d1a3320de..4fdae9ca3 100644 --- a/examples/code/code.pdl +++ b/examples/code/code.pdl @@ -17,4 +17,6 @@ text: Explain the following code: ``` - ${ CODE.source_code }``` \ No newline at end of file + ${ CODE.source_code }``` + parameters: + temperature: 0 \ No newline at end of file diff --git a/examples/react/multi-agent.pdl b/examples/react/multi-agent.pdl deleted file mode 100644 index 7973c612f..000000000 --- a/examples/react/multi-agent.pdl +++ /dev/null @@ -1,21 +0,0 @@ -text: -- include: ./react_fun.pdl -- defs: - question: How many years ago was the discoverer of the Hudson River born? -- def: proposed - call: react - args: - question: ${ question } - model: replicate/ibm-granite/granite-20b-code-instruct-8k -- "\n\n----- Verifying answer... -----\n\n" -- def: verified - call: react - args: - question: ${ question } - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e -- "\n" -- if: ${ proposed.split('Act:') | last == verified.split('Act:') | last } - then: - Answer is correct! - else: - Answer is incorrect! diff --git a/examples/talk/10-multi-agent.pdl b/examples/talk/10-multi-agent.pdl deleted file mode 100644 index 80eecdc1e..000000000 --- a/examples/talk/10-multi-agent.pdl +++ /dev/null @@ -1,22 +0,0 @@ -text: -- include: ./react_fun.pdl -- defs: - question: When was the discoverer of the Hudson River born? -- def: proposed - call: react - args: - question: ${ question } - model: ibm/granite-34b-code-instruct - -- "\n\n----- Verifying answer... -----\n\n" -- def: verified - call: react - args: - question: ${ question } - model: ibm/granite-8b-instruct-preview-4k -- "\n" -- if: ${ proposed.split('Act:') | last == verified.split('Act:') | last } - then: - Answer is correct! - else: - Answer is incorrect! diff --git a/examples/talk/11-sdg.pdl b/examples/talk/10-sdg.pdl similarity index 100% rename from examples/talk/11-sdg.pdl rename to examples/talk/10-sdg.pdl diff --git a/examples/talk/12-repeat.pdl b/examples/talk/11-repeat.pdl similarity index 100% rename from examples/talk/12-repeat.pdl rename to examples/talk/11-repeat.pdl diff --git a/examples/talk/def-use.pdl b/examples/talk/def-use.pdl deleted file mode 100644 index 230f2cd3d..000000000 --- a/examples/talk/def-use.pdl +++ /dev/null @@ -1,13 +0,0 @@ -description: Variable def and use, model input -text: -- Hello, -- model: ibm/granite-34b-code-instruct - platform: bam - def: name - parameters: - stop_sequences: ["!"] - include_stop_sequence: false -- "\n" -- model: ibm/granite-20b-multilingual - input: - - "Translate the word '${ name | trim }' to French\n" diff --git a/examples/talk/react_fun.pdl b/examples/talk/react_fun.pdl deleted file mode 100644 index 68677b2a2..000000000 --- a/examples/talk/react_fun.pdl +++ /dev/null @@ -1,123 +0,0 @@ -description: Function definition for react -defs: - react_inner: - function: - examples: [str] - question: str - model: str - return: - text: - - for: - ex: ${ examples } - repeat: - "${ ex }\n" - - "\n" - - ${ question } - - "\n" - - def: prev_action - contribute: [] - data: none - - def: exit - contribute: [] - data: False - - repeat: - text: - - def: thought - model: ${ model } - platform: bam - parameters: - stop_sequences: - - "Act:" - include_stop_sequence: true - - def: action - model: ${ model } - platform: bam - parameters: - stop_sequences: - - "\n" - parser: json - spec: {name: str, arguments: obj} - - if: ${ action != prev_action} - then: - - def: observation - if: ${ action.name == "Search" } - then: - text: - - "Obs: " - - lang: python - code: | - import warnings, wikipedia - warnings.simplefilter("ignore") - try: - result = wikipedia.summary("${ action.arguments.topic }") - except wikipedia.WikipediaException as e: - result = str(e) - - "\n" - else: - - if: ${ action.name == "Calc" } - then: - text: - - "Obs: " - - lang: python - code: result = ${ action.arguments.expr } - - "\n" - else: - def: exit - contribute: [] - data: True - - def: prev_action - contribute: [] - data: ${ action } - until: ${ action.name == "Finish" or exit } - - react: - function: - question: str - model: str - return: - - defs: - examples: - array: - - text: - | - What is the elevation range for the area that the eastern sector of the Colorado orogeny extends into? - Tho: I need to search Colorado orogeny, find the area that the eastern sector of the Colorado ... - Act: {"name": "Search", "arguments": {"topic": "Colorado orogeny"}} - Obs: The Colorado orogeny was an episode of mountain building (an orogeny) ... - Tho: It does not mention the eastern sector. So I need to look up eastern sector. - Tho: High Plains rise in elevation from around 1,800 to 7,000 ft, so the answer is 1,800 to 7,000 ft. - Act: {"name": "Finish", "arguments": {"topic": "1,800 to 7,000 ft"}} - - - text: - | - What profession does Nicholas Ray and Elia Kazan have in common? - Tho: I need to search Nicholas Ray and Elia Kazan, find their professions, then find the profession they have in common. - Act: {"name": "Search", "arguments": {"topic": "Nicholas Ray"}} - Obs: Nicholas Ray (born Raymond Nicholas Kienzle Jr., August 7, 1911 - June 16, 1979) was an American film director, screenwriter, and actor best known for the 1955 film Rebel Without a Cause. - Tho: Professions of Nicholas Ray are director, screenwriter, and actor. I need to search Elia Kazan next and find his professions. - Act: {"name": "Search", "arguments": {"topic": "Elia Kazan"}} - Obs: Elia Kazan was an American film and theatre director, producer, screenwriter and actor. - Tho: Professions of Elia Kazan are director, producer, screenwriter, and actor. So profession Nicholas Ray and Elia Kazan have in common is director, screenwriter, and actor. - Act: {"name": "Finish", "arguments": {"topic": "director, screenwriter, actor"}} - - - text: - | - What is 18 + 12 x 3? - Act: {"name": "Calc", "arguments": {"expr": "18 + 12 * 3"}} - Obs: 54 - Act: {"name": "Finish", "arguments": {"topic": "54"}} - - - text: - | - A total of 252 qualifying matches were played, and 723 goals were scored. What was the average number of goals per match? - Act: {"name": "Calc", "arguments": {"expr": "723 / 252"}} - Obs: 2.869047619047619 - Act: {"name": "Finish", "arguments": {"topic": "2.869047619047619"}} - - call: react_inner - args: - pdl_context: [] - examples: ${ examples } - question: ${ question } - model: ${ model } - - diff --git a/examples/tutorial/conditionals_loops.pdl b/examples/tutorial/conditionals_loops.pdl index a7e1e194c..78b767b4d 100644 --- a/examples/tutorial/conditionals_loops.pdl +++ b/examples/tutorial/conditionals_loops.pdl @@ -5,7 +5,7 @@ text: contribute: [context] - repeat: text: - - model: watsonx/ibm/granite-13b-chat-v2 + - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e - read: def: eval message: "\nIs this a good answer[yes/no]?\n" diff --git a/src/pdl/pdl_ast.py b/src/pdl/pdl_ast.py index 2a78348bd..6d9c9e55f 100644 --- a/src/pdl/pdl_ast.py +++ b/src/pdl/pdl_ast.py @@ -620,6 +620,7 @@ def set_default_granite_model_parameters( ) -> dict[str, Any]: if parameters is None: parameters = {} + if "decoding_method" not in parameters: parameters["decoding_method"] = ( DECODING_METHOD # pylint: disable=attribute-defined-outside-init @@ -649,7 +650,10 @@ def set_default_granite_model_parameters( parameters["top_p"] = ( TOP_P_SAMPLING # pylint: disable=attribute-defined-outside-init ) - if "granite-3b" in model_id or "granite-8b" in model_id: + if "granite-3.0" in model_id: + if "temperature" not in parameters or parameters["temperature"] is None: + parameters["temperature"] = (0) # setting to decoding greedy + if "roles" not in parameters: parameters["roles"] = { "system": { diff --git a/tests/results/examples/chatbot/chatbot.result b/tests/results/examples/chatbot/chatbot.result index b18e9f544..a76e79640 100644 --- a/tests/results/examples/chatbot/chatbot.result +++ b/tests/results/examples/chatbot/chatbot.result @@ -1,3 +1 @@ -What is APR? -Annual Percentage Rate (APR) is the total cost of borrowing money, expressed as a percentage. It includes the interest rate and any additional fees or charges associated with the loan. APR is used to compare different loan offers and to understand the true cost of borrowing money over time. - +APR stands for Annual Percentage Rate. It is the annual interest rate charged for borrowing or earned through an investment, and it represents the actual yearly cost of funds over the term of a loan. It includes any fees or additional costs associated with the transaction. diff --git a/tests/results/examples/code/code-eval.result b/tests/results/examples/code/code-eval.result index c9e156623..044b0d34f 100644 --- a/tests/results/examples/code/code-eval.result +++ b/tests/results/examples/code/code-eval.result @@ -10,11 +10,15 @@ public static Map deserializeOffsetMap(String lastSourceOffset) return offsetMap; } +This Java method, `deserializeOffsetMap`, is used to deserialize a JSON string into a `Map`. Here's a breakdown of the code: -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. +1. The method takes a single parameter, `lastSourceOffset`, which is expected to be a JSON string. +2. It first checks if `lastSourceOffset` is either `null` or an empty string. If true, it initializes an empty `HashMap` and assigns it to `offsetMap`. +3. If `lastSourceOffset` is not `null` or empty, it uses the `JSON_MAPPER` object (presumably an instance of `ObjectMapper` from the Jackson library) to deserialize the JSON string into a `Map`. The `readValue` method is used for this purpose, with `Map.class` as the second argument, which specifies the expected type of the deserialized object. +4. Finally, the method returns the `offsetMap`, which now contains the deserialized data. -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. +The `@SuppressWarnings("unchecked")` annotation is used to suppress a potential unchecked warning that might occur due to the raw `Map` type used in the method signature. EVALUATION: The similarity (Levenshtein) between this answer and the ground truth is: -0.9967637540453075 +0.30421982335623154 diff --git a/tests/results/examples/code/code-json.result b/tests/results/examples/code/code-json.result index 09c640713..4025a6142 100644 --- a/tests/results/examples/code/code-json.result +++ b/tests/results/examples/code/code-json.result @@ -1 +1 @@ -{"input": {"source_code": "@SuppressWarnings(\"unchecked\")\npublic static Map deserializeOffsetMap(String lastSourceOffset) throws IOException {\n Map offsetMap;\n if (lastSourceOffset == null || lastSourceOffset.isEmpty()) { \n offsetMap = new HashMap<>(); \n } else {\n offsetMap = JSON_MAPPER.readValue(lastSourceOffset, Map.class); \n }\n return offsetMap;\n}\n", "repo_info": {"repo": "streamsets/datacollector", "path": "stagesupport/src/main/java/com/.../OffsetUtil.java", "function_name": "OffsetUtil.deserializeOffsetMap"}}, "output": "\nThe 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.\n\nThe `@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.", "metric": 0.9967637540453075} +{"input": {"source_code": "@SuppressWarnings(\"unchecked\")\npublic static Map deserializeOffsetMap(String lastSourceOffset) throws IOException {\n Map offsetMap;\n if (lastSourceOffset == null || lastSourceOffset.isEmpty()) { \n offsetMap = new HashMap<>(); \n } else {\n offsetMap = JSON_MAPPER.readValue(lastSourceOffset, Map.class); \n }\n return offsetMap;\n}\n", "repo_info": {"repo": "streamsets/datacollector", "path": "stagesupport/src/main/java/com/.../OffsetUtil.java", "function_name": "OffsetUtil.deserializeOffsetMap"}}, "output": "This Java method, `deserializeOffsetMap`, is used to deserialize a JSON string into a `Map`. Here's a breakdown of the code:\n\n1. The method takes a single parameter, `lastSourceOffset`, which is expected to be a JSON string.\n2. It first checks if `lastSourceOffset` is either `null` or an empty string. If true, it initializes an empty `HashMap` and assigns it to `offsetMap`.\n3. If `lastSourceOffset` is not `null` or empty, it uses the `JSON_MAPPER` object (presumably an instance of `ObjectMapper` from the Jackson library) to deserialize the JSON string into a `Map`. The `readValue` method is used for this purpose, with `Map.class` as the second argument, which specifies the expected type of the deserialized object.\n4. Finally, the method returns the `offsetMap`, which now contains the deserialized data.\n\nThe `@SuppressWarnings(\"unchecked\")` annotation is used to suppress a potential unchecked warning that might occur due to the raw `Map` type used in the method signature.", "metric": 0.30421982335623154} diff --git a/tests/results/examples/code/code.result b/tests/results/examples/code/code.result index dea410598..b05e46388 100644 --- a/tests/results/examples/code/code.result +++ b/tests/results/examples/code/code.result @@ -10,8 +10,11 @@ public static Map deserializeOffsetMap(String lastSourceOffset) return offsetMap; } +This Java method, `deserializeOffsetMap`, is used to deserialize a JSON string into a `Map`. Here's a breakdown of the code: +1. The method takes a single parameter, `lastSourceOffset`, which is expected to be a JSON string. +2. It first checks if `lastSourceOffset` is either `null` or an empty string. If true, it initializes an empty `HashMap` and assigns it to `offsetMap`. +3. If `lastSourceOffset` is not `null` or empty, it uses the `JSON_MAPPER` object (presumably an instance of `ObjectMapper` from the Jackson library) to deserialize the JSON string into a `Map`. The `readValue` method is used for this purpose, with `Map.class` as the second argument, which specifies the expected type of the deserialized object. +4. Finally, the method returns the `offsetMap`, which now contains the deserialized data. -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. +The `@SuppressWarnings("unchecked")` annotation is used to suppress a potential unchecked warning that might occur due to the raw `Map` type used in the method signature. diff --git a/tests/results/examples/demo/3-weather.result b/tests/results/examples/demo/3-weather.result index 32fc549a7..437a3c1d0 100644 --- a/tests/results/examples/demo/3-weather.result +++ b/tests/results/examples/demo/3-weather.result @@ -1,2 +1 @@ - -The weather in Yorktown Heights, New York, USA is currently partly cloudy with a temperature of 15.6°C (60.1°F). The wind speed is 10.1 mph (16.2 kph) from the NNW direction. The humidity is 40%, and the visibility is 16 km (9 miles). The UV index is 3.4, and there is no precipitation. The feels-like temperature is 15.6°C (60.1°F), and the wind chill is 13.7°C (56.6°F). The heat index is 14.4°C (58.0°F), and the dew point is 3.8°C (38.8°F). The pressure is 1017 mb (30.02 in). +The weather in Yorktown Heights, New York, USA is currently clear with a temperature of 8.9°C (48.0°F). The wind is blowing at a speed of 5.1 mph (8.3 kph) from the north (N). The pressure is 1023.0 mb (30.2 inches). Humidity is at 49% and the wind chill is also 8.9°C (48.0°F). The dew point is 1.9°C (35.4°F) and visibility is 16.0 km (9.0 miles). There is no UV index, precipitation, or heat index reported. The gust speed is 10.8 mph (17.4 kph). diff --git a/tests/results/examples/demo/4-translator.result b/tests/results/examples/demo/4-translator.result index 2c100b9ca..ce1317c5a 100644 --- a/tests/results/examples/demo/4-translator.result +++ b/tests/results/examples/demo/4-translator.result @@ -1,5 +1,5 @@ What is APR? -Annual Percentage Rate (APR) is the total cost of borrowing money, expressed as a percentage.french +APR stands for Annual Percentage Rate. It is the annual interest rate charged for borrowing or earned through an investment, and it represents the actual yearly cost of funds over the term of a loan. It includes any fees or additional costs associated with the transaction.french Translate the above to french -La taux de change annuel (TAC) est le coût total du prêt, exprimé en pourcentage.stop +APR signifie Taux Annuel Équivalent (TAE) en français. Il s'agit du taux d'intérêt annuel chargé pour emprunter ou gagné grâce à une investissement, et il représente le coût réel annuel des fonds sur la durée d'un prêt. Il inclut toutes les frais ou coûts supplémentaires associés à la transaction.stop diff --git a/tests/results/examples/fibonacci/fib.result b/tests/results/examples/fibonacci/fib.result index 303fe94da..fab29f20e 100644 --- a/tests/results/examples/fibonacci/fib.result +++ b/tests/results/examples/fibonacci/fib.result @@ -1,43 +1,43 @@ +Here is a simple Python function to compute the Fibonacci sequence: ```python -def fib(n): - if n == 0: - return 0 +def fibonacci(n): + if n <= 0: + return "Input should be a positive integer." elif n == 1: + return 0 + elif n == 2: return 1 else: - return fib(n-1) + fib(n-2) + a, b = 0, 1 + for _ in range(n - 2): + a, b = b, a + b + return b ``` -The above code is a recursive implementation of the Fibonacci sequence. -However, it is not very efficient since it recalculates the same values multiple times. -To improve the performance, we can use dynamic programming to store the previously calculated values and reuse them. - -Here's an optimized version of the Fibonacci function using dynamic programming: - -```python -def fib_dp(n): - fib_values = [0, 1] - for i in range(2, n+1): - fib_values.append(fib_values[i-1] + fib_values[i-2]) - return fib_values[n] -``` +This function takes an integer `n` as input and returns the `n`th number in the Fibonacci sequence. The Fibonacci sequence is a series of numbers in which each number is the sum of the two preceding ones, usually starting with 0 and 1. Find a random number between 1 and 20 15 -Now computing fib(15) +Now computing fibonacci(15) -def fib(n): - if n == 0: - return 0 +def fibonacci(n): + if n <= 0: + return "Input should be a positive integer." elif n == 1: + return 0 + elif n == 2: return 1 else: - return fib(n-1) + fib(n-2) -The result is: 610 + a, b = 0, 1 + for _ in range(n - 2): + a, b = b, a + b + return b +The result is: 377 Explain what the above code does and what the result means +The provided code is a Python function named `fibonacci(n)` that computes the `n`th number in the Fibonacci sequence. The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones, usually starting with 0 and 1. -The code calculates the nth Fibonacci number using dynamic programming. It initializes a list `fib_values` with the first two Fibonacci numbers [0, 1]. Then, it iterates from 2 to n and calculates each Fibonacci number by adding the previous two numbers in the list. Finally, it returns the nth Fibonacci number from the list. +The function takes an integer `n` as input and returns the `n`th number in the Fibonacci sequence. It first checks if the input is a positive integer and returns an error message if it's not. If the input is 1, it returns 0 (the first number in the Fibonacci sequence). If the input is 2, it returns 1 (the second number in the Fibonacci sequence). For any other positive integer input, it uses a loop to calculate the `n`th number in the Fibonacci sequence and returns the result. -In this case, the result is 610, which means that the 15th Fibonacci number is 610. +In the given example, the function is called with the argument `15`, which means it will compute the 15th number in the Fibonacci sequence. The result of this computation is `377`. This number is the 15th number in the Fibonacci sequence, which is the sum of the 14th and 13th numbers in the sequence. diff --git a/tests/results/examples/granite/multi_round_chat.result b/tests/results/examples/granite/multi_round_chat.result index b36a0a765..068d20d0d 100644 --- a/tests/results/examples/granite/multi_round_chat.result +++ b/tests/results/examples/granite/multi_round_chat.result @@ -1,29 +1,15 @@ -You are Granite Chat, an AI language model developed by IBM. You are a cautious assistant. You carefully follow instructions. You are helpful and harmless and you follow ethical guidelines and promote positive behavior. You always respond to greetings (for example, hi, hello, g'day, morning, afternoon, evening, night, what's up, nice to meet you, sup, etc) with "Hello! I am Granite Chat, created by IBM. How can I help you today?". Please do not say anything else and do not start a conversation. -What is APR? - -Annual Percentage Rate (APR) is a measure that represents the annual cost of borrowing money, including interest payments and other fees. It is expressed as a percentage and is used to compare different loan offers and determine the true cost of borrowing. APR takes into account the interest rate, points, and other charges associated with the loan, providing a more accurate picture of the total cost of a loan compared to just the interest rate alone. By considering all these factors, APR helps borrowers make informed decisions about which loans offer the best value.Can you write a poem about APR? - -In the realm of lending, there exists a term, -A figure that dance with numbers, both fair and unfair. -Annual Percentage Rate, or APR, it's called, -A tale of interest, wrapped in a mathematical balm. - -It's not just the Interest rate that it entails, -But also the points, the fees, the hidden tangles. -A comprehensive view, it provides, -Of the overall cost, come what may. -Borrowers, take heed, of this true cost, -Not just the interest rate, but the APR's prolong. -For when comparing loans, make sure to delve, -Into the APR's depths, before you succumb. - -APR, a faithful friend, or a foe unseen, -Helps you determine if a loan is right for you. -So, let's embrace this number, so neat, -And navigate the financial market with stealth. - -In the world of finance, APR's the guiding star, -With patience and wisdom, you'll make the most of a far star.Now explain APR to me like I'm 5 years old - -APR is like a special word that grown-ups use when they borrow money from a place like a bank. It's a way to know how much it will cost them to get that money over a year. APR includes not only the interest rate, which is like the cost of borrowing the money, but also things like fees and extra costs. By adding it all up, APR gives a better idea of how much the loan will really cost. So, when choosing a loan, it's important to look at the APR to make sure it's a good deal. +What is APR? +APR stands for Annual Percentage Rate. It is the annual interest rate charged for borrowing or earned through an investment, and it represents the actual yearly cost of funds over the term of a loan. It includes any fees or additional costs associated with the transaction. +Can you write a poem about APR? +In the world of finance, APR is the key, +A number that tells us what we'll pay, or earn, you see. +It's the annual rate, both simple and clear, +Including all fees, for loans and investments, near and far. + +It's the cost of borrowing, or the return we gain, +A figure that helps us make informed financial gain. +So, when you're comparing loans, or investments to choose, +Remember APR, and make the right move. +Now explain APR to me like I'm 5 years old +Sure! Imagine you have a piggy bank, and you want to borrow some money from your parents to buy a toy. Your parents will ask you to pay them back with some extra money, which is like interest. APR is the special number that tells you how much extra money you'll have to pay back, all in one year. It's like a special rule that helps you understand how much you'll owe your parents. diff --git a/tests/results/examples/granite/single_round_chat.result b/tests/results/examples/granite/single_round_chat.result index 03d4014fc..807524844 100644 --- a/tests/results/examples/granite/single_round_chat.result +++ b/tests/results/examples/granite/single_round_chat.result @@ -1,4 +1,4 @@ -{"role": "system", "content": "You are Granite Chat, an AI language model developed by IBM. You are a cautious assistant. You carefully follow instructions. You are helpful and harmless and you follow ethical guidelines and promote positive behavior. You always respond to greetings (for example, hi, hello, g'day, morning, afternoon, evening, night, what's up, nice to meet you, sup, etc) with \"Hello! I am Granite Chat, created by IBM. How can I help you today?\". Please do not say anything else and do not start a conversation.\n"}What is APR? +What is APR? yes -Annual Percentage Rate (APR) is a measure that represents the yearly cost of borrowing money, expressed as a percentage. It includes the interest rate and other fees related to the loan, if any. APR is used to compare different loan offers and is a more accurate representation of the total cost of borrowing than simply looking at the interest rate alone. It's essential to consider both the interest rate and APR when evaluating loan options to make an informed decision. +APR stands for Annual Percentage Rate. It is the annual interest rate charged for borrowing or earned through an investment, and it represents the actual yearly cost of funds over the term of a loan. It includes any fees or additional costs associated with the transaction. diff --git a/tests/results/examples/hello/hello-def-use.result b/tests/results/examples/hello/hello-def-use.result index c80245ebe..9b863a148 100644 --- a/tests/results/examples/hello/hello-def-use.result +++ b/tests/results/examples/hello/hello-def-use.result @@ -1,2 +1,3 @@ -Hello, World -Who is World? +Hello +Hello +You said Hello. diff --git a/tests/results/examples/hello/hello-model-chaining.result b/tests/results/examples/hello/hello-model-chaining.result index f583d329f..0702a9755 100644 --- a/tests/results/examples/hello/hello-model-chaining.result +++ b/tests/results/examples/hello/hello-model-chaining.result @@ -1,3 +1,4 @@ -Hello, World! -Who is World? -World is a fictional character in the popular science fiction television series "The X-Files +Hello +Hello +Did you say Hello? +Yes, I did diff --git a/tests/results/examples/hello/hello-model-input.result b/tests/results/examples/hello/hello-model-input.result index 9fc31828c..e965047ad 100644 --- a/tests/results/examples/hello/hello-model-input.result +++ b/tests/results/examples/hello/hello-model-input.result @@ -1 +1 @@ - World! +Hello diff --git a/tests/results/examples/hello/hello-parser-regex.result b/tests/results/examples/hello/hello-parser-regex.result index 866e5ddb7..a48fa9858 100644 --- a/tests/results/examples/hello/hello-parser-regex.result +++ b/tests/results/examples/hello/hello-parser-regex.result @@ -1 +1 @@ -{"name": "World"} +{"name": "Hello"} diff --git a/tests/results/examples/hello/hello-roles-array.result b/tests/results/examples/hello/hello-roles-array.result index eac1b89d3..c72e5bff4 100644 --- a/tests/results/examples/hello/hello-roles-array.result +++ b/tests/results/examples/hello/hello-roles-array.result @@ -1,36 +1,42 @@ - - -Here is the pseudocode for merge sort: +Here is a Python function that implements the merge sort algorithm: ```python def merge_sort(arr): - if len(arr) > 1: - mid = len(arr) // 2 - left_half = arr[:mid] - right_half = arr[mid:] - - merge_sort(left_half) - merge_sort(right_half) - - i = j = k = 0 - - while i < len(left_half) and j < len(right_half): - if left_half[i] < right_half[j]: - arr[k] = left_half[i] - i += 1 - else: - arr[k] = right_half[j] - j += 1 - k += 1 - - while i < len(left_half): - arr[k] = left_half[i] - i += 1 - k += 1 - - while j < len(right_half): - arr[k] = right_half[j] - j += 1 - k += 1 + # Base case: if the array has 1 or 0 elements, it's already sorted + if len(arr) <= 1: + return arr + + # Split the array into two halves + mid = len(arr) // 2 + left_half = arr[:mid] + right_half = arr[mid:] + + # Recursively sort both halves + left_sorted = merge_sort(left_half) + right_sorted = merge_sort(right_half) + + # Merge the sorted halves + return merge(left_sorted, right_sorted) + +def merge(left, right): + merged = [] + left_index = 0 + right_index = 0 + + # Merge the two halves, keeping them sorted + while left_index < len(left) and right_index < len(right): + if left[left_index] < right[right_index]: + merged.append(left[left_index]) + left_index += 1 + else: + merged.append(right[right_index]) + right_index += 1 + + # Add any remaining elements from the left and right halves + merged.extend(left[left_index:]) + merged.extend(right[right_index:]) + + return merged ``` +This function first checks if the input array has 1 or 0 elements, in which case it's already sorted. If not, it splits the array into two halves and recursively sorts each half using the merge sort algorithm. Finally, it merges the two sorted halves back together. diff --git a/tests/results/examples/hello/hello.result b/tests/results/examples/hello/hello.result index 8ab686eaf..5d752d231 100644 --- a/tests/results/examples/hello/hello.result +++ b/tests/results/examples/hello/hello.result @@ -1 +1,2 @@ -Hello, World! +Hello +Hello! How can I assist you today? diff --git a/tests/results/examples/react/demo.result b/tests/results/examples/react/demo.result new file mode 100644 index 000000000..6e2e92a08 --- /dev/null +++ b/tests/results/examples/react/demo.result @@ -0,0 +1,41 @@ +What is the elevation range for the area that the eastern sector of the Colorado orogeny extends into? +Tho: I need to search Colorado orogeny, find the area that the eastern sector of the Colorado ... +Act: {"name": "Search", "arguments": {"topic": "Colorado orogeny"}} +Obs: The Colorado orogeny was an episode of mountain building (an orogeny) ... +Tho: It does not mention the eastern sector. So I need to look up eastern sector. +Tho: High Plains rise in elevation from around 1,800 to 7,000 ft, so the answer is 1,800 to 7,000 ft. +Act: {"name": "Finish", "arguments": {"topic": "1,800 to 7,000 ft"}} + +What profession does Nicholas Ray and Elia Kazan have in common? +Tho: I need to search Nicholas Ray and Elia Kazan, find their professions, then find the profession they have in common. +Act: {"name": "Search", "arguments": {"topic": "Nicholas Ray"}} +Obs: Nicholas Ray (born Raymond Nicholas Kienzle Jr., August 7, 1911 - June 16, 1979) was an American film director, screenwriter, and actor best known for the 1955 film Rebel Without a Cause. +Tho: Professions of Nicholas Ray are director, screenwriter, and actor. I need to search Elia Kazan next and find his professions. +Act: {"name": "Search", "arguments": {"topic": "Elia Kazan"}} +Obs: Elia Kazan was an American film and theatre director, producer, screenwriter and actor. +Tho: Professions of Elia Kazan are director, producer, screenwriter, and actor. So profession Nicholas Ray and Elia Kazan have in common is director, screenwriter, and actor. +Act: {"name": "Finish", "arguments": {"topic": "director, screenwriter, actor"}} + +What is 18 + 12 x 3? +Tho: I need to call a calculator. +Act: {"name": "Calc", "arguments": {"expr": "18 + 12 * 3"}} +Obs: 54 +Act: {"name": "Finish", "arguments": {"topic": "54"}} + +A total of 252 qualifying matches were played, and 723 goals were scored. What was the average number of goals per match? +Tho: I need to call a calculator. +Act: {"name": "Calc", "arguments": {"expr": "723 / 252"}} +Obs: 2.869047619047619 +Act: {"name": "Finish", "arguments": {"topic": "2.869047619047619"}} + + +How many years ago was the discoverer of the Hudson River born? Keep in mind we are in 2024. +Tho: I need to search Henry Hudson, find out when he was born, and then calculate how many years ago that was. +Act: {"name": "Search", "arguments": {"topic": "Henry Hudson"}} +Obs: Henry Hudson (c. 1565 – disappeared 23 June 1611) was an English sea explorer and navigator during the early 17th century, best known for his explorations of present-day Canada and parts of the Northeastern United States. +In 1607 and 1608, Hudson made two attempts on behalf of English merchants to find a rumoured Northeast Passage to Cathay via a route above the Arctic Circle. In 1609, he landed in North America on behalf of the Dutch East India Company and explored the region around the modern New York metropolitan area. Looking for a Northwest Passage to Asia on his ship Halve Maen ("Half Moon"), he sailed up the Hudson River, which was later named after him, and thereby laid the foundation for Dutch colonization of the region. His contributions to the exploration of the New World were significant and lasting. His voyages helped to establish European contact with the native peoples of North America and contributed to the development of trade and commerce. +On his final expedition, while still searching for the Northwest Passage, Hudson became the first European to see Hudson Strait and the immense Hudson Bay. In 1611, after wintering on the shore of James Bay, Hudson wanted to press on to the west, but most of his crew mutinied. The mutineers cast Hudson, his son, and six others adrift; the Hudsons and their companions were never seen again. +Tho: Henry Hudson was born around 1565. To find out how many years ago that was, I need to subtract his birth year from the current year, which is 2024. +Act: {"name": "Calc", "arguments": {"expr": "2024 - 1565"}} +Obs: 459 + diff --git a/tests/results/examples/react/wikipedia.result b/tests/results/examples/react/wikipedia.result index 84d9e0f95..4620b2aa6 100644 --- a/tests/results/examples/react/wikipedia.result +++ b/tests/results/examples/react/wikipedia.result @@ -16,15 +16,36 @@ Obs: Elia Kazan was an American film and theatre director, producer, screenwrite Tho: Professions of Elia Kazan are director, producer, screenwriter, and actor. So profession Nicholas Ray and Elia Kazan have in common is director, screenwriter, and actor. Act: {"name": "Finish", "arguments": {"topic": "director, screenwriter, actor"}} -When was the discoverer of the Hudson River born? -Tho: I need to search the discoverer of the Hudson River, find when he was born. -Act:{"name": "Search", "arguments": {"topic": "discoverer of the Hudson River"}}Obs: The Hudson River is a 315-mile (507 km) river that flows from north to south primarily through eastern New York, United States. It originates in the Adirondack Mountains of upstate New York at Henderson Lake in the town of Newcomb, and flows southward through the Hudson Valley to the New York Harbor between New York City and Jersey City, eventually draining into the Atlantic Ocean at Upper New York Bay. The river serves as a physical boundary between the states of New Jersey and New York at its southern end. Farther north, it marks local boundaries between several New York counties. The lower half of the river is a tidal estuary, deeper than the body of water into which it flows, occupying the Hudson Fjord, an inlet that formed during the most recent period of North American glaciation, estimated at 26,000 to 13,300 years ago. Even as far north as the city of Troy, the flow of the river changes direction with the tides. -The Hudson River runs through the Munsee, Lenape, Mohican, Mohawk, and Haudenosaunee homelands. Prior to European exploration, the river was known as the Mahicannittuk by the Mohicans, Ka'nón:no by the Mohawks, and Muhheakantuck by the Lenape. The river was subsequently named after Henry Hudson, an Englishman sailing for the Dutch East India Company who explored it in 1609, and after whom Hudson Bay in Canada is also named. It had previously been observed by Italian explorer Giovanni da Verrazzano sailing for King Francis I of France in 1524, as he became the first European known to have entered the Upper New York Bay, but he considered the river to be an estuary. The Dutch called the river the North River, and they called the present-day Delaware River the South River, which formed the spine of the Dutch colony of New Netherland. Settlements of the colony clustered around the Hudson, and its strategic importance as the gateway to the American interior led to years of competition between the English and the Dutch over control of the river and colony. -During the 18th century, the river valley and its inhabitants were the subject and inspiration of Washington Irving, the first internationally acclaimed American author. In the nineteenth century, the area inspired the Hudson River School of landscape painting, an American pastoral style, as well as the concepts of environmentalism and wilderness. The Hudson River was also the eastern outlet for the Erie Canal, which, when completed in 1825, became an important transportation artery for the early 19th century United States. -Pollution in the Hudson River increased in the 20th century, more acutely by mid-century, particularly with industrial contamination from polychlorinated biphenyls, also known by their acronym PCBs. Pollution control regulations, enforcement actions and restoration projects initiated in the latter 20th century have begun to improve water quality, and restoration work has continued in the 21st century. -Tho: The discoverer of the Hudson River is Henry Hudson. I need to search Henry Hudson, find when he was born. -Act:{"name": "Search", "arguments": {"topic": "Henry Hudson"}}Obs: Henry Hudson (c. 1565 – disappeared 23 June 1611) was an English sea explorer and navigator during the early 17th century, best known for his explorations of present-day Canada and parts of the Northeastern United States. +What is 18 + 12 x 3? +Tho: I need to call a calculator. +Act: {"name": "Calc", "arguments": {"expr": "18 + 12 * 3"}} +Obs: 54 +Act: {"name": "Finish", "arguments": {"topic": "54"}} + +A total of 252 qualifying matches were played, and 723 goals were scored. What was the average number of goals per match? +Tho: I need to call a calculator. +Act: {"name": "Calc", "arguments": {"expr": "723 / 252"}} +Obs: 2.869047619047619 +Act: {"name": "Finish", "arguments": {"topic": "2.869047619047619"}} + +What is 18 + 12 x 3? +Tho: I need to call a calculator. +Act: {"name": "Calc", "arguments": {"expr": "18 + 12 * 3"}} +Obs: 54 +Act: {"name": "Finish", "arguments": {"topic": "54"}} + +A total of 252 qualifying matches were played, and 723 goals were scored. What was the average number of goals per match? +Tho: I need to call a calculator. +Act: {"name": "Calc", "arguments": {"expr": "723 / 252"}} +Obs: 2.869047619047619 +Act: {"name": "Finish", "arguments": {"topic": "2.869047619047619"}} + + +when was the discoverer of the Hudson River born? +Tho: I need to search Henry Hudson, find out when he was born. +Act: {"name": "Search", "arguments": {"topic": "Henry Hudson"}} +Obs: Henry Hudson (c. 1565 – disappeared 23 June 1611) was an English sea explorer and navigator during the early 17th century, best known for his explorations of present-day Canada and parts of the Northeastern United States. In 1607 and 1608, Hudson made two attempts on behalf of English merchants to find a rumoured Northeast Passage to Cathay via a route above the Arctic Circle. In 1609, he landed in North America on behalf of the Dutch East India Company and explored the region around the modern New York metropolitan area. Looking for a Northwest Passage to Asia on his ship Halve Maen ("Half Moon"), he sailed up the Hudson River, which was later named after him, and thereby laid the foundation for Dutch colonization of the region. His contributions to the exploration of the New World were significant and lasting. His voyages helped to establish European contact with the native peoples of North America and contributed to the development of trade and commerce. On his final expedition, while still searching for the Northwest Passage, Hudson became the first European to see Hudson Strait and the immense Hudson Bay. In 1611, after wintering on the shore of James Bay, Hudson wanted to press on to the west, but most of his crew mutinied. The mutineers cast Hudson, his son, and six others adrift; the Hudsons and their companions were never seen again. -Tho: Henry Hudson was born in 1565. -Act:{"name": "Finish", "arguments": {"topic": "1565"}} +Tho: Henry Hudson was born around 1565. +Act: {"name": "Finish", "arguments": {"topic": "around 1565"}} diff --git a/tests/results/examples/sdk/hello.result b/tests/results/examples/sdk/hello.result index 8ab686eaf..af17d2f87 100644 --- a/tests/results/examples/sdk/hello.result +++ b/tests/results/examples/sdk/hello.result @@ -1 +1,2 @@ -Hello, World! +Hello +Hello diff --git a/tests/results/examples/talk/1-hello.result b/tests/results/examples/talk/1-hello.result index 8ab686eaf..af17d2f87 100644 --- a/tests/results/examples/talk/1-hello.result +++ b/tests/results/examples/talk/1-hello.result @@ -1 +1,2 @@ -Hello, World! +Hello +Hello diff --git a/tests/results/examples/talk/11-repeat.result b/tests/results/examples/talk/11-repeat.result new file mode 100644 index 000000000..e75e22558 --- /dev/null +++ b/tests/results/examples/talk/11-repeat.result @@ -0,0 +1,8 @@ +Bob's number is 1 +{"name": "Bob", "number": 1} +Carol's number is 2 +{"name": "Carol", "number": 2} +David's number is 3 +{"name": "David", "number": 3} +Ernest's number is 4 +{"name": "Ernest", "number": 4} diff --git a/tests/results/examples/talk/2-model-chaining.result b/tests/results/examples/talk/2-model-chaining.result index 511abb028..f284cf32b 100644 --- a/tests/results/examples/talk/2-model-chaining.result +++ b/tests/results/examples/talk/2-model-chaining.result @@ -1,3 +1,4 @@ -Hello, World! +Hello +Hello Translate this to French -Bonjour le monde ! +I'm sorry for the confusion, but it seems like you didn't provide any text to translate. Could you please provide the text you'd like me to translate into French? diff --git a/tests/results/examples/talk/3-def-use.result b/tests/results/examples/talk/3-def-use.result index 65f258688..ebf1038bd 100644 --- a/tests/results/examples/talk/3-def-use.result +++ b/tests/results/examples/talk/3-def-use.result @@ -1,2 +1,3 @@ -Hello, World -The French translation of the word "World" is "Monde". This term is used to refer to the entire planet Earth, including all its countries, continents, and oceans. It can also be used metaphorically to describe a vast or extensive system or organization. +Hello +Hello +The word "Hello" translates to "Bonjour" in French. diff --git a/tests/results/examples/talk/4-function.result b/tests/results/examples/talk/4-function.result index 4d6fd2d7b..bb60b1210 100644 --- a/tests/results/examples/talk/4-function.result +++ b/tests/results/examples/talk/4-function.result @@ -1,2 +1,2 @@ -The translation of 'I love Paris!' to French is 'J'aime Paris!'. -The translation of 'I love Madrid!' to Spanish is 'Me encanta Madrid!'. +The translation of 'I love Paris!' in French is 'Je t'aime, Paris!'. +The translation of 'I love Madrid!' in Spanish is 'Me encanta Madrid!'. diff --git a/tests/results/examples/talk/5-code-eval.result b/tests/results/examples/talk/5-code-eval.result index 912ad1476..9693c956b 100644 --- a/tests/results/examples/talk/5-code-eval.result +++ b/tests/results/examples/talk/5-code-eval.result @@ -10,11 +10,15 @@ public static Map deserializeOffsetMap(String lastSourceOffset) return offsetMap; } +This Java method, `deserializeOffsetMap`, is used to deserialize a JSON string into a `Map`. Here's a breakdown of the code: -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. +1. The method takes a single parameter, `lastSourceOffset`, which is expected to be a JSON string. +2. It first checks if `lastSourceOffset` is either `null` or an empty string. If true, it initializes an empty `HashMap` and assigns it to `offsetMap`. +3. If `lastSourceOffset` is not `null` or empty, it uses the `JSON_MAPPER` object (presumably an instance of `ObjectMapper` from the Jackson library) to deserialize the JSON string into a `Map`. The `readValue` method is used for this purpose, with `Map.class` as the second argument, which specifies the expected type of the deserialized object. +4. Finally, the method returns the `offsetMap`, which now contains the deserialized data. -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. +The `@SuppressWarnings("unchecked")` annotation is used to suppress a potential unchecked warning that might occur due to the raw `Map` type used in the method signature. EVALUATION: The similarity (Levenshtein) between this answer and the ground truth is: -0.9983818770226537 +0.30520117762512267 diff --git a/tests/results/examples/talk/6-code-json.result b/tests/results/examples/talk/6-code-json.result index 5a5502981..83232f38c 100644 --- a/tests/results/examples/talk/6-code-json.result +++ b/tests/results/examples/talk/6-code-json.result @@ -1 +1 @@ -{"input": {"source_code": "@SuppressWarnings(\"unchecked\")\npublic static Map deserializeOffsetMap(String lastSourceOffset) throws IOException {\n Map offsetMap;\n if (lastSourceOffset == null || lastSourceOffset.isEmpty()) { \n offsetMap = new HashMap<>(); \n } else {\n offsetMap = JSON_MAPPER.readValue(lastSourceOffset, Map.class); \n }\n return offsetMap;\n}\n", "repo_info": {"repo": "streamsets/datacollector", "path": "stagesupport/src/main/java/com/.../OffsetUtil.java", "function_name": "OffsetUtil.deserializeOffsetMap"}}, "output": "\nThe 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.\n\nThe `@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.", "metric": 0.9983818770226537} +{"input": {"source_code": "@SuppressWarnings(\"unchecked\")\npublic static Map deserializeOffsetMap(String lastSourceOffset) throws IOException {\n Map offsetMap;\n if (lastSourceOffset == null || lastSourceOffset.isEmpty()) { \n offsetMap = new HashMap<>(); \n } else {\n offsetMap = JSON_MAPPER.readValue(lastSourceOffset, Map.class); \n }\n return offsetMap;\n}\n", "repo_info": {"repo": "streamsets/datacollector", "path": "stagesupport/src/main/java/com/.../OffsetUtil.java", "function_name": "OffsetUtil.deserializeOffsetMap"}}, "output": "This Java method, `deserializeOffsetMap`, is used to deserialize a JSON string into a `Map`. Here's a breakdown of the code:\n\n1. The method takes a single parameter, `lastSourceOffset`, which is expected to be a JSON string.\n2. It first checks if `lastSourceOffset` is either `null` or an empty string. If true, it initializes an empty `HashMap` and assigns it to `offsetMap`.\n3. If `lastSourceOffset` is not `null` or empty, it uses the `JSON_MAPPER` object (presumably an instance of `ObjectMapper` from the Jackson library) to deserialize the JSON string into a `Map`. The `readValue` method is used for this purpose, with `Map.class` as the second argument, which specifies the expected type of the deserialized object.\n4. Finally, the method returns the `offsetMap`, which now contains the deserialized data.\n\nThe `@SuppressWarnings(\"unchecked\")` annotation is used to suppress a potential unchecked warning that might occur due to the raw `Map` type used in the method signature.", "metric": 0.30520117762512267} diff --git a/tests/results/examples/talk/7-chatbot-roles.result b/tests/results/examples/talk/7-chatbot-roles.result index 1d48a7bd6..293f0823e 100644 --- a/tests/results/examples/talk/7-chatbot-roles.result +++ b/tests/results/examples/talk/7-chatbot-roles.result @@ -1,6 +1,8 @@ Type `quit` to exit this chatbot. +APR stands for Annual Percentage Rate. It is the annual interest rate charged for borrowing or earned on an investment, expressed as a single percentage number that represents the actual yearly cost of funds over the term of a loan. It includes any fees or additional costs associated with the transaction. -APR, or Annual Percentage Rate, is a fundamental concept in finance that represents the yearly cost of borrowing money, including any fees or additional charges. It's expressed as a percentage and is used to calculate the total amount of interest paid over the life of a loan. APR is crucial for comparing different loan offers and understanding the true cost of borrowing. By taking into account both the interest rate and other fees, APR provides a more comprehensive view of the loan's overall expense compared to just the interest rate alone. -Thank you for using Granite Chat. If you have any more questions or need assistance, feel free to ask. Have a great day! +I'm sorry to see you go. If you have any more questions in the future, feel free to return. Have a great day! + + diff --git a/tests/results/examples/talk/9-react.result b/tests/results/examples/talk/9-react.result index 84d9e0f95..4620b2aa6 100644 --- a/tests/results/examples/talk/9-react.result +++ b/tests/results/examples/talk/9-react.result @@ -16,15 +16,36 @@ Obs: Elia Kazan was an American film and theatre director, producer, screenwrite Tho: Professions of Elia Kazan are director, producer, screenwriter, and actor. So profession Nicholas Ray and Elia Kazan have in common is director, screenwriter, and actor. Act: {"name": "Finish", "arguments": {"topic": "director, screenwriter, actor"}} -When was the discoverer of the Hudson River born? -Tho: I need to search the discoverer of the Hudson River, find when he was born. -Act:{"name": "Search", "arguments": {"topic": "discoverer of the Hudson River"}}Obs: The Hudson River is a 315-mile (507 km) river that flows from north to south primarily through eastern New York, United States. It originates in the Adirondack Mountains of upstate New York at Henderson Lake in the town of Newcomb, and flows southward through the Hudson Valley to the New York Harbor between New York City and Jersey City, eventually draining into the Atlantic Ocean at Upper New York Bay. The river serves as a physical boundary between the states of New Jersey and New York at its southern end. Farther north, it marks local boundaries between several New York counties. The lower half of the river is a tidal estuary, deeper than the body of water into which it flows, occupying the Hudson Fjord, an inlet that formed during the most recent period of North American glaciation, estimated at 26,000 to 13,300 years ago. Even as far north as the city of Troy, the flow of the river changes direction with the tides. -The Hudson River runs through the Munsee, Lenape, Mohican, Mohawk, and Haudenosaunee homelands. Prior to European exploration, the river was known as the Mahicannittuk by the Mohicans, Ka'nón:no by the Mohawks, and Muhheakantuck by the Lenape. The river was subsequently named after Henry Hudson, an Englishman sailing for the Dutch East India Company who explored it in 1609, and after whom Hudson Bay in Canada is also named. It had previously been observed by Italian explorer Giovanni da Verrazzano sailing for King Francis I of France in 1524, as he became the first European known to have entered the Upper New York Bay, but he considered the river to be an estuary. The Dutch called the river the North River, and they called the present-day Delaware River the South River, which formed the spine of the Dutch colony of New Netherland. Settlements of the colony clustered around the Hudson, and its strategic importance as the gateway to the American interior led to years of competition between the English and the Dutch over control of the river and colony. -During the 18th century, the river valley and its inhabitants were the subject and inspiration of Washington Irving, the first internationally acclaimed American author. In the nineteenth century, the area inspired the Hudson River School of landscape painting, an American pastoral style, as well as the concepts of environmentalism and wilderness. The Hudson River was also the eastern outlet for the Erie Canal, which, when completed in 1825, became an important transportation artery for the early 19th century United States. -Pollution in the Hudson River increased in the 20th century, more acutely by mid-century, particularly with industrial contamination from polychlorinated biphenyls, also known by their acronym PCBs. Pollution control regulations, enforcement actions and restoration projects initiated in the latter 20th century have begun to improve water quality, and restoration work has continued in the 21st century. -Tho: The discoverer of the Hudson River is Henry Hudson. I need to search Henry Hudson, find when he was born. -Act:{"name": "Search", "arguments": {"topic": "Henry Hudson"}}Obs: Henry Hudson (c. 1565 – disappeared 23 June 1611) was an English sea explorer and navigator during the early 17th century, best known for his explorations of present-day Canada and parts of the Northeastern United States. +What is 18 + 12 x 3? +Tho: I need to call a calculator. +Act: {"name": "Calc", "arguments": {"expr": "18 + 12 * 3"}} +Obs: 54 +Act: {"name": "Finish", "arguments": {"topic": "54"}} + +A total of 252 qualifying matches were played, and 723 goals were scored. What was the average number of goals per match? +Tho: I need to call a calculator. +Act: {"name": "Calc", "arguments": {"expr": "723 / 252"}} +Obs: 2.869047619047619 +Act: {"name": "Finish", "arguments": {"topic": "2.869047619047619"}} + +What is 18 + 12 x 3? +Tho: I need to call a calculator. +Act: {"name": "Calc", "arguments": {"expr": "18 + 12 * 3"}} +Obs: 54 +Act: {"name": "Finish", "arguments": {"topic": "54"}} + +A total of 252 qualifying matches were played, and 723 goals were scored. What was the average number of goals per match? +Tho: I need to call a calculator. +Act: {"name": "Calc", "arguments": {"expr": "723 / 252"}} +Obs: 2.869047619047619 +Act: {"name": "Finish", "arguments": {"topic": "2.869047619047619"}} + + +when was the discoverer of the Hudson River born? +Tho: I need to search Henry Hudson, find out when he was born. +Act: {"name": "Search", "arguments": {"topic": "Henry Hudson"}} +Obs: Henry Hudson (c. 1565 – disappeared 23 June 1611) was an English sea explorer and navigator during the early 17th century, best known for his explorations of present-day Canada and parts of the Northeastern United States. In 1607 and 1608, Hudson made two attempts on behalf of English merchants to find a rumoured Northeast Passage to Cathay via a route above the Arctic Circle. In 1609, he landed in North America on behalf of the Dutch East India Company and explored the region around the modern New York metropolitan area. Looking for a Northwest Passage to Asia on his ship Halve Maen ("Half Moon"), he sailed up the Hudson River, which was later named after him, and thereby laid the foundation for Dutch colonization of the region. His contributions to the exploration of the New World were significant and lasting. His voyages helped to establish European contact with the native peoples of North America and contributed to the development of trade and commerce. On his final expedition, while still searching for the Northwest Passage, Hudson became the first European to see Hudson Strait and the immense Hudson Bay. In 1611, after wintering on the shore of James Bay, Hudson wanted to press on to the west, but most of his crew mutinied. The mutineers cast Hudson, his son, and six others adrift; the Hudsons and their companions were never seen again. -Tho: Henry Hudson was born in 1565. -Act:{"name": "Finish", "arguments": {"topic": "1565"}} +Tho: Henry Hudson was born around 1565. +Act: {"name": "Finish", "arguments": {"topic": "around 1565"}} diff --git a/tests/results/examples/tutorial/calling_llm.result b/tests/results/examples/tutorial/calling_llm.result index 8ab686eaf..af17d2f87 100644 --- a/tests/results/examples/tutorial/calling_llm.result +++ b/tests/results/examples/tutorial/calling_llm.result @@ -1 +1,2 @@ -Hello, World! +Hello +Hello diff --git a/tests/results/examples/tutorial/calling_llm_with_input.result b/tests/results/examples/tutorial/calling_llm_with_input.result index 290e2f6e4..2d71ab72c 100644 --- a/tests/results/examples/tutorial/calling_llm_with_input.result +++ b/tests/results/examples/tutorial/calling_llm_with_input.result @@ -1,2 +1 @@ -Hello, : -Le mot 'world' en français est 'monde'. +Hello, The word 'world' translates to 'monde' in French. diff --git a/tests/results/examples/tutorial/conditionals_loops.result b/tests/results/examples/tutorial/conditionals_loops.result index b3c16e7d3..a6b1fdf6b 100644 --- a/tests/results/examples/tutorial/conditionals_loops.result +++ b/tests/results/examples/tutorial/conditionals_loops.result @@ -1,17 +1,4 @@ - -Annual Percentage Rate (APR) is the total cost of borrowing money, expressed as a percentage. It includes the interest rate and any additional fees or charges associated with the loan. APR is used to compare different loan offers and to understand the true cost of borrowing money over time. -Say it as a poem -In the realm of loans, a crucial term you'll find, -A figure that's both intriguing and profound, -Annual Percentage Rate, or APR, it's called, -A beacon that shines, to help you choose your ground. - -It's not just the interest rate that it entails, -But other costs, both big and small, combined, -APR, like a lighthouse, guides you through the fray, -Illuminating the path to a wiser day. - -So when shopping for loans, don't shy away, -Ask for APR, and compare it all, -For in the end, it's this number you'll see, -That truly reveals the cost of being free. +APR stands for Annual Percentage Rate. It is the annual interest rate charged for borrowing or earned through an investment, and it represents the actual yearly cost of funds over the term of a loan. It includes any fees or additional costs associated with the transaction.Say it as a poemAPR, a rate so grand, +Annual Percentage Rate, across the land. +It's the cost of borrowing, or earning, you see, +Including fees, for a year's decree. diff --git a/tests/results/examples/tutorial/data_block.result b/tests/results/examples/tutorial/data_block.result index 68d247afd..5eca40198 100644 --- a/tests/results/examples/tutorial/data_block.result +++ b/tests/results/examples/tutorial/data_block.result @@ -1 +1 @@ -{'input': {'source_code': '@SuppressWarnings("unchecked")\npublic static Map deserializeOffsetMap(String lastSourceOffset) throws IOException {\n Map offsetMap;\n if (lastSourceOffset == null || lastSourceOffset.isEmpty()) { \n offsetMap = new HashMap<>(); \n } else {\n offsetMap = JSON_MAPPER.readValue(lastSourceOffset, Map.class); \n }\n return offsetMap;\n}\n', 'repo_info': {'repo': 'streamsets/datacollector', 'path': 'stagesupport/src/main/java/com/.../OffsetUtil.java', 'function_name': 'OffsetUtil.deserializeOffsetMap'}}, 'output': '\nThe 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.\n\nThe `@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.', 'metric': 0.9967637540453075} +{'input': {'source_code': '@SuppressWarnings("unchecked")\npublic static Map deserializeOffsetMap(String lastSourceOffset) throws IOException {\n Map offsetMap;\n if (lastSourceOffset == null || lastSourceOffset.isEmpty()) { \n offsetMap = new HashMap<>(); \n } else {\n offsetMap = JSON_MAPPER.readValue(lastSourceOffset, Map.class); \n }\n return offsetMap;\n}\n', 'repo_info': {'repo': 'streamsets/datacollector', 'path': 'stagesupport/src/main/java/com/.../OffsetUtil.java', 'function_name': 'OffsetUtil.deserializeOffsetMap'}}, 'output': 'This Java method, `deserializeOffsetMap`, is used to deserialize a JSON string into a `Map`. Here\'s a breakdown of the code:\n\n1. The method takes a single parameter, `lastSourceOffset`, which is expected to be a JSON string.\n2. It first checks if `lastSourceOffset` is either `null` or an empty string. If true, it initializes an empty `HashMap` and assigns it to `offsetMap`.\n3. If `lastSourceOffset` is not `null` or empty, it uses the `JSON_MAPPER` object (presumably an instance of `ObjectMapper` from the Jackson library) to deserialize the JSON string into a `Map`. The `readValue` method is used for this purpose, with `Map.class` as the second argument, which specifies the expected type of the deserialized object.\n4. Finally, the method returns the `offsetMap`, which now contains the deserialized data.\n\nThe `@SuppressWarnings("unchecked")` annotation is used to suppress a potential unchecked warning that might occur due to the raw `Map` type used in the method signature.', 'metric': 0.30421982335623154} diff --git a/tests/results/examples/tutorial/function_definition.result b/tests/results/examples/tutorial/function_definition.result index 4d6fd2d7b..bb60b1210 100644 --- a/tests/results/examples/tutorial/function_definition.result +++ b/tests/results/examples/tutorial/function_definition.result @@ -1,2 +1,2 @@ -The translation of 'I love Paris!' to French is 'J'aime Paris!'. -The translation of 'I love Madrid!' to Spanish is 'Me encanta Madrid!'. +The translation of 'I love Paris!' in French is 'Je t'aime, Paris!'. +The translation of 'I love Madrid!' in Spanish is 'Me encanta Madrid!'. diff --git a/tests/results/examples/tutorial/grouping_definitions.result b/tests/results/examples/tutorial/grouping_definitions.result index 4d6fd2d7b..bb60b1210 100644 --- a/tests/results/examples/tutorial/grouping_definitions.result +++ b/tests/results/examples/tutorial/grouping_definitions.result @@ -1,2 +1,2 @@ -The translation of 'I love Paris!' to French is 'J'aime Paris!'. -The translation of 'I love Madrid!' to Spanish is 'Me encanta Madrid!'. +The translation of 'I love Paris!' in French is 'Je t'aime, Paris!'. +The translation of 'I love Madrid!' in Spanish is 'Me encanta Madrid!'. diff --git a/tests/results/examples/tutorial/include.result b/tests/results/examples/tutorial/include.result index 7551f0f37..068d20d0d 100644 --- a/tests/results/examples/tutorial/include.result +++ b/tests/results/examples/tutorial/include.result @@ -1,32 +1,15 @@ -You are Granite Chat, an AI language model developed by IBM. You are a cautious assistant. You carefully follow instructions. You are helpful and harmless and you follow ethical guidelines and promote positive behavior. You always respond to greetings (for example, hi, hello, g'day, morning, afternoon, evening, night, what's up, nice to meet you, sup, etc) with "Hello! I am Granite Chat, created by IBM. How can I help you today?". Please do not say anything else and do not start a conversation. -What is APR? - -Annual Percentage Rate (APR) is a measure of the cost of borrowing money, expressed as a percentage rate. It takes into account both the interest rate and other fees associated with the loan. APR is typically higher than the interest rate because it includes the cost of insurance, points, and other charges imposed by the lender. By providing a single, standardized measure of the cost of a loan, APR facilitates comparisons between different loans and lenders. It's important to note that APR is not the same as simple interest, which is only the cost of borrowing the principal amount without any additional fees or charges.Can you write a poem about APR? - -In the realm of finance, there exists a term, -A percentage that signifies cost. -Annual Percentage Rate, or APR, you may inquire, -A comprehensive measure, complete and sincere. - -It's more than just the interest rate, mind you, -For it includes other costs, quite a bunch. -Insurance, points, and other fees they pile, -APR, in its glory, reveals the ill. - -A standardized figure, universal and bright, -Facilitating comparisons in the financial market light. -Though not the same as simple interest, which is but -The principal's price, without the extras' thrust. -So, when you borrow, look beyond the rate, -To APR's comprehensive view, be wise and sage. -For in the world of finance, transparency is key, -And understanding APR, is where it starts.Now explain APR to me like I'm 5 years old - -Sure, I'd be happy to explain APR in a simple way! - -Imagine you want to borrow some money from your friend, and they charge you a certain amount of money to lend you the money. This extra amount is like a gift they're giving you for letting them use their stuff. The Annual Percentage Rate (APR) is a way to tell you how much extra you have to pay back to your friend, including the gift and all the other little things that come with borrowing money. - -So, if your friend charges 3 apples as a gift, and you have to eat 5 apples (because you borrowed the money for a longer time than usual), then the APR is 5 apples divided by the number of apples you had to eat (which is the total cost of borrowing). In this case, the APR would be 1 apple. - -This way, you can easily understand how much more you'll be paying back to your friend compared to just the interest rate. APR helps everyone compare prices and make better decisions when borrowing money. +What is APR? +APR stands for Annual Percentage Rate. It is the annual interest rate charged for borrowing or earned through an investment, and it represents the actual yearly cost of funds over the term of a loan. It includes any fees or additional costs associated with the transaction. +Can you write a poem about APR? +In the world of finance, APR is the key, +A number that tells us what we'll pay, or earn, you see. +It's the annual rate, both simple and clear, +Including all fees, for loans and investments, near and far. + +It's the cost of borrowing, or the return we gain, +A figure that helps us make informed financial gain. +So, when you're comparing loans, or investments to choose, +Remember APR, and make the right move. +Now explain APR to me like I'm 5 years old +Sure! Imagine you have a piggy bank, and you want to borrow some money from your parents to buy a toy. Your parents will ask you to pay them back with some extra money, which is like interest. APR is the special number that tells you how much extra money you'll have to pay back, all in one year. It's like a special rule that helps you understand how much you'll owe your parents. diff --git a/tests/results/examples/tutorial/model_chaining.result b/tests/results/examples/tutorial/model_chaining.result index 511abb028..f284cf32b 100644 --- a/tests/results/examples/tutorial/model_chaining.result +++ b/tests/results/examples/tutorial/model_chaining.result @@ -1,3 +1,4 @@ -Hello, World! +Hello +Hello Translate this to French -Bonjour le monde ! +I'm sorry for the confusion, but it seems like you didn't provide any text to translate. Could you please provide the text you'd like me to translate into French? diff --git a/tests/results/examples/tutorial/muting_block_output.result b/tests/results/examples/tutorial/muting_block_output.result index 5b39e815a..3a32b5abe 100644 --- a/tests/results/examples/tutorial/muting_block_output.result +++ b/tests/results/examples/tutorial/muting_block_output.result @@ -1 +1 @@ -The french sentence was: The translation of 'I love Paris!' to French is 'J'aime Paris!'. +The french sentence was: The translation of 'I love Paris!' in French is 'Je t'aime, Paris!'. diff --git a/tests/results/examples/tutorial/variable_def_use.result b/tests/results/examples/tutorial/variable_def_use.result index 61ee55a9d..1eeb2d9b2 100644 --- a/tests/results/examples/tutorial/variable_def_use.result +++ b/tests/results/examples/tutorial/variable_def_use.result @@ -1,2 +1,2 @@ -Hello, World! -GEN is equal to: World! +Hello,Hello +GEN is equal to: Hello diff --git a/tests/results/examples/weather/weather.result b/tests/results/examples/weather/weather.result index dba3ea432..437a3c1d0 100644 --- a/tests/results/examples/weather/weather.result +++ b/tests/results/examples/weather/weather.result @@ -1,2 +1 @@ - -The temperature is 15.6 degrees Celsius and the sky is partly cloudy. +The weather in Yorktown Heights, New York, USA is currently clear with a temperature of 8.9°C (48.0°F). The wind is blowing at a speed of 5.1 mph (8.3 kph) from the north (N). The pressure is 1023.0 mb (30.2 inches). Humidity is at 49% and the wind chill is also 8.9°C (48.0°F). The dew point is 1.9°C (35.4°F) and visibility is 16.0 km (9.0 miles). There is no UV index, precipitation, or heat index reported. The gust speed is 10.8 mph (17.4 kph). diff --git a/tests/test_examples_run.py b/tests/test_examples_run.py index 7a9050d32..ff6569add 100644 --- a/tests/test_examples_run.py +++ b/tests/test_examples_run.py @@ -18,7 +18,7 @@ for name in [ pathlib.Path("examples") / "demo" / "2-teacher.pdl", # TODO: check why pathlib.Path("examples") / "talk" / "8-tools.pdl", # TODO: check why - pathlib.Path("examples") / "talk" / "11-sdg.pdl", # TODO: check why + pathlib.Path("examples") / "talk" / "10-sdg.pdl", # TODO: check why pathlib.Path("examples") / "teacher" / "teacher.pdl", # TODO: check why pathlib.Path("examples") / "tools" / "calc.pdl", # TODO: check why pathlib.Path("examples") / "tutorial" / "calling_apis.pdl", @@ -43,8 +43,9 @@ pathlib.Path("examples") / "joke" / "Joke.pdl", pathlib.Path("examples") / "react" / "multi-agent.pdl", pathlib.Path("examples") / "react" / "wikipedia.pdl", - pathlib.Path("examples") / "talk" / "11-sdg.pdl", + pathlib.Path("examples") / "talk" / "10-sdg.pdl", pathlib.Path("examples") / "talk" / "7-chatbot-roles.pdl", + pathlib.Path("examples") / "chatbot" / "chatbot.pdl", pathlib.Path("examples") / "talk" / "8-tools.pdl", pathlib.Path("examples") / "talk" / "9-react.pdl", pathlib.Path("examples") / "teacher" / "teacher.pdl", @@ -55,6 +56,7 @@ pathlib.Path("examples") / "demo" / "3-weather.pdl", pathlib.Path("examples") / "tutorial" / "conditionals_loops.pdl", pathlib.Path("examples") / "chatbot" / "chatbot.pdl", + pathlib.Path("examples") / "fibonacci" / "fib.pdl", ] } @@ -129,6 +131,7 @@ class InputsType: pathlib.Path("examples") / "hello" / "hello-type-code.pdl", pathlib.Path("examples") / "hello" / "hello-type-list.pdl", pathlib.Path("examples") / "hello" / "hello-type.pdl", + pathlib.Path("examples") / "hello" / "hello-parser-json.pdl", pathlib.Path("tests") / "data" / "line" / "hello12.pdl", pathlib.Path("tests") / "data" / "line" / "hello13.pdl", pathlib.Path("tests") / "data" / "line" / "hello14.pdl", From f72f2bbed180ddd00c799833a673ce3845542a01 Mon Sep 17 00:00:00 2001 From: Mandana Vaziri Date: Thu, 17 Oct 2024 21:10:58 -0400 Subject: [PATCH 21/24] updated to final model id Signed-off-by: Mandana Vaziri --- README.md | 6 +++--- docs/README.md | 6 +++--- examples/callback/repair_prompt.pdl | 2 +- examples/chatbot/chatbot.pdl | 2 +- examples/cldk/cldk-assistant.pdl | 6 +++--- examples/code/code-eval.pdl | 2 +- examples/code/code-json.pdl | 2 +- examples/code/code.pdl | 2 +- examples/demo/1-gen-data.pdl | 2 +- examples/demo/2-teacher.pdl | 2 +- examples/demo/3-weather.pdl | 4 ++-- examples/demo/4-translator.pdl | 4 ++-- examples/fibonacci/fib.pdl | 4 ++-- examples/granite/multi_round_chat.pdl | 2 +- examples/granite/single_round_chat.pdl | 2 +- examples/hello/hello-def-use.pdl | 2 +- examples/hello/hello-model-chaining.pdl | 4 ++-- examples/hello/hello-model-input.pdl | 2 +- examples/hello/hello-parser-json.pdl | 2 +- examples/hello/hello-parser-regex.pdl | 2 +- examples/hello/hello-roles-array.pdl | 2 +- examples/hello/hello-type.pdl | 2 +- examples/hello/hello.pdl | 2 +- examples/notebooks/demo.ipynb | 12 ++++++------ examples/notebooks/notebook.ipynb | 4 ++-- examples/notebooks/notebook_debug.ipynb | 2 +- examples/rag/rag.pdl | 2 +- examples/react/demo.pdl | 4 ++-- examples/react/react_call.pdl | 2 +- examples/react/wikipedia.pdl | 4 ++-- examples/sdk/hello.pdl | 2 +- examples/sdk/hello_dict.py | 2 +- examples/sdk/hello_prog.py | 2 +- examples/sdk/hello_str.py | 2 +- examples/talk/1-hello.pdl | 2 +- examples/talk/10-sdg.pdl | 2 +- examples/talk/2-model-chaining.pdl | 4 ++-- examples/talk/3-def-use.pdl | 4 ++-- examples/talk/4-function.pdl | 2 +- examples/talk/5-code-eval.pdl | 2 +- examples/talk/6-code-json.pdl | 2 +- examples/talk/7-chatbot-roles.pdl | 2 +- examples/talk/8-tools.pdl | 2 +- examples/talk/9-react.pdl | 4 ++-- examples/teacher/teacher.pdl | 2 +- examples/tools/calc.pdl | 2 +- examples/tutorial/calling_apis.pdl | 4 ++-- examples/tutorial/calling_llm.pdl | 2 +- examples/tutorial/calling_llm_with_input.pdl | 2 +- examples/tutorial/conditionals_loops.pdl | 2 +- examples/tutorial/data_block.pdl | 2 +- examples/tutorial/function_definition.pdl | 2 +- examples/tutorial/gen-data.pdl | 2 +- examples/tutorial/grouping_definitions.pdl | 2 +- examples/tutorial/include.pdl | 2 +- examples/tutorial/model_chaining.pdl | 4 ++-- examples/tutorial/muting_block_output.pdl | 2 +- examples/tutorial/variable_def_use.pdl | 2 +- examples/weather/weather.pdl | 4 ++-- 59 files changed, 83 insertions(+), 83 deletions(-) diff --git a/README.md b/README.md index 0a4c98d7c..a4ccf49a8 100644 --- a/README.md +++ b/README.md @@ -227,7 +227,7 @@ defs: parser: yaml text: - "\n${ CODE.source_code }\n" -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct input: - | Here is some info about the location of the function in the repo. @@ -292,7 +292,7 @@ defs: read: ./ground_truth.txt text: - "\n${ CODE.source_code }\n" -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct def: EXPLANATION input: | Here is some info about the location of the function in the repo. @@ -373,7 +373,7 @@ defs: TRUTH: read: ./ground_truth.txt text: -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct def: EXPLANATION contribute: [] input: diff --git a/docs/README.md b/docs/README.md index 0a3de7421..ad17f782a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -232,7 +232,7 @@ defs: parser: yaml text: - "\n${ CODE.source_code }\n" -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct input: - | Here is some info about the location of the function in the repo. @@ -297,7 +297,7 @@ defs: read: ./ground_truth.txt text: - "\n${ CODE.source_code }\n" -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct def: EXPLANATION input: | Here is some info about the location of the function in the repo. @@ -378,7 +378,7 @@ defs: TRUTH: read: ./ground_truth.txt text: -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct def: EXPLANATION contribute: [] input: diff --git a/examples/callback/repair_prompt.pdl b/examples/callback/repair_prompt.pdl index 306117f6d..b110be54a 100644 --- a/examples/callback/repair_prompt.pdl +++ b/examples/callback/repair_prompt.pdl @@ -9,7 +9,7 @@ contribute: [context] - def: raw_output - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: stop_sequences: "\n\n" temperature: 0 diff --git a/examples/chatbot/chatbot.pdl b/examples/chatbot/chatbot.pdl index 02e980838..9950f7774 100644 --- a/examples/chatbot/chatbot.pdl +++ b/examples/chatbot/chatbot.pdl @@ -5,7 +5,7 @@ text: contribute: [context] - repeat: text: - - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + - model: replicate/ibm-granite/granite-3.0-8b-instruct - read: def: eval message: "\nIs this a good answer[yes/no]?\n" diff --git a/examples/cldk/cldk-assistant.pdl b/examples/cldk/cldk-assistant.pdl index 5e7f6a7d2..a13ff2f04 100644 --- a/examples/cldk/cldk-assistant.pdl +++ b/examples/cldk/cldk-assistant.pdl @@ -36,7 +36,7 @@ text: - if: ${ query != 'quit'} then: text: - - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + - model: replicate/ibm-granite/granite-3.0-8b-instruct def: PDL input: - | @@ -117,7 +117,7 @@ text: method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") result = method - "\n\nGenerate a summary of method Foo\n\n" - - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + - model: replicate/ibm-granite/granite-3.0-8b-instruct ``` Question: Generate a different comment for method Foo(string) in class org.ibm.App? @@ -130,7 +130,7 @@ text: method = PDL_SESSION.cldk_state.get_method("org.ibm.App", "Foo(string)") result = method - "\n\nGenerate a different comment for method Foo(string)\n\n" - - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + - model: replicate/ibm-granite/granite-3.0-8b-instruct ``` If the query contains something about a field be sure to call a model. diff --git a/examples/code/code-eval.pdl b/examples/code/code-eval.pdl index c4595f551..fcad0997e 100644 --- a/examples/code/code-eval.pdl +++ b/examples/code/code-eval.pdl @@ -7,7 +7,7 @@ defs: read: ./ground_truth.txt text: - "\n${ CODE.source_code }\n" -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct def: EXPLANATION input: | Here is some info about the location of the function in the repo. diff --git a/examples/code/code-json.pdl b/examples/code/code-json.pdl index 095117b00..3caf38d4d 100644 --- a/examples/code/code-json.pdl +++ b/examples/code/code-json.pdl @@ -6,7 +6,7 @@ defs: TRUTH: read: ./ground_truth.txt text: -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct def: EXPLANATION contribute: [] input: diff --git a/examples/code/code.pdl b/examples/code/code.pdl index 4fdae9ca3..66f86ab79 100644 --- a/examples/code/code.pdl +++ b/examples/code/code.pdl @@ -5,7 +5,7 @@ defs: parser: yaml text: - "\n${ CODE.source_code }\n" -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct input: - | Here is some info about the location of the function in the repo. diff --git a/examples/demo/1-gen-data.pdl b/examples/demo/1-gen-data.pdl index 3b7cad2cf..dfa2ffae0 100644 --- a/examples/demo/1-gen-data.pdl +++ b/examples/demo/1-gen-data.pdl @@ -5,7 +5,7 @@ defs: parser: yaml spec: { questions: [str], answers: [obj] } text: - - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + - model: replicate/ibm-granite/granite-3.0-8b-instruct def: model_output spec: {name: str, age: int} input: diff --git a/examples/demo/2-teacher.pdl b/examples/demo/2-teacher.pdl index 2ac8c8887..b31763834 100644 --- a/examples/demo/2-teacher.pdl +++ b/examples/demo/2-teacher.pdl @@ -1,6 +1,6 @@ defs: teacher_sys_prompt: You are a very knowledgeable AI Assistant that will faithfully assist the user with their task. - teacher_model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + teacher_model: replicate/ibm-granite/granite-3.0-8b-instruct teacher_template: function: sys_prompt: str diff --git a/examples/demo/3-weather.pdl b/examples/demo/3-weather.pdl index 37d1d790b..266490b3b 100644 --- a/examples/demo/3-weather.pdl +++ b/examples/demo/3-weather.pdl @@ -4,7 +4,7 @@ text: def: QUERY message: "Ask a query: " contribute: [] -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct input: | Extract the location from the question. Question: What is the weather in London? @@ -27,7 +27,7 @@ text: parser: json contribute: [] -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct input: | Explain the weather from the following JSON: ${ WEATHER } diff --git a/examples/demo/4-translator.pdl b/examples/demo/4-translator.pdl index 51517d42a..a84af271e 100644 --- a/examples/demo/4-translator.pdl +++ b/examples/demo/4-translator.pdl @@ -1,7 +1,7 @@ description: PDL program text: - "What is APR?\n" -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct - repeat: text: - read: @@ -11,5 +11,5 @@ text: then: text: - "\n\nTranslate the above to ${ language }\n" - - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + - model: replicate/ibm-granite/granite-3.0-8b-instruct until: ${ language == 'stop' } diff --git a/examples/fibonacci/fib.pdl b/examples/fibonacci/fib.pdl index 9d9fd6d5a..394fd46cf 100644 --- a/examples/fibonacci/fib.pdl +++ b/examples/fibonacci/fib.pdl @@ -1,7 +1,7 @@ description: Fibonacci text: - def: CODE - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + model: replicate/ibm-granite/granite-3.0-8b-instruct input: "Write a Python function to compute the Fibonacci sequence. Do not include a doc string.\n\n" parameters: temperature: 0 @@ -26,5 +26,5 @@ text: contribute: [] - 'The result is: ${ RESULT }' - "\n\nExplain what the above code does and what the result means\n\n" -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct \ No newline at end of file diff --git a/examples/granite/multi_round_chat.pdl b/examples/granite/multi_round_chat.pdl index bb3529cc2..e3acd7e07 100644 --- a/examples/granite/multi_round_chat.pdl +++ b/examples/granite/multi_round_chat.pdl @@ -13,7 +13,7 @@ text: - | ${ prompt } - - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + - model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: temperature: 0 role: user \ No newline at end of file diff --git a/examples/granite/single_round_chat.pdl b/examples/granite/single_round_chat.pdl index caa975f85..917a258ed 100644 --- a/examples/granite/single_round_chat.pdl +++ b/examples/granite/single_round_chat.pdl @@ -2,7 +2,7 @@ description: Granite Single-Round Chat text: - include: ./granite_defs.pdl - "${ PROMPT }\n" -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: temperature: 0 role: user diff --git a/examples/hello/hello-def-use.pdl b/examples/hello/hello-def-use.pdl index 09662f40c..cf3f187ea 100644 --- a/examples/hello/hello-def-use.pdl +++ b/examples/hello/hello-def-use.pdl @@ -1,7 +1,7 @@ description: Hello world with variable use text: - "Hello\n" -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: decoding_method: greedy stop_sequences: '!' diff --git a/examples/hello/hello-model-chaining.pdl b/examples/hello/hello-model-chaining.pdl index aeb42c02f..a0fff6f14 100644 --- a/examples/hello/hello-model-chaining.pdl +++ b/examples/hello/hello-model-chaining.pdl @@ -1,13 +1,13 @@ description: Hello world showing model chaining text: - "Hello\n" -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: decoding_method: greedy stop_sequences: '!' def: GEN - "\nDid you say ${ GEN }?\n" -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: decoding_method: greedy stop_sequences: '.' diff --git a/examples/hello/hello-model-input.pdl b/examples/hello/hello-model-input.pdl index 16d21f3fb..acb7ae367 100644 --- a/examples/hello/hello-model-input.pdl +++ b/examples/hello/hello-model-input.pdl @@ -1,6 +1,6 @@ description: Hello world with model input text: -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct input: "Hello," parameters: stop_sequences: '!' diff --git a/examples/hello/hello-parser-json.pdl b/examples/hello/hello-parser-json.pdl index 8dcd9c454..875b53e6e 100644 --- a/examples/hello/hello-parser-json.pdl +++ b/examples/hello/hello-parser-json.pdl @@ -5,7 +5,7 @@ defs: parser: yaml spec: { questions: [str], answers: [obj] } text: - - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + - model: replicate/ibm-granite/granite-3.0-8b-instruct def: model_output spec: {name: str, age: int} input: diff --git a/examples/hello/hello-parser-regex.pdl b/examples/hello/hello-parser-regex.pdl index c9f724d8f..a62c537fd 100644 --- a/examples/hello/hello-parser-regex.pdl +++ b/examples/hello/hello-parser-regex.pdl @@ -1,6 +1,6 @@ description: Hello world with parser using regex text: -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct input: "Hello," parameters: stop_sequences: '!' diff --git a/examples/hello/hello-roles-array.pdl b/examples/hello/hello-roles-array.pdl index 63375c222..82c254a96 100644 --- a/examples/hello/hello-roles-array.pdl +++ b/examples/hello/hello-roles-array.pdl @@ -7,6 +7,6 @@ text: - role: user content: Write a Python function that implement merge sort. contribute: [] -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct input: ${ prompt } diff --git a/examples/hello/hello-type.pdl b/examples/hello/hello-type.pdl index 69563ed3f..dcdffd3af 100644 --- a/examples/hello/hello-type.pdl +++ b/examples/hello/hello-type.pdl @@ -9,7 +9,7 @@ text: spec: int return: - "\nTranslate the sentence '${ sentence }' to ${ language }\n" - - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + - model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: stop_sequences: "\n" - call: translate diff --git a/examples/hello/hello.pdl b/examples/hello/hello.pdl index 43b793206..7441cbafd 100644 --- a/examples/hello/hello.pdl +++ b/examples/hello/hello.pdl @@ -1,4 +1,4 @@ description: Hello world text: - "Hello\n" -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct diff --git a/examples/notebooks/demo.ipynb b/examples/notebooks/demo.ipynb index 236c9ea1e..da1bd1d9b 100644 --- a/examples/notebooks/demo.ipynb +++ b/examples/notebooks/demo.ipynb @@ -162,7 +162,7 @@ "%%pdl --reset-context\n", "text: \n", "- \"What is the meaning of life?\\n\"\n", - "- model: \"replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e\"" + "- model: \"replicate/ibm-granite/granite-3.0-8b-instruct\"" ] }, { @@ -213,9 +213,9 @@ "%%pdl\n", "text:\n", "- \"\\nSay it like a poem\\n\"\n", - "- model: \"replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e\"\n", + "- model: \"replicate/ibm-granite/granite-3.0-8b-instruct\"\n", "- \"\\n\\nTranslate it to French\\n\"\n", - "- model: \"replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e\"" + "- model: \"replicate/ibm-granite/granite-3.0-8b-instruct\"" ] }, { @@ -305,7 +305,7 @@ " read: ./ground_truth.txt\n", "text:\n", "- \"\\n${ code.source_code }\\n\"\n", - "- model: \"replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e\"\n", + "- model: \"replicate/ibm-granite/granite-3.0-8b-instruct\"\n", " def: explanation\n", " input: |\n", " Here is some info about the location of the function in the repo.\n", @@ -393,12 +393,12 @@ "- repeat:\n", " text:\n", " - def: thought\n", - " model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e\n", + " model: replicate/ibm-granite/granite-3.0-8b-instruct\n", " parameters:\n", " stop_sequences: \"Act:\"\n", " temperature: 0\n", " - def: rawAction\n", - " model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e\n", + " model: replicate/ibm-granite/granite-3.0-8b-instruct\n", " parameters:\n", " stop_sequences: \"\\n\"\n", " temperature: 0\n", diff --git a/examples/notebooks/notebook.ipynb b/examples/notebooks/notebook.ipynb index fc6930ff9..eeba55899 100644 --- a/examples/notebooks/notebook.ipynb +++ b/examples/notebooks/notebook.ipynb @@ -30,7 +30,7 @@ "description: Model call\n", "text: \n", "- \"Hello\\n\"\n", - "- model: \"replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e\"\n", + "- model: \"replicate/ibm-granite/granite-3.0-8b-instruct\"\n", " parameters:\n", " stop_sequences: \"!\"\n", " " @@ -89,7 +89,7 @@ " read: ./ground_truth.txt\n", "text:\n", "- \"\\n${ CODE.source_code }\\n\"\n", - "- model: \"replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e\"\n", + "- model: \"replicate/ibm-granite/granite-3.0-8b-instruct\"\n", " def: EXPLANATION\n", " input: |\n", " Here is some info about the location of the function in the repo.\n", diff --git a/examples/notebooks/notebook_debug.ipynb b/examples/notebooks/notebook_debug.ipynb index f94556c75..744ef498a 100644 --- a/examples/notebooks/notebook_debug.ipynb +++ b/examples/notebooks/notebook_debug.ipynb @@ -164,7 +164,7 @@ "description: Model call\n", "text: \n", "- Hello,\n", - "- model: \"replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e\"\n", + "- model: \"replicate/ibm-granite/granite-3.0-8b-instruct\"\n", " parameters:\n", " stop_sequences: \"!\"" ] diff --git a/examples/rag/rag.pdl b/examples/rag/rag.pdl index 17bf5079e..d5b67093d 100644 --- a/examples/rag/rag.pdl +++ b/examples/rag/rag.pdl @@ -43,4 +43,4 @@ text: Q: ${ TEST_PROMPT } A: -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct diff --git a/examples/react/demo.pdl b/examples/react/demo.pdl index 4a8e10dc2..0116ac672 100644 --- a/examples/react/demo.pdl +++ b/examples/react/demo.pdl @@ -35,12 +35,12 @@ text: - repeat: text: - def: thought - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: stop_sequences: "Act:" temperature: 0 - def: rawAction - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: stop_sequences: "\n" temperature: 0 diff --git a/examples/react/react_call.pdl b/examples/react/react_call.pdl index cdac66de3..2ad7043a8 100644 --- a/examples/react/react_call.pdl +++ b/examples/react/react_call.pdl @@ -4,6 +4,6 @@ text: - call: react args: question: How many years ago was the discoverer of the Hudson River born? Keep in mind we are in 2024. - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + model: replicate/ibm-granite/granite-3.0-8b-instruct diff --git a/examples/react/wikipedia.pdl b/examples/react/wikipedia.pdl index ef4423150..114b3932e 100644 --- a/examples/react/wikipedia.pdl +++ b/examples/react/wikipedia.pdl @@ -47,12 +47,12 @@ text: - repeat: text: - def: thought - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: stop_sequences: "Act:" temperature: 0 - def: rawAction - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: stop_sequences: "\n" temperature: 0 diff --git a/examples/sdk/hello.pdl b/examples/sdk/hello.pdl index ba88cc7aa..28ef61974 100644 --- a/examples/sdk/hello.pdl +++ b/examples/sdk/hello.pdl @@ -1,5 +1,5 @@ text: - "Hello\n" -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: stop_sequences: '!' diff --git a/examples/sdk/hello_dict.py b/examples/sdk/hello_dict.py index 2f537074f..d7cd2b031 100644 --- a/examples/sdk/hello_dict.py +++ b/examples/sdk/hello_dict.py @@ -4,7 +4,7 @@ "text": [ "Hello\n", { - "model": "replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e", + "model": "replicate/ibm-granite/granite-3.0-8b-instruct", "parameters": {"stop_sequences": "!"}, }, ] diff --git a/examples/sdk/hello_prog.py b/examples/sdk/hello_prog.py index ad094422b..a458ce182 100644 --- a/examples/sdk/hello_prog.py +++ b/examples/sdk/hello_prog.py @@ -6,7 +6,7 @@ text=[ "Hello\n", LitellmModelBlock( - model="replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e", + model="replicate/ibm-granite/granite-3.0-8b-instruct", parameters=LitellmParameters( stop_sequences="!" # pyright: ignore ), diff --git a/examples/sdk/hello_str.py b/examples/sdk/hello_str.py index 315ee82ba..48d8b2ba7 100644 --- a/examples/sdk/hello_str.py +++ b/examples/sdk/hello_str.py @@ -3,7 +3,7 @@ HELLO = """ text: - "Hello\n" -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: stop_sequences: '!' """ diff --git a/examples/talk/1-hello.pdl b/examples/talk/1-hello.pdl index 35ad74ba5..2bd0a8d62 100644 --- a/examples/talk/1-hello.pdl +++ b/examples/talk/1-hello.pdl @@ -1,7 +1,7 @@ description: Model call text: - "Hello\n" -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: stop_sequences: "!" include_stop_sequence: true diff --git a/examples/talk/10-sdg.pdl b/examples/talk/10-sdg.pdl index 2ac8c8887..b31763834 100644 --- a/examples/talk/10-sdg.pdl +++ b/examples/talk/10-sdg.pdl @@ -1,6 +1,6 @@ defs: teacher_sys_prompt: You are a very knowledgeable AI Assistant that will faithfully assist the user with their task. - teacher_model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + teacher_model: replicate/ibm-granite/granite-3.0-8b-instruct teacher_template: function: sys_prompt: str diff --git a/examples/talk/2-model-chaining.pdl b/examples/talk/2-model-chaining.pdl index 550014187..185052cbc 100644 --- a/examples/talk/2-model-chaining.pdl +++ b/examples/talk/2-model-chaining.pdl @@ -1,11 +1,11 @@ description: Model chaining text: - "Hello\n" -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: stop_sequences: "!" - "\nTranslate this to French\n" -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: stop_sequences: "!" \ No newline at end of file diff --git a/examples/talk/3-def-use.pdl b/examples/talk/3-def-use.pdl index 7ba93f278..325668cca 100644 --- a/examples/talk/3-def-use.pdl +++ b/examples/talk/3-def-use.pdl @@ -1,12 +1,12 @@ description: Variable def and use, model input text: - "Hello\n" -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct def: name parameters: stop_sequences: "!" - "\n" -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct input: - "Translate the word ${ name | trim } to French\n" parameters: diff --git a/examples/talk/4-function.pdl b/examples/talk/4-function.pdl index a297a7c5c..15751c436 100644 --- a/examples/talk/4-function.pdl +++ b/examples/talk/4-function.pdl @@ -6,7 +6,7 @@ text: language: str return: - "\nTranslate the sentence '${ sentence }' to ${ language }.\n" - - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + - model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: stop_sequences: "\n" temperature: 0 diff --git a/examples/talk/5-code-eval.pdl b/examples/talk/5-code-eval.pdl index d29aec449..b61e6b7ae 100644 --- a/examples/talk/5-code-eval.pdl +++ b/examples/talk/5-code-eval.pdl @@ -7,7 +7,7 @@ defs: read: ./ground_truth.txt text: - "\n${ CODE.source_code }\n" -- model: ireplicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct def: EXPLANATION input: | Here is some info about the location of the function in the repo. diff --git a/examples/talk/6-code-json.pdl b/examples/talk/6-code-json.pdl index e5dbc79d9..cfb8561f9 100644 --- a/examples/talk/6-code-json.pdl +++ b/examples/talk/6-code-json.pdl @@ -6,7 +6,7 @@ defs: TRUTH: read: ./ground_truth.txt text: -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct def: EXPLANATION contribute: [] input: diff --git a/examples/talk/7-chatbot-roles.pdl b/examples/talk/7-chatbot-roles.pdl index c0f4ebcad..5833970bb 100644 --- a/examples/talk/7-chatbot-roles.pdl +++ b/examples/talk/7-chatbot-roles.pdl @@ -10,7 +10,7 @@ text: message: ">>> " def: query contribute: [context] - - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + - model: replicate/ibm-granite/granite-3.0-8b-instruct - "\n\n" until: ${ query == 'quit'} join: diff --git a/examples/talk/8-tools.pdl b/examples/talk/8-tools.pdl index 80f5d7f87..c90faba59 100644 --- a/examples/talk/8-tools.pdl +++ b/examples/talk/8-tools.pdl @@ -17,7 +17,7 @@ text: Out of 1400 participants, 400 passed the test. What percentage is that? - "\n" - def: rawAction - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: stop_sequences: "\n" - def: action diff --git a/examples/talk/9-react.pdl b/examples/talk/9-react.pdl index ef4423150..114b3932e 100644 --- a/examples/talk/9-react.pdl +++ b/examples/talk/9-react.pdl @@ -47,12 +47,12 @@ text: - repeat: text: - def: thought - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: stop_sequences: "Act:" temperature: 0 - def: rawAction - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: stop_sequences: "\n" temperature: 0 diff --git a/examples/teacher/teacher.pdl b/examples/teacher/teacher.pdl index 2ac8c8887..b31763834 100644 --- a/examples/teacher/teacher.pdl +++ b/examples/teacher/teacher.pdl @@ -1,6 +1,6 @@ defs: teacher_sys_prompt: You are a very knowledgeable AI Assistant that will faithfully assist the user with their task. - teacher_model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + teacher_model: replicate/ibm-granite/granite-3.0-8b-instruct teacher_template: function: sys_prompt: str diff --git a/examples/tools/calc.pdl b/examples/tools/calc.pdl index 80f5d7f87..c90faba59 100644 --- a/examples/tools/calc.pdl +++ b/examples/tools/calc.pdl @@ -17,7 +17,7 @@ text: Out of 1400 participants, 400 passed the test. What percentage is that? - "\n" - def: rawAction - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: stop_sequences: "\n" - def: action diff --git a/examples/tutorial/calling_apis.pdl b/examples/tutorial/calling_apis.pdl index 37d1d790b..266490b3b 100644 --- a/examples/tutorial/calling_apis.pdl +++ b/examples/tutorial/calling_apis.pdl @@ -4,7 +4,7 @@ text: def: QUERY message: "Ask a query: " contribute: [] -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct input: | Extract the location from the question. Question: What is the weather in London? @@ -27,7 +27,7 @@ text: parser: json contribute: [] -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct input: | Explain the weather from the following JSON: ${ WEATHER } diff --git a/examples/tutorial/calling_llm.pdl b/examples/tutorial/calling_llm.pdl index 82053ee3e..88cb6efa9 100644 --- a/examples/tutorial/calling_llm.pdl +++ b/examples/tutorial/calling_llm.pdl @@ -1,7 +1,7 @@ description: Hello world calling a model text: - "Hello\n" -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: decoding_method: greedy stop_sequences: '!' \ No newline at end of file diff --git a/examples/tutorial/calling_llm_with_input.pdl b/examples/tutorial/calling_llm_with_input.pdl index 548fa2e60..3a1f15cea 100644 --- a/examples/tutorial/calling_llm_with_input.pdl +++ b/examples/tutorial/calling_llm_with_input.pdl @@ -1,6 +1,6 @@ description: Hello world calling a model text: - "Hello, " -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct input: Translate the word 'world' to French diff --git a/examples/tutorial/conditionals_loops.pdl b/examples/tutorial/conditionals_loops.pdl index 78b767b4d..2ae7078d9 100644 --- a/examples/tutorial/conditionals_loops.pdl +++ b/examples/tutorial/conditionals_loops.pdl @@ -5,7 +5,7 @@ text: contribute: [context] - repeat: text: - - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + - model: replicate/ibm-granite/granite-3.0-8b-instruct - read: def: eval message: "\nIs this a good answer[yes/no]?\n" diff --git a/examples/tutorial/data_block.pdl b/examples/tutorial/data_block.pdl index 068e54bd2..1dd78d532 100644 --- a/examples/tutorial/data_block.pdl +++ b/examples/tutorial/data_block.pdl @@ -6,7 +6,7 @@ defs: TRUTH: read: ./ground_truth.txt lastOf: -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct def: EXPLANATION input: | diff --git a/examples/tutorial/function_definition.pdl b/examples/tutorial/function_definition.pdl index a297a7c5c..15751c436 100644 --- a/examples/tutorial/function_definition.pdl +++ b/examples/tutorial/function_definition.pdl @@ -6,7 +6,7 @@ text: language: str return: - "\nTranslate the sentence '${ sentence }' to ${ language }.\n" - - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + - model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: stop_sequences: "\n" temperature: 0 diff --git a/examples/tutorial/gen-data.pdl b/examples/tutorial/gen-data.pdl index 86033040b..a22c2d376 100644 --- a/examples/tutorial/gen-data.pdl +++ b/examples/tutorial/gen-data.pdl @@ -5,7 +5,7 @@ defs: parser: yaml spec: { questions: [str], answers: [obj] } text: - - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + - model: replicate/ibm-granite/granite-3.0-8b-instruct def: model_output spec: {name: str, age: int} input: diff --git a/examples/tutorial/grouping_definitions.pdl b/examples/tutorial/grouping_definitions.pdl index db34dfaaa..88cf3e05b 100644 --- a/examples/tutorial/grouping_definitions.pdl +++ b/examples/tutorial/grouping_definitions.pdl @@ -6,7 +6,7 @@ defs: language: str return: - "\nTranslate the sentence '${ sentence }' to ${ language }.\n" - - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + - model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: stop_sequences: "\n" text: diff --git a/examples/tutorial/include.pdl b/examples/tutorial/include.pdl index 866880268..5f95e5e36 100644 --- a/examples/tutorial/include.pdl +++ b/examples/tutorial/include.pdl @@ -13,7 +13,7 @@ text: - | ${ prompt } - - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + - model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: decoding_method: sample max_new_tokens: 512 diff --git a/examples/tutorial/model_chaining.pdl b/examples/tutorial/model_chaining.pdl index 9c067db0c..dd6b488d9 100644 --- a/examples/tutorial/model_chaining.pdl +++ b/examples/tutorial/model_chaining.pdl @@ -1,10 +1,10 @@ description: Model chaining text: - "Hello\n" -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: stop_sequences: "!" - "\nTranslate this to French\n" -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: stop_sequences: "!" diff --git a/examples/tutorial/muting_block_output.pdl b/examples/tutorial/muting_block_output.pdl index 84d42c81b..ce1b0bf80 100644 --- a/examples/tutorial/muting_block_output.pdl +++ b/examples/tutorial/muting_block_output.pdl @@ -6,7 +6,7 @@ defs: language: str return: - "\nTranslate the sentence '${ sentence }' to ${ language }.\n" - - model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e + - model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: stop_sequences: "\n" text: diff --git a/examples/tutorial/variable_def_use.pdl b/examples/tutorial/variable_def_use.pdl index 6dc36df61..235392089 100644 --- a/examples/tutorial/variable_def_use.pdl +++ b/examples/tutorial/variable_def_use.pdl @@ -1,7 +1,7 @@ description: Hello world with variable def and use text: - Hello, -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct def: GEN parameters: decoding_method: greedy diff --git a/examples/weather/weather.pdl b/examples/weather/weather.pdl index 37d1d790b..266490b3b 100644 --- a/examples/weather/weather.pdl +++ b/examples/weather/weather.pdl @@ -4,7 +4,7 @@ text: def: QUERY message: "Ask a query: " contribute: [] -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct input: | Extract the location from the question. Question: What is the weather in London? @@ -27,7 +27,7 @@ text: parser: json contribute: [] -- model: replicate/ibm-granite/granite-3.0-8b-instruct:8d8fb55950fb8eb2817fc078b7b05a0bd3ecc612d6332d8009fb0c007839192e +- model: replicate/ibm-granite/granite-3.0-8b-instruct input: | Explain the weather from the following JSON: ${ WEATHER } From 6d9af32087c66fa559d2e84f8a9c0344268cad17 Mon Sep 17 00:00:00 2001 From: Mandana Vaziri Date: Fri, 18 Oct 2024 07:46:01 -0400 Subject: [PATCH 22/24] updates Signed-off-by: Mandana Vaziri --- examples/cldk/README.md | 2 +- examples/code/README.md | 6 +++--- examples/input/input_test1.pdl | 4 +++- examples/rag/README.md | 4 ++++ examples/talk/out.json | 1 - out.json | 1 - 6 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 examples/rag/README.md delete mode 100644 examples/talk/out.json delete mode 100644 out.json diff --git a/examples/cldk/README.md b/examples/cldk/README.md index 104a41a9f..ce34fd191 100644 --- a/examples/cldk/README.md +++ b/examples/cldk/README.md @@ -12,7 +12,7 @@ wget https://github.com/apache/commons-cli/archive/refs/tags/rel/commons-cli-1.7 To run the CLDK assistant: ``` -pdl examples/cldk/cldk-assistant.pdl +pdl cldk-assistant.pdl ``` Enter the path to the above Java project when prompted. Then you can make queries such as "what are all the classes?". \ No newline at end of file diff --git a/examples/code/README.md b/examples/code/README.md index c0c1ecb04..758c4ac8e 100644 --- a/examples/code/README.md +++ b/examples/code/README.md @@ -15,7 +15,7 @@ public static Map deserializeOffsetMap(String lastSourceOffset) } ``` -We have some information about the repository for this code stored in a JSON [file](examples/code/data.json), such as repository name, path and filename. Using that data, we wish to formulate a prompt as follows: +We have some information about the repository for this code stored in a JSON [file](./data.yaml), such as repository name, path and filename. Using that data, we wish to formulate a prompt as follows: ``` Here is some info about the location of the function in the repo. @@ -38,5 +38,5 @@ public static Map deserializeOffsetMap(String lastSourceOffset) } ``` -The PDL program for this example can be found [here](examples/code/code.yaml). This example also contains a comparison with some ground truth for evaluation and outputs a text similarity metric ([code-eval.pdl](examples/code/code-eval.yaml)). -The program [code-json.pdl](examples/code/code-json.yaml) outputs its results in JSON format. \ No newline at end of file +The PDL program for this example can be found [here](code.pdl). This example also contains a comparison with some ground truth for evaluation and outputs a text similarity metric ([code-eval.pdl](code-eval.pdl)). +The program [code-json.pdl](code-json.pdl) outputs its results in JSON format. \ No newline at end of file diff --git a/examples/input/input_test1.pdl b/examples/input/input_test1.pdl index 637c04aab..ae94e94d9 100644 --- a/examples/input/input_test1.pdl +++ b/examples/input/input_test1.pdl @@ -4,4 +4,6 @@ text: - read: message: "Please provide an input: " def: STDIN -- get: STDIN + contribute: [] +- ${ STDIN } + diff --git a/examples/rag/README.md b/examples/rag/README.md new file mode 100644 index 000000000..add819ee1 --- /dev/null +++ b/examples/rag/README.md @@ -0,0 +1,4 @@ +This example requires you to install: +``` +pip install scikit-learn +``` \ No newline at end of file diff --git a/examples/talk/out.json b/examples/talk/out.json deleted file mode 100644 index 52f290708..000000000 --- a/examples/talk/out.json +++ /dev/null @@ -1 +0,0 @@ -{"kind": "text", "description": "Code explanation example", "defs": {"CODE": {"kind": "read", "defs": {}, "read": "./data.yaml", "message": null, "multiline": false, "result": "source_code: \n |\n @SuppressWarnings(\"unchecked\")\n public static Map deserializeOffsetMap(String lastSourceOffset) throws IOException {\n Map offsetMap;\n if (lastSourceOffset == null || lastSourceOffset.isEmpty()) { \n offsetMap = new HashMap<>(); \n } else {\n offsetMap = JSON_MAPPER.readValue(lastSourceOffset, Map.class); \n }\n return offsetMap;\n }\nrepo_info: \n repo: streamsets/datacollector\n path: stagesupport/src/main/java/com/.../OffsetUtil.java\n function_name: OffsetUtil.deserializeOffsetMap", "parser": "yaml"}, "TRUTH": {"kind": "read", "defs": {}, "read": "./ground_truth.txt", "message": null, "multiline": false, "result": "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.\n\nThe `@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."}}, "text": ["\n@SuppressWarnings(\"unchecked\")\npublic static Map deserializeOffsetMap(String lastSourceOffset) throws IOException {\n Map offsetMap;\n if (lastSourceOffset == null || lastSourceOffset.isEmpty()) { \n offsetMap = new HashMap<>(); \n } else {\n offsetMap = JSON_MAPPER.readValue(lastSourceOffset, Map.class); \n }\n return offsetMap;\n}\n\n", {"kind": "model", "defs": {}, "platform": "litellm", "model": "watsonx/ibm/granite-34b-code-instruct", "input": "Here is some info about the location of the function in the repo.\nrepo: \n${ CODE.repo_info.repo }\npath: ${ CODE.repo_info.path }\nFunction_name: ${ CODE.repo_info.function_name }\n\n\nExplain the following code:\n```\n${ CODE.source_code }```\n", "def": "EXPLANATION", "result": "\nThe 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.\n\nThe `@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."}, "\n\nEVALUATION:\nThe similarity (Levenshtein) between this answer and the ground truth is:\n", {"kind": "code", "defs": {}, "lang": "python", "code": "import textdistance\nexpl = \"\"\"\n\nThe 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.\n\nThe `@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.\n\"\"\"\ntruth = \"\"\"\nThe 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.\n\nThe `@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.\n\"\"\"\nresult = textdistance.levenshtein.normalized_similarity(expl, truth)\n", "def": "EVAL", "result": 0.9983818770226537}], "result": "\n@SuppressWarnings(\"unchecked\")\npublic static Map deserializeOffsetMap(String lastSourceOffset) throws IOException {\n Map offsetMap;\n if (lastSourceOffset == null || lastSourceOffset.isEmpty()) { \n offsetMap = new HashMap<>(); \n } else {\n offsetMap = JSON_MAPPER.readValue(lastSourceOffset, Map.class); \n }\n return offsetMap;\n}\n\n\nThe 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.\n\nThe `@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.\n\nEVALUATION:\nThe similarity (Levenshtein) between this answer and the ground truth is:\n0.9983818770226537"} \ No newline at end of file diff --git a/out.json b/out.json deleted file mode 100644 index 52f290708..000000000 --- a/out.json +++ /dev/null @@ -1 +0,0 @@ -{"kind": "text", "description": "Code explanation example", "defs": {"CODE": {"kind": "read", "defs": {}, "read": "./data.yaml", "message": null, "multiline": false, "result": "source_code: \n |\n @SuppressWarnings(\"unchecked\")\n public static Map deserializeOffsetMap(String lastSourceOffset) throws IOException {\n Map offsetMap;\n if (lastSourceOffset == null || lastSourceOffset.isEmpty()) { \n offsetMap = new HashMap<>(); \n } else {\n offsetMap = JSON_MAPPER.readValue(lastSourceOffset, Map.class); \n }\n return offsetMap;\n }\nrepo_info: \n repo: streamsets/datacollector\n path: stagesupport/src/main/java/com/.../OffsetUtil.java\n function_name: OffsetUtil.deserializeOffsetMap", "parser": "yaml"}, "TRUTH": {"kind": "read", "defs": {}, "read": "./ground_truth.txt", "message": null, "multiline": false, "result": "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.\n\nThe `@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."}}, "text": ["\n@SuppressWarnings(\"unchecked\")\npublic static Map deserializeOffsetMap(String lastSourceOffset) throws IOException {\n Map offsetMap;\n if (lastSourceOffset == null || lastSourceOffset.isEmpty()) { \n offsetMap = new HashMap<>(); \n } else {\n offsetMap = JSON_MAPPER.readValue(lastSourceOffset, Map.class); \n }\n return offsetMap;\n}\n\n", {"kind": "model", "defs": {}, "platform": "litellm", "model": "watsonx/ibm/granite-34b-code-instruct", "input": "Here is some info about the location of the function in the repo.\nrepo: \n${ CODE.repo_info.repo }\npath: ${ CODE.repo_info.path }\nFunction_name: ${ CODE.repo_info.function_name }\n\n\nExplain the following code:\n```\n${ CODE.source_code }```\n", "def": "EXPLANATION", "result": "\nThe 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.\n\nThe `@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."}, "\n\nEVALUATION:\nThe similarity (Levenshtein) between this answer and the ground truth is:\n", {"kind": "code", "defs": {}, "lang": "python", "code": "import textdistance\nexpl = \"\"\"\n\nThe 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.\n\nThe `@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.\n\"\"\"\ntruth = \"\"\"\nThe 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.\n\nThe `@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.\n\"\"\"\nresult = textdistance.levenshtein.normalized_similarity(expl, truth)\n", "def": "EVAL", "result": 0.9983818770226537}], "result": "\n@SuppressWarnings(\"unchecked\")\npublic static Map deserializeOffsetMap(String lastSourceOffset) throws IOException {\n Map offsetMap;\n if (lastSourceOffset == null || lastSourceOffset.isEmpty()) { \n offsetMap = new HashMap<>(); \n } else {\n offsetMap = JSON_MAPPER.readValue(lastSourceOffset, Map.class); \n }\n return offsetMap;\n}\n\n\nThe 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.\n\nThe `@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.\n\nEVALUATION:\nThe similarity (Levenshtein) between this answer and the ground truth is:\n0.9983818770226537"} \ No newline at end of file From c5739458d4a5e8988225ec5507141e69cdbbd0ee Mon Sep 17 00:00:00 2001 From: Mandana Vaziri Date: Fri, 18 Oct 2024 08:42:13 -0400 Subject: [PATCH 23/24] updates Signed-off-by: Mandana Vaziri --- tests/results/examples/demo/3-weather.result | 2 +- tests/results/examples/input/input_test1.result | 2 +- .../examples/tutorial/calling_llm_with_input_messages.result | 1 + tests/results/examples/weather/weather.result | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 tests/results/examples/tutorial/calling_llm_with_input_messages.result diff --git a/tests/results/examples/demo/3-weather.result b/tests/results/examples/demo/3-weather.result index 437a3c1d0..72444d62d 100644 --- a/tests/results/examples/demo/3-weather.result +++ b/tests/results/examples/demo/3-weather.result @@ -1 +1 @@ -The weather in Yorktown Heights, New York, USA is currently clear with a temperature of 8.9°C (48.0°F). The wind is blowing at a speed of 5.1 mph (8.3 kph) from the north (N). The pressure is 1023.0 mb (30.2 inches). Humidity is at 49% and the wind chill is also 8.9°C (48.0°F). The dew point is 1.9°C (35.4°F) and visibility is 16.0 km (9.0 miles). There is no UV index, precipitation, or heat index reported. The gust speed is 10.8 mph (17.4 kph). +The weather in Yorktown Heights, New York, USA is currently sunny with a temperature of 46°F (7.8°C). The wind is blowing at a speed of 4.5 mph (7.2 kph) from the north-northwest (NNW) direction. The pressure is 30.39 inches of mercury (1029.0 mb). Humidity is at 65% and the dew point is 32.7°F (0.4°C). Visibility is 9 miles (16.0 km). There is no precipitation and the UV index is 0. The wind gusts can reach up to 14.5 kph (9.0 mph). diff --git a/tests/results/examples/input/input_test1.result b/tests/results/examples/input/input_test1.result index 8c7d795e5..18d0688d7 100644 --- a/tests/results/examples/input/input_test1.result +++ b/tests/results/examples/input/input_test1.result @@ -1,2 +1,2 @@ The following will prompt the user on stdin. -HelloHello +Hello diff --git a/tests/results/examples/tutorial/calling_llm_with_input_messages.result b/tests/results/examples/tutorial/calling_llm_with_input_messages.result new file mode 100644 index 000000000..dd5023c7d --- /dev/null +++ b/tests/results/examples/tutorial/calling_llm_with_input_messages.result @@ -0,0 +1 @@ +Hello, as 'monde'. diff --git a/tests/results/examples/weather/weather.result b/tests/results/examples/weather/weather.result index 437a3c1d0..72444d62d 100644 --- a/tests/results/examples/weather/weather.result +++ b/tests/results/examples/weather/weather.result @@ -1 +1 @@ -The weather in Yorktown Heights, New York, USA is currently clear with a temperature of 8.9°C (48.0°F). The wind is blowing at a speed of 5.1 mph (8.3 kph) from the north (N). The pressure is 1023.0 mb (30.2 inches). Humidity is at 49% and the wind chill is also 8.9°C (48.0°F). The dew point is 1.9°C (35.4°F) and visibility is 16.0 km (9.0 miles). There is no UV index, precipitation, or heat index reported. The gust speed is 10.8 mph (17.4 kph). +The weather in Yorktown Heights, New York, USA is currently sunny with a temperature of 46°F (7.8°C). The wind is blowing at a speed of 4.5 mph (7.2 kph) from the north-northwest (NNW) direction. The pressure is 30.39 inches of mercury (1029.0 mb). Humidity is at 65% and the dew point is 32.7°F (0.4°C). Visibility is 9 miles (16.0 km). There is no precipitation and the UV index is 0. The wind gusts can reach up to 14.5 kph (9.0 mph). From df2b3d152ceff2531a7ddf8eba61fc432070ff56 Mon Sep 17 00:00:00 2001 From: Mandana Vaziri Date: Fri, 18 Oct 2024 11:02:40 -0400 Subject: [PATCH 24/24] updates Signed-off-by: Mandana Vaziri --- docs/tutorial.md | 446 +++++------------- examples/talk/2-model-chaining.pdl | 2 +- examples/tutorial/calling_llm.pdl | 1 - examples/tutorial/calling_llm_with_input.pdl | 4 +- .../calling_llm_with_input_messages.pdl | 6 +- examples/tutorial/model_chaining.pdl | 2 +- examples/tutorial/variable_def_use.pdl | 4 +- tests/results/examples/demo/3-weather.result | 2 +- .../examples/talk/2-model-chaining.result | 4 +- .../tutorial/calling_llm_with_input.result | 3 +- .../calling_llm_with_input_messages.result | 3 +- .../examples/tutorial/model_chaining.result | 4 +- .../examples/tutorial/variable_def_use.result | 3 +- tests/results/examples/weather/weather.result | 2 +- 14 files changed, 137 insertions(+), 349 deletions(-) diff --git a/docs/tutorial.md b/docs/tutorial.md index e9d15007d..973824137 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -36,8 +36,8 @@ Hello, world! --8<-- "./examples/tutorial/calling_llm.pdl" ``` -In this program ([file](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/calling_llm.pdl)), the `text` starts with the word `Hello,`, and we call a model (`watsonx/ibm/granite-34b-code-instruct`) with this as input prompt. Notice the watsonx model id on LiteLLM. -The model is passed some parameters including the `decoding_method` and `stop`, which corresponds to the `stop_sequences` parameter in watsonx. The stop sequences are to be included in the output. +In this program ([file](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/calling_llm.pdl)), the `text` starts with the word `"Hello\n"`, and we call a model (`replicate/ibm-granite/granite-3.0-8b-instruct`) with this as input prompt. +The model is passed a parameter `stop_sequences`. A PDL program computes 2 data structures. The first is a JSON corresponding to the result of the overall program, obtained by aggregating the results of each block. This is what is printed by default when we run the interpreter. The second is a conversational background context, which is a list of role/content pairs, where we implicitly keep track of roles and content for the purpose of communicating with models that support chat APIs. The contents in the latter correspond to the results of each block. The conversational background context is what is used to make calls to LLMs via LiteLLM. @@ -47,23 +47,24 @@ default role `user`. When we execute this program using the interpreter, we obtain: ``` -Hello, world! +Hello +Hello ``` -where the portion ` world!` has been generated by Granite. +where the second `Hello` has been generated by Granite. -Here's another of model call that includes an `input` field ([file](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/calling_llm_with_input.pdl)): +Here's another example of model call that includes an `input` field ([file](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/calling_llm_with_input.pdl)): ```yaml --8<-- "./examples/tutorial/calling_llm_with_input.pdl" ``` -In this case, we make a call to the granite multilingual model, and the input passed to the model is the sentence: `Translate the word 'world' to French` and nothing else from the surrounding document. When we execute this program, we obtain: +In this case, the input passed to the model is the sentence: `Translate the word 'Hello' to French` and nothing else from the surrounding document. When we execute this program, we obtain: ``` -Hello, : -Le mot 'world' en français est 'monde'. +Hello +The word 'Hello' translates to 'Bonjour' in French. ``` -where everything after the `:` including it were generated by the model. +where the second line is generated by the model. Using the `input` field, we can also give a directly an array of messages (`role`/`content`) to the model ([file](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/calling_llm_with_input_messages.pdl)): @@ -71,15 +72,17 @@ Using the `input` field, we can also give a directly an array of messages (`role --8<-- "./examples/tutorial/calling_llm_with_input_messages.pdl" ``` +This has the same output as the previous program. + ### Parameter defaults for watsonx Granite models -PDL provides the following defaults for watsonx Granite models, when the following parameters are missing: - - `decoding_method`: `greedy` +When using Granite models, we use the following defaults for model parameters (except `granite-20b-code-instruct-r1.1`): + - `decoding_method`: `greedy`, (`temperature`: 0) - `max_new_tokens`: 1024 - `min_new_tokens`: 1 - `repetition_penalty`: 1.05 - -Also if the `decoding_method` is `sample`, then the following defaults are used: + + Also if the `decoding_method` is `sample`, then the following defaults are used: - `temperature`: 0.7 - `top_p`: 0.85 - `top_k`: 50 @@ -98,12 +101,14 @@ Consider the following example ([file](https://github.com/IBM/prompt-declaration --8<-- "./examples/tutorial/variable_def_use.pdl" ``` -Here we assign the output of the model to variable `GEN` using the `def` field. The last line of the program prints out the value of `GEN`. Notice the notation `${ }` for accessing the value of a variable. +Here we assign the output of the model to variable `GEN` using the `def` field. The last line of the program prints out the value of `GEN`. Notice the notation `${ }` for accessing the value of a variable. Any [Jinja](https://jinja.palletsprojects.com/en/3.1.x/) expression is allowed to be used inside these braces. These expressions +are also used to specify conditions for loops and conditionals. See for example this [file](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/conditionals_loops.pdl). When we execute this program, we obtain: ``` -Hello, world! -GEN is equal to: world! +Hello +Hello +GEN is equal to: Hello ``` ## Model Chaining @@ -119,9 +124,10 @@ In this program, the first call is to a granite model to complete the sentence ` When we execute this program, we obtain: ``` -Hello, World! -Translate this to French -Bonjour le monde ! +Hello +Hello +Did you just say Hello? +Yes, I did. How can I assist you today? ``` @@ -131,27 +137,9 @@ Bonjour le monde ! PDL also supports function definitions to make it easier to reuse code. Suppose we want to define a translation function that takes a string and calls a falcon model for the translation. This would be written in PDL as follows ([file](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/function_definition.pdl)): + ```yaml -description: function def and call -text: -- def: translate - function: - sentence: str - language: str - return: - - "\nTranslate the sentence '${ sentence }' to ${ language }.\n" - - model: watsonx/ibm/granite-20b-multilingual - parameters: - stop: ["\n"] -- call: translate - args: - sentence: I love Paris! - language: French -- "\n" -- call: translate - args: - sentence: I love Madrid! - language: Spanish +--8<-- "./examples/tutorial/function_definition.pdl" ``` In this program, the first block defines a function `translate` that takes as parameters `sentence` and `language`, both of which are of type string. The body of the function is defined by its `return` field. In this case, we formulate a translation prompt using the parameters and send it to a Granite multilingual model. @@ -165,6 +153,8 @@ The translation of 'I love Madrid!' to Spanish is 'Me encanta Madrid!'. A function only contributes to the output document when it is called. So the definition itself results in `""`. When we call a function, we implicitly pass the current background context, and this is used as input to model calls inside the function body. In the above example, since the `input` field is omitted, the entire document produced at that point is passed as input to the granite model. +To reset the context when calling a function, we can pass the special argument: `pdl_context: []`. + Notice that the arguments of function calls are expressions and cannot be arbitrary PDL blocks. ## Grouping Variable Definitions in Defs @@ -172,29 +162,10 @@ Notice that the arguments of function calls are expressions and cannot be arbitr In PDL, the above program can be written more neatly by grouping certain variable definitions into a `defs` section, as follows ([file](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/grouping_definitions.pdl)): ```yaml -description: function def and call -defs: - translate: - function: - sentence: str - language: str - return: - - "\nTranslate the sentence '${ sentence }' to ${ language }.\n" - - model: watsonx/ibm/granite-20b-multilingual - parameters: - stop: ["\n"] -text: -- call: translate - args: - sentence: I love Paris! - language: French -- "\n" -- call: translate - args: - sentence: I love Madrid! - language: Spanish +--8<-- "./examples/tutorial/grouping_definitions.pdl" ``` + This program has the same output has the one from the previous section. @@ -203,30 +174,13 @@ This program has the same output has the one from the previous section. By default, when a PDL block is executed it produces a result that is contributed to the overall result, and it also contributes to the background context. It is possible to mute both contributions by setting `contribute` to `[]` for any block. This feature allows the computation of intermediate values that are not necessarily output in the document. The value of the variable specified in `def` is still set to the result of the block. -Consider the same example as above, but with `contribute` set to `[]` ([file](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/muting_block_output.pdl)): +Consider the similar example as above, but with `contribute` set to `[]` ([file](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/muting_block_output.pdl)): ```yaml -description: function def and call -defs: - translate: - function: - sentence: str - language: str - return: - - "\nTranslate the sentence '${ sentence }' to ${ language }.\n" - - model: watsonx/ibm/granite-20b-multilingual - parameters: - stop: ["\n"] -text: -- call: translate - contribute: [] - def: FRENCH - args: - sentence: I love Paris! - language: French -- "The french sentence was: ${ FRENCH }" +--8<-- "./examples/tutorial/muting_block_output.pdl" ``` + The call to the translator with French as language does not produce an output. However, we save the result in variable `FRENCH` and use it in the last sentence of the document. When we execute this program, we obtain: ``` @@ -307,63 +261,39 @@ You could also turn the list into a text or an array by surrounding it with a `t PDL can accept textual input from a file or stdin. In the following example ([file](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/input_file.pdl)), the contents of this [file](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/data.txt) are read by PDL and incorporated in the document. The result is also assigned to a variable `HELLO`. - ```yaml -description: PDL code with input block -text: -- read: ./data.txt - def: HELLO +--8<-- "./examples/tutorial/input_file.pdl" ``` + In the next example, prompts are obtained from stdin ([file](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/input_stdin.pdl)). This is indicated by assigning the value `null` to the `read` field. ```yaml -description: PDL code with input block -text: -- "The following will prompt the user on stdin.\n" -- read: - message: "Please provide an input: " - def: STDIN +--8<-- "./examples/tutorial/input_stdin.pdl" ``` + If the `message` field is omitted then one is provided for you. -The following example shows a multiline stdin input ([file](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/input_stdin_multiline.pdl)). When executing this code and to exit from the multiline input simply press control D (macos). +The following example shows a multiline stdin input ([file](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/input_stdin_multiline.pdl)). When executing this code and to exit from the multiline input simply press control D (on macOS). + ```yaml -description: PDL code with input block -text: -- "A multiline stdin input.\n" -- read: - multiline: true +--8<-- "./examples/tutorial/input_stdin_multiline.pdl" ``` + Finally, the following example shows reading content in JSON format. Consider the JSON content in this [file](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/input.json): -```json -{ - "name": "Bob", - "address": { - "number": 87, - "street": "Smith Road", - "town": "Armonk", - "state": "NY", - "zip": 10504 - } -} + +```yaml +--8<-- "./examples/tutorial/input.json" ``` The following PDL program reads this content and assigns it to variable `PERSON` in JSON format ([file](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/input_file_json.pdl)). The reference `PERSON.address.street` then refers to that field inside the JSON object. ```yaml -description: Input block example with json input -defs: - PERSON: - read: ./input.json - parser: json -text: | - ${ PERSON.name } lives at the following address: - ${ PERSON.address.number } ${ PERSON.address.street } in the town of ${ PERSON.address.town }, ${ PERSON.address.state } +--8<-- "./examples/tutorial/input_file_json.pdl" ``` When we execute this program, we obtain: @@ -375,25 +305,17 @@ Bob lives at the following address: ## Calling code -The following script shows how to execute python code ([file](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/calling_code.pdl)). Currently, the python code is executed locally. In principle, PDL is agnostic of any specific programming language, but we currently only support Python. Variables defined in PDL are copied into the global scope of the Python code, so those variables can be used directly in the code. However, mutating variables in Python has no effect on the variables in the PDL program. The result of the code must be assigned to the variable `result` internally to be propagated to the result of the block. A variable `def` on the code block will then be set to this result. +The following script shows how to execute python code ([file](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/calling_code.pdl)). The python code is executed locally (or in a containerized way if using `pdl --sandbox`). In principle, PDL is agnostic of any specific programming language, but we currently only support Python. Variables defined in PDL are copied into the global scope of the Python code, so those variables can be used directly in the code. However, mutating variables in Python has no effect on the variables in the PDL program. The result of the code must be assigned to the variable `result` internally to be propagated to the result of the block. A variable `def` on the code block will then be set to this result. In order to define variables that are carried over to the next Python code block, a special variable `PDL_SESSION` can be used, and variables assigned to it as fields. See for example: ([file](https://github.com/IBM/prompt-declaration-language//blob/main/examples/rag/rag.pdl)). ```yaml -description: Hello world showing call to python code -text: -- "Hello, " -- lang: python - code: - | - import random - import string - result = random.choice(string.ascii_lowercase) +--8<-- "./examples/tutorial/calling_code.pdl" ``` -This results in the following output: +This results in the following output (for example): ``` Hello, r! ``` @@ -403,42 +325,7 @@ Hello, r! PDL programs can contain calls to REST APIs with Python code. Consider a simple weather app ([file](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/calling_apis.pdl)): ```yaml -description: Using a weather API and LLM to make a small weather app -text: -- read: - def: QUERY - message: "Ask a query: " - contribute: [] -- model: watsonx/ibm/granite-34b-code-instruct - input: | - Question: What is the weather in London? - London - Question: What's the weather in Paris? - Paris - Question: Tell me the weather in Lagos? - Lagos - Question: ${ QUERY } - parameters: - stop: - - Question - - What - - '!' - include_stop_sequence: false - def: LOCATION - contribute: [] -- lang: python - code: | - import requests - response = requests.get('https://api.weatherapi.com/v1/current.json?key=cf601276764642cb96224947230712&q=${ LOCATION }') - result = response.content - def: WEATHER - parser: json - contribute: [] - -- model: watsonx/ibm/granite-34b-code-instruct - input: | - Explain the weather from the following JSON: - ${ WEATHER } +--8<-- "./examples/tutorial/calling_apis.pdl" ``` In this program, we first prompt the user to enter a query about the weather in some location (assigned to variable `QUERY`). The next block is a call to a granite model with few-shot examples to extract the location, which we assign to variable `LOCATION`. The next block makes an API call with Python. Here the `LOCATION` is appended to the `url`. The result is a JSON object, which may be hard to interpret for a human user. So we make a final call to an LLM to interpret the JSON in terms of weather. Notice that many blocks have `contribute` set to `[]` to hide intermediate results. @@ -446,65 +333,23 @@ In this program, we first prompt the user to enter a query about the weather in ## Data Block -PDL offers the ability to create JSON data as illustrated by the following example (described in detail in the [Overview](https://github.com/IBM/prompt-declaration-language//blob/main/README.md#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 bootstrapped with a bash or Python script to generate data en masse. ([file](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/data_block.pdl)) +PDL offers the ability to create JSON data as illustrated by the following example (described in detail in the [Overview](https://github.com/IBM/prompt-declaration-language/blob/main/README.md#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 bootstrapped with a bash or Python script to generate data en masse ([file](https://github.com/IBM/prompt-declaration-language/blob/main/examples/tutorial/data_block.pdl)). ```yaml -description: Code explanation example -defs: - CODE: - read: ./data.yaml - parser: yaml - TRUTH: - read: ./ground_truth.txt -text: -- model: watsonx/ibm/granite-34b-code-instruct - def: EXPLANATION - contribute: [] - input: - | - Here is some info about the location of the function in the repo. - repo: - ${ CODE.repo_info.repo } - path: ${ CODE.repo_info.path } - Function_name: ${ CODE.repo_info.function_name } - - - Explain the following code: - ``` - ${ CODE.source_code }``` -- def: EVAL - contribute: [] - lang: python - code: - | - import textdistance - expl = """ - ${ EXPLANATION } - """ - truth = """ - ${ TRUTH } - """ - result = textdistance.levenshtein.normalized_similarity(expl, truth) -- data: - input: ${ CODE } - output: ${ EXPLANATION } - metric: ${ EVAL } -``` - -Notice that in the `data` block the values are interpreted as Jinja2 expressions. If values need to be PDL programs to be interpreted, then you need to use +--8<-- "./examples/tutorial/data_block.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 the `object` block instead (see [this section](#specifying-data)). In the example above, the expressions inside the `data` block are interpreted. In some cases, it may be useful not to interpret the values in a `data` block. The `raw` field can be used to turn off the interpreter inside a `data` block. For example, consider the ([file](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/data_block_raw.pdl)): -``` -description: raw data block -data: - name: ${ name } - phone: ${ phone } -raw: True +```yaml +--8<-- "./examples/tutorial/data_block_raw.pdl" ``` + The result of this program is the JSON object: ``` @@ -521,33 +366,14 @@ where the values of `name` and `phone` have been left uninterpreted. PDL allows programs to be defined over multiple files. The `include` block allows one file to incorporate another, as shown in the following [example](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/include.pdl): -``` -description: Granite Multi-Round Chat -text: -- include: ../granite/granite_defs.pdl -- read: ../granite/multi-prompts.json - parser: json - def: prompts - spec: {prompts: [str]} - contribute: [] -- ${ SYSTEM_CONTENT_CHAT } -- for: - prompt: ${ prompts.prompts } - repeat: - text: - - | - ${ prompt } - - model: watsonx/ibm/granite-13b-chat-v2 - parameters: - decoding_method: sample - max_new_tokens: 512 -role: user +```yaml +--8<-- "./examples/tutorial/include.pdl" ``` which includes the following [file](https://github.com/IBM/prompt-declaration-language//blob/main/examples/granite/granite_defs.pdl): -The `include` block means that the PDL code at that file is executed and its output is included at the point where the `include` block appears in a document. In this example, the file contains definitions, which are used in the program. This feature allows reuse of common templates and patterns and to build libraries. Notice that relative paths are relative to the containing file. +The `include` block means that the PDL code at that file is executed and its output is included at the point where the `include` block appears in the program. In this example, the file contains definitions, which are used in the program. This feature allows reuse of common templates and patterns and to build libraries. Notice that relative paths are relative to the containing file. ## Conditionals and Loops @@ -556,24 +382,7 @@ PDL supports conditionals and loops as illustrated in the following example ([fi ```yaml -description: chatbot -text: -- read: - message: "What is your query?\n" - contribute: [context] -- repeat: - text: - - model: watsonx/ibm/granite-13b-chat-v2 - - read: - def: eval - message: "\nIs this a good answer[yes/no]?\n" - contribute: [] - - if: ${ eval == 'no' } - then: - text: - - read: - message: "Why not?\n" - until: ${ eval == 'yes'} +--8<-- "./examples/tutorial/conditionals_loops.pdl" ``` The first block prompts the user for a query, and this is contributed to the background context. The next @@ -587,9 +396,9 @@ the list is interpreted to be a `lastOf` block. So again the blocks in the list of the last block. The chatbot keeps looping by making a call to a model, asking the user if the generated text is a good answer, -and asking `why not?` if the answer (stored in variable `eval`) is `no`. The loop ends when `eval` becomes `yes`. +and asking `why not?` if the answer (stored in variable `eval`) is `no`. The loop ends when `eval` becomes `yes`. This is specified with a Jinja expression on line 18. -Notice that the `repeat` and `then` blocks are followed by `text`. This is because of the semantics of lists in PDL. If we want to aggregate the result by stringifying every element in the list and collating them together (which is the case of top-level programs in general), then we need the keyword `text` to precede a list. If this is omitted then the list is treated as a programmatic sequence where all the blocks are executed in sequence but result of the overall list is the result of the {\em last} block in the sequence. This behavior can be marked explicitly with a `lastOf` block. +Notice that the `repeat` and `then` blocks are followed by `text`. This is because of the semantics of lists in PDL. If we want to aggregate the result by stringifying every element in the list and collating them together, then we need the keyword `text` to precede a list. If this is omitted then the list is treated as a programmatic sequence where all the blocks are executed in sequence but result of the overall list is the result of the {\em last} block in the sequence. This behavior can be marked explicitly with a `lastOf` block. Another form of iteration in PDL is `repeat` followed by `num_iterations`, which repeats the body `num_iterations` times. @@ -601,12 +410,8 @@ the `join` feature (see the following section). PDL also offers `for` loops over lists. The following [example](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/for.pdl) stringifies and outputs each number. -``` -description: for loop -for: - i: [1, 2, 3, 4] -repeat: - ${ i } +```yaml +--8<-- "./examples/tutorial/for.pdl" ``` This program outputs: @@ -673,7 +478,9 @@ join: ``` meaning that result of each iteration is stringified and concatenated with that of other iterations. When using `with`, -`as: text` can be elided. +`as: text` can be elided. + +Note that `join` can be added to any looping construct (`repeat`) not just `for` loops. The `for` loop constructs also allows iterating over 2 or more lists of the same length simultaneously: @@ -715,7 +522,7 @@ text: contribute: [context] - repeat: text: - - model: watsonx/ibm/granite-13b-chat-v2 + - model: replicate/ibm-granite/granite-3.0-8b-instruct role: assistant - read: def: eval @@ -731,7 +538,11 @@ role: user ``` In PDL, any block can be adorned with a `role` field indicating the role for that block. These are high-level annotations -that help to make programs more portable accross different models. PDL takes care of applying appropriate chat templates. +that help to make programs more portable accross different models. If the role of a block is not specified (except for model blocks that have `assistant` role), +then the role is inherited from the surrounding block. So in the above example, we only need to specify `role: user` at the top level (this is the default, so it doesn't +need to be specified explicitly). + +PDL takes care of applying appropriate chat templates. The prompt that is actually submitted to the first model call (with query `What is APR?`) is the following: ``` @@ -742,7 +553,7 @@ The prompt that is actually submitted to the first model call (with query `What To change the template that is applied, you can specify it as a parameter of the model call: ```yaml -model: watsonx/ibm/granite-13b-chat-v2 +model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: roles: system: @@ -759,37 +570,11 @@ parameters: ## Type Checking Consider the following PDL program ([file](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/gen-data.pdl)). It first reads the data -found [here](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/data.pdl) to form few-shot examples. These demonstrations show how to create +found [here](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/data.yaml) to form few-shot examples. These demonstrations show how to create some JSON data. -``` -description: Creating JSON Data -defs: - data: - read: ./data.yaml - parser: yaml - spec: { questions: [str], answers: [obj] } -text: - - model: watsonx/ibm/granite-20b-code-instruct - def: model_output - spec: {name: str, age: int} - input: - text: - - for: - question: ${ data.questions } - answer: ${ data.answers } - repeat: - - | - ${ question } - ${ answer } - - > - Question: Create a JSON object with fields 'name' and 'age' - and set them appropriately. Write the age in letters. - parser: yaml - parameters: - stop: - - '}' - include_stop_sequence: true +```yaml +--8<-- "./examples/tutorial/gen-data.pdl" ``` Upon reading the data we use a parser to parse it into a YAML. The `spec` field indicates the expected type for the @@ -801,13 +586,12 @@ Similarly, the output of the model call is parsed as YAML, and the `spec` indica When we run this program, we obtain the output: ``` -{ "name" : "John", "age" : "twenty five" } -examples/tutorial/gen-data.pdl:8 - Type errors during spec checking -examples/tutorial/gen-data.pdl:8 - twenty five should be of type +gen-data.pdl:8 - Type errors during spec checking: +gen-data.pdl:8 - 30 should be of type +{'name': 'John', 'age': '30'} ``` -Notice that since we asked the age to be produced in letters, this causes a type error indicated above. -If we modify the prompt not to contain this directive, the type error goes away. +Notice that since we asked the age to be produced in letters, we got a string back and this causes a type error indicated above. In general, `spec` definitions can be a subset of JSON schema, or use a shorthand notation as illustrated by the examples below: @@ -834,7 +618,9 @@ the examples below: ## Python SDK See examples of PDL being called programmatically in Python -([here](https://github.com/IBM/prompt-declaration-language//blob/main/examples/sdk)). +[here](https://github.com/IBM/prompt-declaration-language/blob/main/examples/sdk). + +For a more sophisticated example, see [here](https://github.com/IBM/prompt-declaration-language/blob/main/examples/callback). ## Debugging PDL Programs @@ -863,9 +649,39 @@ in the right pane. This is similar to a spreadsheet for tabular data, where data is in the forefront and the user can inspect the formula that generates the data in each cell. In the Live Document, cells are not uniform but can take arbitrary extents. Clicking on them similarly reveals the part of the code that produced them. +## Using Ollama models + +1. Install Ollama e.g., `brew install --cask ollama` +2. Run a model e.g., `ollama run granite-code:34b-instruct-q5_K_M`. See [the Ollama library for more models](https://ollama.com/library/granite-code/tags) +3. An OpenAI style server is running locally at [http://localhost:11434/](http://localhost:11434/), see [the Ollama blog](https://ollama.com/blog/openai-compatibility) for more details. + + +Example: + +``` +text: +- Hello, +- model: ollama_chat/granite-code:34b-instruct-q5_K_M + parameters: + stop: + - '!' + decoding_method: greedy +``` + + +Alternatively, one could also use Ollama's OpenAI-style endpoint using the `openai/` prefix instead of `ollama_chat/`. In this case, set the `OPENAI_API_BASE`, `OPENAI_API_KEY`, and `OPENAI_ORGANIZATION` (if necessary) environment variables. If you were using the official OpenAI API, you would only have to set the api key and possibly the organization. For local use e.g., using Ollama, this could look like so: + +```bash +export OPENAI_API_BASE=http://localhost:11434/v1 +export OPENAI_API_KEY=ollama # required, but unused +export OPENAI_ORGANIZATION=ollama # not required + +pdl <...> +``` + ## Strings In Yaml -Multiline strings are commonly used when writing PDL programs. However, their exact semantics are not intuitive. There are two types of formats that YAML supports for strings: block scalar and flow scalar formats. Scalars are what YAML calls basic values like numbers or strings, as opposed to complex types like arrays or objects. Block scalars have more control over how they are interpreted, whereas flow scalars have more limited escaping support. (Explanation here is thanks to [Wolfgang Faust](https://yaml-multiline.info/)) +Multiline strings are commonly used when writing PDL programs. There are two types of formats that YAML supports for strings: block scalar and flow scalar formats. Scalars are what YAML calls basic values like numbers or strings, as opposed to complex types like arrays or objects. Block scalars have more control over how they are interpreted, whereas flow scalars have more limited escaping support. (Explanation here is thanks to [Wolfgang Faust](https://yaml-multiline.info/)) ### Block Scalars @@ -1115,35 +931,7 @@ Several lines of text, with some "quotes" of various 'types'. Escapes (like \n) Newlines can be added by leaving a blank line. Additional leading whitespace is ignored. ``` -## Using Ollama models - -1. Install Ollama e.g., `brew install --cask ollama` -2. Run a model e.g., `ollama run granite-code:34b-instruct-q5_K_M`. See [the Ollama library for more models](https://ollama.com/library/granite-code/tags) -3. An OpenAI style server is running locally at [http://localhost:11434/](http://localhost:11434/), see [the Ollama blog](https://ollama.com/blog/openai-compatibility) for more details. - - -Example: - -``` -text: -- Hello, -- model: ollama_chat/granite-code:34b-instruct-q5_K_M - parameters: - stop: - - '!' - decoding_method: greedy -``` - -Alternatively, one could also use Ollama's OpenAI-style endpoint using the `openai/` prefix instead of `ollama_chat/`. In this case, set the `OPENAI_API_BASE`, `OPENAI_API_KEY`, and `OPENAI_ORGANIZATION` (if necessary) environment variables. If you were using the official OpenAI API, you would only have to set the api key and possibly the organization. For local use e.g., using Ollama, this could look like so: - -```bash -export OPENAI_API_BASE=http://localhost:11434/v1 -export OPENAI_API_KEY=ollama # required, but unused -export OPENAI_ORGANIZATION=ollama # not required - -pdl <...> -``` diff --git a/examples/talk/2-model-chaining.pdl b/examples/talk/2-model-chaining.pdl index 185052cbc..d3fdd6334 100644 --- a/examples/talk/2-model-chaining.pdl +++ b/examples/talk/2-model-chaining.pdl @@ -4,7 +4,7 @@ text: - model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: stop_sequences: "!" -- "\nTranslate this to French\n" +- "\nDid you just say Hello?\n" - model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: stop_sequences: "!" diff --git a/examples/tutorial/calling_llm.pdl b/examples/tutorial/calling_llm.pdl index 88cb6efa9..bdf3180e7 100644 --- a/examples/tutorial/calling_llm.pdl +++ b/examples/tutorial/calling_llm.pdl @@ -3,5 +3,4 @@ text: - "Hello\n" - model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: - decoding_method: greedy stop_sequences: '!' \ No newline at end of file diff --git a/examples/tutorial/calling_llm_with_input.pdl b/examples/tutorial/calling_llm_with_input.pdl index 3a1f15cea..d03e870c5 100644 --- a/examples/tutorial/calling_llm_with_input.pdl +++ b/examples/tutorial/calling_llm_with_input.pdl @@ -1,6 +1,6 @@ description: Hello world calling a model text: -- "Hello, " +- "Hello\n" - model: replicate/ibm-granite/granite-3.0-8b-instruct input: - Translate the word 'world' to French + Translate the word 'Hello' to French diff --git a/examples/tutorial/calling_llm_with_input_messages.pdl b/examples/tutorial/calling_llm_with_input_messages.pdl index 8fb02679c..afee7a37e 100644 --- a/examples/tutorial/calling_llm_with_input_messages.pdl +++ b/examples/tutorial/calling_llm_with_input_messages.pdl @@ -1,10 +1,10 @@ description: Hello world calling a model text: -- "Hello, " -- model: watsonx/ibm/granite-20b-multilingual +- "Hello\n" +- model: replicate/ibm-granite/granite-3.0-8b-instruct input: array: - role: system content: You are a helpful assistant that is fluent in French. - role: user - content: Translate the word 'world' to French + content: Translate the word 'Hello' to French diff --git a/examples/tutorial/model_chaining.pdl b/examples/tutorial/model_chaining.pdl index dd6b488d9..ac52de8c1 100644 --- a/examples/tutorial/model_chaining.pdl +++ b/examples/tutorial/model_chaining.pdl @@ -4,7 +4,7 @@ text: - model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: stop_sequences: "!" -- "\nTranslate this to French\n" +- "\nDid you just say Hello?\n" - model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: stop_sequences: "!" diff --git a/examples/tutorial/variable_def_use.pdl b/examples/tutorial/variable_def_use.pdl index 235392089..112ec6db7 100644 --- a/examples/tutorial/variable_def_use.pdl +++ b/examples/tutorial/variable_def_use.pdl @@ -1,10 +1,8 @@ description: Hello world with variable def and use text: -- Hello, +- "Hello\n" - model: replicate/ibm-granite/granite-3.0-8b-instruct def: GEN parameters: - decoding_method: greedy stop_sequences: '!' - include_stop_sequence: true - "\nGEN is equal to: ${ GEN }" \ No newline at end of file diff --git a/tests/results/examples/demo/3-weather.result b/tests/results/examples/demo/3-weather.result index 72444d62d..ba7bbb4fe 100644 --- a/tests/results/examples/demo/3-weather.result +++ b/tests/results/examples/demo/3-weather.result @@ -1 +1 @@ -The weather in Yorktown Heights, New York, USA is currently sunny with a temperature of 46°F (7.8°C). The wind is blowing at a speed of 4.5 mph (7.2 kph) from the north-northwest (NNW) direction. The pressure is 30.39 inches of mercury (1029.0 mb). Humidity is at 65% and the dew point is 32.7°F (0.4°C). Visibility is 9 miles (16.0 km). There is no precipitation and the UV index is 0. The wind gusts can reach up to 14.5 kph (9.0 mph). +The current weather in Yorktown Heights, New York, USA is sunny with a temperature of 13.3°C (55.9°F). The wind is blowing at a speed of 7.6 mph (12.2 kph) from the north (N) direction. The pressure is 1031.0 mb (30.43 inches). The humidity is 42% and the dew point is 3.5°C (38.3°F). The visibility is 16.0 km (9.0 miles). The UV index is 1.3 and the wind gusts are up to 9.3 mph (14.9 kph). diff --git a/tests/results/examples/talk/2-model-chaining.result b/tests/results/examples/talk/2-model-chaining.result index f284cf32b..7e2cf3dc9 100644 --- a/tests/results/examples/talk/2-model-chaining.result +++ b/tests/results/examples/talk/2-model-chaining.result @@ -1,4 +1,4 @@ Hello Hello -Translate this to French -I'm sorry for the confusion, but it seems like you didn't provide any text to translate. Could you please provide the text you'd like me to translate into French? +Did you just say Hello? +Yes, I did. How can I assist you today? diff --git a/tests/results/examples/tutorial/calling_llm_with_input.result b/tests/results/examples/tutorial/calling_llm_with_input.result index 2d71ab72c..815854692 100644 --- a/tests/results/examples/tutorial/calling_llm_with_input.result +++ b/tests/results/examples/tutorial/calling_llm_with_input.result @@ -1 +1,2 @@ -Hello, The word 'world' translates to 'monde' in French. +Hello +The word 'Hello' translates to 'Bonjour' in French. diff --git a/tests/results/examples/tutorial/calling_llm_with_input_messages.result b/tests/results/examples/tutorial/calling_llm_with_input_messages.result index dd5023c7d..815854692 100644 --- a/tests/results/examples/tutorial/calling_llm_with_input_messages.result +++ b/tests/results/examples/tutorial/calling_llm_with_input_messages.result @@ -1 +1,2 @@ -Hello, as 'monde'. +Hello +The word 'Hello' translates to 'Bonjour' in French. diff --git a/tests/results/examples/tutorial/model_chaining.result b/tests/results/examples/tutorial/model_chaining.result index f284cf32b..7e2cf3dc9 100644 --- a/tests/results/examples/tutorial/model_chaining.result +++ b/tests/results/examples/tutorial/model_chaining.result @@ -1,4 +1,4 @@ Hello Hello -Translate this to French -I'm sorry for the confusion, but it seems like you didn't provide any text to translate. Could you please provide the text you'd like me to translate into French? +Did you just say Hello? +Yes, I did. How can I assist you today? diff --git a/tests/results/examples/tutorial/variable_def_use.result b/tests/results/examples/tutorial/variable_def_use.result index 1eeb2d9b2..c0e3cad60 100644 --- a/tests/results/examples/tutorial/variable_def_use.result +++ b/tests/results/examples/tutorial/variable_def_use.result @@ -1,2 +1,3 @@ -Hello,Hello +Hello +Hello GEN is equal to: Hello diff --git a/tests/results/examples/weather/weather.result b/tests/results/examples/weather/weather.result index 72444d62d..ba7bbb4fe 100644 --- a/tests/results/examples/weather/weather.result +++ b/tests/results/examples/weather/weather.result @@ -1 +1 @@ -The weather in Yorktown Heights, New York, USA is currently sunny with a temperature of 46°F (7.8°C). The wind is blowing at a speed of 4.5 mph (7.2 kph) from the north-northwest (NNW) direction. The pressure is 30.39 inches of mercury (1029.0 mb). Humidity is at 65% and the dew point is 32.7°F (0.4°C). Visibility is 9 miles (16.0 km). There is no precipitation and the UV index is 0. The wind gusts can reach up to 14.5 kph (9.0 mph). +The current weather in Yorktown Heights, New York, USA is sunny with a temperature of 13.3°C (55.9°F). The wind is blowing at a speed of 7.6 mph (12.2 kph) from the north (N) direction. The pressure is 1031.0 mb (30.43 inches). The humidity is 42% and the dew point is 3.5°C (38.3°F). The visibility is 16.0 km (9.0 miles). The UV index is 1.3 and the wind gusts are up to 9.3 mph (14.9 kph).