From eecc237f3ca64bbf73313cd46654f2a2d54671b2 Mon Sep 17 00:00:00 2001 From: Mandana Vaziri Date: Sat, 30 Nov 2024 12:24:19 -0500 Subject: [PATCH] updated tools and react examples to ues granite tool calling Signed-off-by: Mandana Vaziri --- examples/react/demo.pdl | 106 ++++++++++++++++-------------- examples/react/react_fun.pdl | 96 ++++++++++++++------------- examples/react/wikipedia.pdl | 82 ----------------------- examples/talk/8-tools.pdl | 55 ++++++++-------- examples/talk/9-react.pdl | 122 ++++++++++++++++++----------------- examples/tools/calc.pdl | 55 ++++++++-------- 6 files changed, 219 insertions(+), 297 deletions(-) delete mode 100644 examples/react/wikipedia.pdl diff --git a/examples/react/demo.pdl b/examples/react/demo.pdl index 415478667..2487fe42a 100644 --- a/examples/react/demo.pdl +++ b/examples/react/demo.pdl @@ -1,59 +1,67 @@ +defs: + tools: + data: + - type: function + function: + name: Calc + description: Calculator function + parameters: + type: object + properties: + expr: + type: string + description: Arithmetic expression to calculate + required: + - expr + - type: function + function: + name: Search + description: Wikipedia search + parameters: + type: object + properties: + topic: + type: string + description: Topic to search + required: + - topic 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"}} +- role: system + text: You are a helpful assistant with access to the following function calls. Your task is to produce a sequence of function calls necessary to generate response to the user utterance. Use the following function calls as required. + contribute: [context] +- role: available_tools + text: ${ tools } + contribute: [context] +- 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"}}] + contribute: [context] - 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. +- "How many years ago was the discoverer of the Hudson River born? Keep in mind we are in 2024.\n" - repeat: text: - def: thought model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: stop_sequences: "Act:" - temperature: 0 - - def: rawAction + - "Act:\n" + - def: action model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: 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" } + - if: ${ action[0].name == 'Search' } then: text: - "\nObs: " @@ -62,17 +70,17 @@ text: import warnings, wikipedia warnings.simplefilter("ignore") try: - result = wikipedia.summary("${ action.arguments.topic }") + result = wikipedia.summary("${ action[0].arguments.topic }") except wikipedia.WikipediaException as e: result = str(e) - "\n" else: - if: ${ action.name == "Calc" } + if: ${ action[0].name == "Calc" } then: text: - "\nObs: " - lang: python - code: result = ${ action.arguments.expr } + code: result = ${ action[0].arguments.expr } - "\n" - until: ${ action.name != "Search" } - + until: ${ action[0].name == "Finish" } + diff --git a/examples/react/react_fun.pdl b/examples/react/react_fun.pdl index 8b991f422..bb8d417e4 100644 --- a/examples/react/react_fun.pdl +++ b/examples/react/react_fun.pdl @@ -7,6 +7,33 @@ defs: model: str return: text: + - defs: + tools: + data: + - type: function + function: + name: Calc + description: Calculator function + parameters: + type: object + properties: + expr: + type: string + description: Arithmetic expression to calculate + required: + - expr + - type: function + function: + name: Search + description: Wikipedia search + parameters: + type: object + properties: + topic: + type: string + description: Topic to search + required: + - topic - for: ex: ${ examples } repeat: @@ -14,6 +41,12 @@ defs: - "\n" - ${ question } - "\n" + - role: system + text: You are a helpful assistant with access to the following function calls. Your task is to produce a sequence of function calls necessary to generate response to the user utterance. Use the following function calls as required. + contribute: [context] + - role: available_tools + text: ${ tools } + contribute: [context] - def: prev_action contribute: [] data: none @@ -26,24 +59,16 @@ defs: model: ${ model } parameters: stop_sequences: "Act:" - temperature: 0 - - def: rawAction + - "Act:\n" + - def: action model: ${ model } parameters: stop_sequences: "\n" - temperature: 0 - - def: action - lang: python parser: json - spec: {name: str, arguments: obj} - contribute: [context] - code: - | - result = '${ rawAction }'.replace("Act: ", "") - - if: ${ action != prev_action} + - if: ${ action != prev_action} then: def: observation - if: ${ action.name == "Search" } + if: ${ action[0].name == "Search" } then: text: - "\nObs: " @@ -52,17 +77,17 @@ defs: import warnings, wikipedia warnings.simplefilter("ignore") try: - result = wikipedia.summary("${ action.arguments.topic }") + result = wikipedia.summary("${ action[0].arguments.topic }") except wikipedia.WikipediaException as e: result = str(e) - "\n" else: - if: ${ action.name == "Calc" } + if: ${ action[0].name == "Calc" } then: text: - "\nObs: " - lang: python - code: result = ${ action.arguments.expr } + code: result = ${ action[0].arguments.expr } - "\n" else: def: exit @@ -71,7 +96,7 @@ defs: - def: prev_action contribute: [] data: ${ action } - until: ${ action.name == "Finish" or exit } + until: ${ action[0].name == "Finish" or exit } react: function: @@ -81,47 +106,20 @@ defs: 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"}} + 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"}} + 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? - 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"}} - + Act: + [{"name": "Finish", "arguments": {"topic": "director, screenwriter, actor"}}] call: react_inner args: diff --git a/examples/react/wikipedia.pdl b/examples/react/wikipedia.pdl deleted file mode 100644 index 114b3932e..000000000 --- a/examples/react/wikipedia.pdl +++ /dev/null @@ -1,82 +0,0 @@ -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? - 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? -- repeat: - text: - - def: thought - 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 - parameters: - 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: - - "\nObs: " - - 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" - until: ${ action.name != "Search" } - diff --git a/examples/talk/8-tools.pdl b/examples/talk/8-tools.pdl index ac6468ef7..c4d07b7be 100644 --- a/examples/talk/8-tools.pdl +++ b/examples/talk/8-tools.pdl @@ -1,37 +1,34 @@ description: tool use +defs: + tools: + data: + - type: function + function: + name: calc + description: Calculator function + parameters: + type: object + properties: + expr: + type: string + description: Arithmetic expression to calculate + required: + - expr 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 - - Out of 1400 participants, 400 passed the test. What percentage is that? -- "\n" -- def: rawAction +- role: system + text: You are a helpful assistant with access to the following function calls. Your task is to produce a sequence of function calls necessary to generate response to the user utterance. Use the following function calls as required. + contribute: [context] +- role: available_tools + text: ${ tools } + contribute: [context] +- "Out of 1400 participants, 400 passed the test. What percentage is that?\n" +- def: actions model: replicate/ibm-granite/granite-3.0-8b-instruct - parameters: - stop_sequences: "\n" -- def: action - lang: python parser: json - spec: {name: str, arguments: obj} - contribute: [context] - code: - | - result = '${ rawAction }'.replace("Act: ", "") + spec: [{ name: str, arguments: { expr: str }}] - "\n" -- if: ${ action.name == "Calc" } +- if: ${ actions[0].name == "calc" } then: text: - - "Obs: " - lang: python - code: result = ${ action.arguments.expr } + code: result = ${ actions[0].arguments.expr } \ No newline at end of file diff --git a/examples/talk/9-react.pdl b/examples/talk/9-react.pdl index 114b3932e..2487fe42a 100644 --- a/examples/talk/9-react.pdl +++ b/examples/talk/9-react.pdl @@ -1,71 +1,67 @@ +defs: + tools: + data: + - type: function + function: + name: Calc + description: Calculator function + parameters: + type: object + properties: + expr: + type: string + description: Arithmetic expression to calculate + required: + - expr + - type: function + function: + name: Search + description: Wikipedia search + parameters: + type: object + properties: + topic: + type: string + description: Topic to search + required: + - topic 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"}} +- role: system + text: You are a helpful assistant with access to the following function calls. Your task is to produce a sequence of function calls necessary to generate response to the user utterance. Use the following function calls as required. + contribute: [context] +- role: available_tools + text: ${ tools } + contribute: [context] +- 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"}}] + contribute: [context] - 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"}} - - 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? +- "How many years ago was the discoverer of the Hudson River born? Keep in mind we are in 2024.\n" - repeat: text: - def: thought model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: stop_sequences: "Act:" - temperature: 0 - - def: rawAction + - "Act:\n" + - def: action model: replicate/ibm-granite/granite-3.0-8b-instruct parameters: 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" } + - if: ${ action[0].name == 'Search' } then: text: - "\nObs: " @@ -74,9 +70,17 @@ text: import warnings, wikipedia warnings.simplefilter("ignore") try: - result = wikipedia.summary("${ action.arguments.topic }") + result = wikipedia.summary("${ action[0].arguments.topic }") except wikipedia.WikipediaException as e: result = str(e) - "\n" - until: ${ action.name != "Search" } - + else: + if: ${ action[0].name == "Calc" } + then: + text: + - "\nObs: " + - lang: python + code: result = ${ action[0].arguments.expr } + - "\n" + until: ${ action[0].name == "Finish" } + diff --git a/examples/tools/calc.pdl b/examples/tools/calc.pdl index ac6468ef7..c4d07b7be 100644 --- a/examples/tools/calc.pdl +++ b/examples/tools/calc.pdl @@ -1,37 +1,34 @@ description: tool use +defs: + tools: + data: + - type: function + function: + name: calc + description: Calculator function + parameters: + type: object + properties: + expr: + type: string + description: Arithmetic expression to calculate + required: + - expr 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 - - Out of 1400 participants, 400 passed the test. What percentage is that? -- "\n" -- def: rawAction +- role: system + text: You are a helpful assistant with access to the following function calls. Your task is to produce a sequence of function calls necessary to generate response to the user utterance. Use the following function calls as required. + contribute: [context] +- role: available_tools + text: ${ tools } + contribute: [context] +- "Out of 1400 participants, 400 passed the test. What percentage is that?\n" +- def: actions model: replicate/ibm-granite/granite-3.0-8b-instruct - parameters: - stop_sequences: "\n" -- def: action - lang: python parser: json - spec: {name: str, arguments: obj} - contribute: [context] - code: - | - result = '${ rawAction }'.replace("Act: ", "") + spec: [{ name: str, arguments: { expr: str }}] - "\n" -- if: ${ action.name == "Calc" } +- if: ${ actions[0].name == "calc" } then: text: - - "Obs: " - lang: python - code: result = ${ action.arguments.expr } + code: result = ${ actions[0].arguments.expr } \ No newline at end of file