Skip to content

Commit 0afbd05

Browse files
authored
updated tools and react examples to ues granite tool calling (#206)
Signed-off-by: Mandana Vaziri <[email protected]>
1 parent b5e4534 commit 0afbd05

File tree

6 files changed

+219
-297
lines changed

6 files changed

+219
-297
lines changed

examples/react/demo.pdl

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,67 @@
1+
defs:
2+
tools:
3+
data:
4+
- type: function
5+
function:
6+
name: Calc
7+
description: Calculator function
8+
parameters:
9+
type: object
10+
properties:
11+
expr:
12+
type: string
13+
description: Arithmetic expression to calculate
14+
required:
15+
- expr
16+
- type: function
17+
function:
18+
name: Search
19+
description: Wikipedia search
20+
parameters:
21+
type: object
22+
properties:
23+
topic:
24+
type: string
25+
description: Topic to search
26+
required:
27+
- topic
128
text:
2-
- |
3-
What is the elevation range for the area that the eastern sector of the Colorado orogeny extends into?
4-
Tho: I need to search Colorado orogeny, find the area that the eastern sector of the Colorado ...
5-
Act: {"name": "Search", "arguments": {"topic": "Colorado orogeny"}}
6-
Obs: The Colorado orogeny was an episode of mountain building (an orogeny) ...
7-
Tho: It does not mention the eastern sector. So I need to look up eastern sector.
8-
Tho: High Plains rise in elevation from around 1,800 to 7,000 ft, so the answer is 1,800 to 7,000 ft.
9-
Act: {"name": "Finish", "arguments": {"topic": "1,800 to 7,000 ft"}}
29+
- role: system
30+
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.
31+
contribute: [context]
32+
- role: available_tools
33+
text: ${ tools }
34+
contribute: [context]
35+
- text:
36+
|
37+
What profession does Nicholas Ray and Elia Kazan have in common?
38+
Tho: I need to search Nicholas Ray and Elia Kazan, find their professions, then find the profession they have in common.
39+
Act:
40+
[{"name": "Search", "arguments": {"topic": "Nicholas Ray"}}]
41+
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.
42+
Tho: Professions of Nicholas Ray are director, screenwriter, and actor. I need to search Elia Kazan next and find his professions.
43+
Act:
44+
[{"name": "Search", "arguments": {"topic": "Elia Kazan"}}]
45+
Obs: Elia Kazan was an American film and theatre director, producer, screenwriter and actor.
46+
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.
47+
Act:
48+
[{"name": "Finish", "arguments": {"topic": "director, screenwriter, actor"}}]
49+
contribute: [context]
1050

11-
What profession does Nicholas Ray and Elia Kazan have in common?
12-
Tho: I need to search Nicholas Ray and Elia Kazan, find their professions, then find the profession they have in common.
13-
Act: {"name": "Search", "arguments": {"topic": "Nicholas Ray"}}
14-
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.
15-
Tho: Professions of Nicholas Ray are director, screenwriter, and actor. I need to search Elia Kazan next and find his professions.
16-
Act: {"name": "Search", "arguments": {"topic": "Elia Kazan"}}
17-
Obs: Elia Kazan was an American film and theatre director, producer, screenwriter and actor.
18-
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.
19-
Act: {"name": "Finish", "arguments": {"topic": "director, screenwriter, actor"}}
20-
21-
What is 18 + 12 x 3?
22-
Tho: I need to call a calculator.
23-
Act: {"name": "Calc", "arguments": {"expr": "18 + 12 * 3"}}
24-
Obs: 54
25-
Act: {"name": "Finish", "arguments": {"topic": "54"}}
26-
27-
A total of 252 qualifying matches were played, and 723 goals were scored. What was the average number of goals per match?
28-
Tho: I need to call a calculator.
29-
Act: {"name": "Calc", "arguments": {"expr": "723 / 252"}}
30-
Obs: 2.869047619047619
31-
Act: {"name": "Finish", "arguments": {"topic": "2.869047619047619"}}
32-
33-
34-
How many years ago was the discoverer of the Hudson River born? Keep in mind we are in 2024.
51+
- "How many years ago was the discoverer of the Hudson River born? Keep in mind we are in 2024.\n"
3552
- repeat:
3653
text:
3754
- def: thought
3855
model: replicate/ibm-granite/granite-3.0-8b-instruct
3956
parameters:
4057
stop_sequences: "Act:"
41-
temperature: 0
42-
- def: rawAction
58+
- "Act:\n"
59+
- def: action
4360
model: replicate/ibm-granite/granite-3.0-8b-instruct
4461
parameters:
4562
stop_sequences: "\n"
46-
temperature: 0
47-
- def: action
48-
lang: python
4963
parser: json
50-
spec: {name: str, arguments: obj}
51-
contribute: [context]
52-
code:
53-
|
54-
result = '${ rawAction }'.replace("Act: ", "")
55-
- def: observation
56-
if: ${ action.name == "Search" }
64+
- if: ${ action[0].name == 'Search' }
5765
then:
5866
text:
5967
- "\nObs: "
@@ -62,17 +70,17 @@ text:
6270
import warnings, wikipedia
6371
warnings.simplefilter("ignore")
6472
try:
65-
result = wikipedia.summary("${ action.arguments.topic }")
73+
result = wikipedia.summary("${ action[0].arguments.topic }")
6674
except wikipedia.WikipediaException as e:
6775
result = str(e)
6876
- "\n"
6977
else:
70-
if: ${ action.name == "Calc" }
78+
if: ${ action[0].name == "Calc" }
7179
then:
7280
text:
7381
- "\nObs: "
7482
- lang: python
75-
code: result = ${ action.arguments.expr }
83+
code: result = ${ action[0].arguments.expr }
7684
- "\n"
77-
until: ${ action.name != "Search" }
78-
85+
until: ${ action[0].name == "Finish" }
86+

examples/react/react_fun.pdl

Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,46 @@ defs:
77
model: str
88
return:
99
text:
10+
- defs:
11+
tools:
12+
data:
13+
- type: function
14+
function:
15+
name: Calc
16+
description: Calculator function
17+
parameters:
18+
type: object
19+
properties:
20+
expr:
21+
type: string
22+
description: Arithmetic expression to calculate
23+
required:
24+
- expr
25+
- type: function
26+
function:
27+
name: Search
28+
description: Wikipedia search
29+
parameters:
30+
type: object
31+
properties:
32+
topic:
33+
type: string
34+
description: Topic to search
35+
required:
36+
- topic
1037
- for:
1138
ex: ${ examples }
1239
repeat:
1340
"${ ex }\n"
1441
- "\n"
1542
- ${ question }
1643
- "\n"
44+
- role: system
45+
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.
46+
contribute: [context]
47+
- role: available_tools
48+
text: ${ tools }
49+
contribute: [context]
1750
- def: prev_action
1851
contribute: []
1952
data: none
@@ -26,24 +59,16 @@ defs:
2659
model: ${ model }
2760
parameters:
2861
stop_sequences: "Act:"
29-
temperature: 0
30-
- def: rawAction
62+
- "Act:\n"
63+
- def: action
3164
model: ${ model }
3265
parameters:
3366
stop_sequences: "\n"
34-
temperature: 0
35-
- def: action
36-
lang: python
3767
parser: json
38-
spec: {name: str, arguments: obj}
39-
contribute: [context]
40-
code:
41-
|
42-
result = '${ rawAction }'.replace("Act: ", "")
43-
- if: ${ action != prev_action}
68+
- if: ${ action != prev_action}
4469
then:
4570
def: observation
46-
if: ${ action.name == "Search" }
71+
if: ${ action[0].name == "Search" }
4772
then:
4873
text:
4974
- "\nObs: "
@@ -52,17 +77,17 @@ defs:
5277
import warnings, wikipedia
5378
warnings.simplefilter("ignore")
5479
try:
55-
result = wikipedia.summary("${ action.arguments.topic }")
80+
result = wikipedia.summary("${ action[0].arguments.topic }")
5681
except wikipedia.WikipediaException as e:
5782
result = str(e)
5883
- "\n"
5984
else:
60-
if: ${ action.name == "Calc" }
85+
if: ${ action[0].name == "Calc" }
6186
then:
6287
text:
6388
- "\nObs: "
6489
- lang: python
65-
code: result = ${ action.arguments.expr }
90+
code: result = ${ action[0].arguments.expr }
6691
- "\n"
6792
else:
6893
def: exit
@@ -71,7 +96,7 @@ defs:
7196
- def: prev_action
7297
contribute: []
7398
data: ${ action }
74-
until: ${ action.name == "Finish" or exit }
99+
until: ${ action[0].name == "Finish" or exit }
75100

76101
react:
77102
function:
@@ -81,47 +106,20 @@ defs:
81106
defs:
82107
examples:
83108
array:
84-
- text:
85-
|
86-
What is the elevation range for the area that the eastern sector of the Colorado orogeny extends into?
87-
Tho: I need to search Colorado orogeny, find the area that the eastern sector of the Colorado ...
88-
Act: {"name": "Search", "arguments": {"topic": "Colorado orogeny"}}
89-
Obs: The Colorado orogeny was an episode of mountain building (an orogeny) ...
90-
Tho: It does not mention the eastern sector. So I need to look up eastern sector.
91-
Tho: High Plains rise in elevation from around 1,800 to 7,000 ft, so the answer is 1,800 to 7,000 ft.
92-
Act: {"name": "Finish", "arguments": {"topic": "1,800 to 7,000 ft"}}
93-
94-
95109
- text:
96110
|
97111
What profession does Nicholas Ray and Elia Kazan have in common?
98112
Tho: I need to search Nicholas Ray and Elia Kazan, find their professions, then find the profession they have in common.
99-
Act: {"name": "Search", "arguments": {"topic": "Nicholas Ray"}}
113+
Act:
114+
[{"name": "Search", "arguments": {"topic": "Nicholas Ray"}}]
100115
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.
101116
Tho: Professions of Nicholas Ray are director, screenwriter, and actor. I need to search Elia Kazan next and find his professions.
102-
Act: {"name": "Search", "arguments": {"topic": "Elia Kazan"}}
117+
Act:
118+
[{"name": "Search", "arguments": {"topic": "Elia Kazan"}}]
103119
Obs: Elia Kazan was an American film and theatre director, producer, screenwriter and actor.
104120
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.
105-
Act: {"name": "Finish", "arguments": {"topic": "director, screenwriter, actor"}}
106-
107-
108-
- text:
109-
|
110-
What is 18 + 12 x 3?
111-
Tho: I need to call a calculator.
112-
Act: {"name": "Calc", "arguments": {"expr": "18 + 12 * 3"}}
113-
Obs: 54
114-
Act: {"name": "Finish", "arguments": {"topic": "54"}}
115-
116-
117-
- text:
118-
|
119-
A total of 252 qualifying matches were played, and 723 goals were scored. What was the average number of goals per match?
120-
Tho: I need to call a calculator.
121-
Act: {"name": "Calc", "arguments": {"expr": "723 / 252"}}
122-
Obs: 2.869047619047619
123-
Act: {"name": "Finish", "arguments": {"topic": "2.869047619047619"}}
124-
121+
Act:
122+
[{"name": "Finish", "arguments": {"topic": "director, screenwriter, actor"}}]
125123

126124
call: react_inner
127125
args:

examples/react/wikipedia.pdl

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)