Skip to content

Commit a854fd5

Browse files
authored
tests: update react example (#1001)
Signed-off-by: Louis Mandel <[email protected]>
1 parent 055add8 commit a854fd5

18 files changed

+194
-97
lines changed

examples/demo/9-react.pdl

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
description: Demonstrating a React program
22
defs:
3+
Calc:
4+
description: Calculator function
5+
function:
6+
expr:
7+
type: string
8+
description: Arithmetic expression to calculate
9+
return:
10+
lang: python
11+
code: result = ${ expr }
12+
Search:
13+
description: Wikipedia search
14+
function:
15+
topic:
16+
type: string
17+
description: Topic to search
18+
return:
19+
lang: python
20+
code: |
21+
import warnings, wikipedia
22+
warnings.simplefilter("ignore")
23+
try:
24+
result = wikipedia.summary("${ topic }")
25+
except wikipedia.WikipediaException as e:
26+
result = str(e)
327
tools:
428
data:
5-
- type: function
6-
function:
7-
name: Calc
8-
description: Calculator function
9-
parameters:
10-
type: object
11-
properties:
12-
expr:
13-
type: string
14-
description: Arithmetic expression to calculate
15-
required:
16-
- expr
17-
- type: function
18-
function:
19-
name: Search
20-
description: Wikipedia search
21-
parameters:
22-
type: object
23-
properties:
24-
topic:
25-
type: string
26-
description: Topic to search
27-
required:
28-
- topic
29+
- ${ Calc.signature }
30+
- ${ Search.signature }
2931
text:
3032
- role: system
3133
text: You are Granite, developed by IBM. You are a helpful AI assistant with access to the following tools. When a tool is required to answer the user's query, respond with <|tool_call|> followed by a JSON list of tools used. If a tool does not exist in the provided list of tools, notify the user that you do not have the ability to fulfill the request.
@@ -77,19 +79,17 @@ text:
7779
- "\nObservation: "
7880
- match: ${ action[0].name }
7981
with:
80-
- case: 'Search'
82+
- case: Search
8183
then:
82-
lang: python
83-
code: |
84-
import warnings, wikipedia
85-
warnings.simplefilter("ignore")
86-
try:
87-
result = wikipedia.summary("${ action[0].arguments.topic }")
88-
except wikipedia.WikipediaException as e:
89-
result = str(e)
90-
- case: 'Calc'
84+
call: ${ Search }
85+
args:
86+
topic: ${ action[0].arguments.topic }
87+
- case: Calc
9188
then:
92-
lang: python
93-
code: result = ${ action[0].arguments.expr }
89+
call: ${ Calc }
90+
args:
91+
expr: ${ action[0].arguments.expr }
92+
- case: Finish
93+
then: ${ action[0].arguments.topic }
9494
- "\n"
95-
until: ${ action[0].name == "Finish" }
95+
until: ${ action[0].name == "Finish" }

examples/demos/react.pdl

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
1+
description: Demonstrating a React program
12
defs:
3+
Calc:
4+
description: Calculator function
5+
function:
6+
expr:
7+
type: string
8+
description: Arithmetic expression to calculate
9+
return:
10+
lang: python
11+
code: result = ${ expr }
12+
Search:
13+
description: Wikipedia search
14+
function:
15+
topic:
16+
type: string
17+
description: Topic to search
18+
return:
19+
lang: python
20+
code: |
21+
import warnings, wikipedia
22+
warnings.simplefilter("ignore")
23+
try:
24+
result = wikipedia.summary("${ topic }")
25+
except wikipedia.WikipediaException as e:
26+
result = str(e)
227
tools:
328
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
29+
- ${ Calc.signature }
30+
- ${ Search.signature }
2831
text:
2932
- role: system
3033
text: You are Granite, developed by IBM. You are a helpful AI assistant with access to the following tools. When a tool is required to answer the user's query, respond with <|tool_call|> followed by a JSON list of tools used. If a tool does not exist in the provided list of tools, notify the user that you do not have the ability to fulfill the request.
@@ -76,19 +79,17 @@ text:
7679
- "\nObservation: "
7780
- match: ${ action[0].name }
7881
with:
79-
- case: 'Search'
82+
- case: Search
8083
then:
81-
lang: python
82-
code: |
83-
import warnings, wikipedia
84-
warnings.simplefilter("ignore")
85-
try:
86-
result = wikipedia.summary("${ action[0].arguments.topic }")
87-
except wikipedia.WikipediaException as e:
88-
result = str(e)
89-
- case: 'Calc'
84+
call: ${ Search }
85+
args:
86+
topic: ${ action[0].arguments.topic }
87+
- case: Calc
9088
then:
91-
lang: python
92-
code: result = ${ action[0].arguments.expr }
89+
call: ${ Calc }
90+
args:
91+
expr: ${ action[0].arguments.expr }
92+
- case: Finish
93+
then: ${ action[0].arguments.topic }
9394
- "\n"
94-
until: ${ action[0].name == "Finish" }
95+
until: ${ action[0].name == "Finish" }

tests/results/examples/demo/9-react.0.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ Action:
1111
Observation: 460
1212
Henry Hudson was born around 1565, so he was approximately 460 years ago.Action:
1313
[{"name": "Finish", "arguments": {"topic": "460"}}]
14-
Observation:
14+
Observation: 460

tests/results/examples/demo/9-react.1.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ Action:
2121
Observation: 460
2222
In the year 2025, it would be approximately 460 years ago that Henry Hudson was born.Action:
2323
[{"name": "Finish", "arguments": {"topic": "460"}}]
24-
Observation:
24+
Observation: 460

tests/results/examples/demo/9-react.2.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ Action:
2323
Observation: 460
2424
In the year 2025, it would be approximately 460 years ago that Henry Hudson was born.Action:
2525
[{"name": "Finish", "arguments": {"topic": "460"}}]
26-
Observation:
26+
Observation: 460

tests/results/examples/demo/9-react.3.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ Action:
2121
Observation: 460
2222
In the year 2025, it would be approximately 460 years ago that Henry Hudson was born.Action:
2323
[{"name": "Finish", "arguments": {"topic": "460"}}]
24-
Observation:
24+
Observation: 460

tests/results/examples/demo/9-react.4.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ Action:
1111
Observation: 460
1212
Henry Hudson was born around 1565, so he was approximately 460 years ago.Action:
1313
[{"name": "Finish", "arguments": {"topic": "460"}}]
14-
Observation:
14+
Observation: 460

tests/results/examples/demo/9-react.5.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ Henry Hudson was born around 1565. As of 2025, it has been approximately 470 yea
1010
Observation: 460
1111
Henry Hudson was born around 1565, which means he was born approximately 460 years ago as of 2025.Action:
1212
[{"name": "Finish", "arguments": {"topic": ""}}]
13-
Observation:
13+
Observation: 460

tests/results/examples/demo/9-react.6.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ Henry Hudson was born around 1565. As of 2025, it has been approximately 470 yea
1212
Observation: 460
1313
It has been approximately 460 years since Henry Hudson was born.Action:
1414
[{"name": "Finish", "arguments": {"topic": "460"}}]
15-
Observation:
15+
Observation: 460
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
How many years ago was the discoverer of the Hudson River born? Keep in mind we are in 2025. When searching for a birthday for a person, simply ask for the name of that person.
2+
Thought: I need to find out who discovered the Hudson River and then calculate how many years ago they were born based on the current year, 2025.
3+
Action:
4+
[{"name": "Search", "arguments": {"topic": "Henry Hudson"}}]
5+
Observation: 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.
6+
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.
7+
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; what then happened to the Hudsons and their companions is unknown.
8+
Henry Hudson was born around 1565. As of 2025, it has been approximately 470 years since Henry Hudson's birth.Action:
9+
[{"name": "Calc", "arguments": {"expr": "2025 - 1565"}}]
10+
Observation: 460
11+
It has been approximately 460 years since Henry Hudson was born.Action:
12+
[{"name": "Finish", "arguments": {"topic": "460"}}]
13+
Observation: 460

0 commit comments

Comments
 (0)