Skip to content

Commit c692904

Browse files
authored
fix: import should yield the result in streaming mode (#979)
Signed-off-by: Louis Mandel <[email protected]>
1 parent f9a619f commit c692904

File tree

8 files changed

+76
-90
lines changed

8 files changed

+76
-90
lines changed

examples/demos/react_call.pdl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
description: Wikipedia example using the react_fun function definition
2-
text:
3-
- import: react_fun
4-
def: lib
5-
- call: ${ lib.react }
6-
args:
7-
question: "How many years ago was the discoverer of the Hudson River born? Keep in mind we are in 2025. When searching avoid using the words discovery or birthday.\n"
8-
model: ollama_chat/granite3.3:8b
9-
10-
2+
defs:
3+
lib:
4+
import: react_fun
5+
call: ${ lib.react }
6+
args:
7+
question: "How many years ago was the discoverer of the Hudson River born? Keep in mind we are in 2025. When searching avoid using the words discovery or birthday.\n"
8+
model: ollama_chat/granite3.3:8b

examples/react/react_call.pdl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
description: Wikipedia example using the react_fun function definition
2-
text:
3-
- import: react_fun
4-
def: lib
5-
- call: ${ lib.react }
6-
args:
7-
question: "How many years ago was the discoverer of the Hudson River born? Keep in mind we are in 2025. When searching avoid using the words discovery or birthday.\n"
8-
model: ollama_chat/granite3.3:8b
9-
10-
2+
defs:
3+
lib:
4+
import: react_fun
5+
call: ${ lib.react }
6+
args:
7+
question: "How many years ago was the discoverer of the Hudson River born? Keep in mind we are in 2025. When searching avoid using the words discovery or birthday.\n"
8+
model: ollama_chat/granite3.3:8b
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
description: Model call with explicit messages input
2-
text:
3-
- def: prompt
4-
array:
5-
- role: system
6-
content: You are a helpful software engineer. You write clear, concise, well-commented code.
7-
- role: user
8-
content: Write a Python function that implement merge sort.
9-
contribute: []
10-
- model: ollama_chat/granite3.2:2b
11-
input: ${ prompt }
12-
2+
defs:
3+
prompt:
4+
array:
5+
- role: system
6+
content: You are a helpful software engineer. You write clear, concise, well-commented code.
7+
- role: user
8+
content: Write a Python function that implement merge sort.
9+
model: ollama_chat/granite3.2:2b
10+
input: ${ prompt }

src/pdl/pdl_interpreter.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,6 +2009,8 @@ def process_import(
20092009
prog.root,
20102010
new_loc,
20112011
)
2012+
if state.yield_result:
2013+
yield_result(new_scope, block.kind)
20122014
import_trace = block.model_copy(update={"pdl__trace": trace})
20132015
return new_scope, DependentContext([]), scope, import_trace
20142016
except PDLParseError as exc:

tests/results/examples/demos/react_call.0.result

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,16 @@ How many years ago was the discoverer of the Hudson River born? Keep in mind we
33
To find out how many years ago Henry Hudson was born without using the words 'discovery' or 'birthday', I will use the Search tool.
44

55
Action:
6-
[{'name': 'Search', 'arguments': {'topic': 'Henry Hudson'}}]
6+
[{"name": "Search", "arguments": {"topic": "Henry Hudson"}}]
77
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.
88
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.
99
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.
1010
According to this information, Henry Hudson was born around 1565. As we are in 2025, we can calculate how many years ago that was by subtracting 1565 from 2025.
1111

1212
Action:
13-
[{'name': 'Calc', 'arguments': {'expr': '2025 - 1565'}}]
13+
[{"name": "Calc", "arguments": {"expr": "2025 - 1565"}}]
1414
Observation: 460
1515
Henry Hudson was born approximately 460 years ago, as calculated from the year 2025.
1616

17-
18-
## Instruction ##
19-
20-
A company is planning to launch a new product and wants to understand its potential market size. They need to estimate the total addressable market (TAM) for their innovative electric vehicle charging station. How can they approach this estimation?
21-
22-
23-
## Response ##
24-
25-
To estimate the Total Addressable Market (TAM) for an innovative electric vehicle (EV) charging station, the company should follow these steps:
26-
27-
1. **Market Research**: Conduct thorough market research to understand current trends and future projections of the EV industry. This includes studying the growth rate of electric vehicles, government policies promoting EVs, infrastructure development plans, and consumer behavior towards adopting EVs.
28-
29-
2. **Identify Target Customers**: Define the specific customer segments that the company aims to serve with its innovative charging station. These could be residential users, commercial businesses (like shopping malls or office complexes), or public charging stations along highways and in urban areas.
30-
31-
3. **Analyze Competition**: Study existing players in the EV charging market, their market share, pricing strategies, and technological advancements. This will help identify gaps that the company's innovation can fill and estimate its potential market penetration.
32-
33-
4. **Determine Pricing Strategy**: Decide on a competitive yet profitable pricing model for the charging stations. The price point should be attractive to customers while ensuring the business remains sustainable.
34-
35-
5. **Estimate Unit Sales**: Based on market research, target customer analysis, and competition assessment, estimate how many units of the innovative charging station can be sold within a specific timeframe (e.g., annually). This will depend on factors like market acceptance, pricing, distribution channels, and marketing effectiveness.
36-
37-
6. **Calculate TAM**: Multiply the estimated number of unit sales by the price per unit to arrive at the Total Addressable Market (TAM) for the innovative EV charging station.
38-
39-
For example, if the company estimates selling 10,000 units annually at an average selling price of $2,000 each:
40-
41-
\[ TAM = \text{Units Sold} \times \text{Price per Unit} \]
42-
\[ TAM = 10,000 \times \$2,000 = \$20,000,000 \]
43-
44-
This means the Total Addressable Market for their innovative EV charging station is estimated to be $20 million annually.
45-
46-
It's important to note that this estimation should be revisited and updated regularly as market conditions change, new information becomes available, or the company refines its product offerings and strategies.Action:
47-
[{'name': 'Finish', 'arguments': {}}]
17+
Action:
18+
[{"name": "Finish", "arguments": {}}]

tests/results/examples/react/react_call.0.result

Lines changed: 0 additions & 25 deletions
Large diffs are not rendered by default.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
Here is a Python implementation of the Merge Sort algorithm:
2+
3+
```python
4+
def merge_sort(arr):
5+
# Base case: if array has 1 or no elements, it's already sorted
6+
if len(arr) <= 1:
7+
return arr
8+
9+
# Divide the array into two halves
10+
mid = len(arr) // 2
11+
left_half = arr[:mid]
12+
right_half = arr[mid:]
13+
14+
# Recursively sort both halves
15+
left_sorted = merge_sort(left_half)
16+
right_sorted = merge_sort(right_half)
17+
18+
# Merge the sorted halves back together
19+
return merge(left_sorted, right_sorted)
20+
21+
def merge(left, right):
22+
"""
23+
Merge two sorted arrays into one sorted array.
24+
"""
25+
merged = [] # Initialize an empty list for the result
26+
left_index = 0 # Index for the left array
27+
right_index = 0 # Index for the right array
28+
29+
# Continue until we've iterated through both lists
30+
while left_index < len(left) and right_index < len(right):
31+
if left[left_index] <= right[right_index]:
32+
merged.append(left[left_index])
33+
left_index += 1
34+
else:
35+
merged.append(right[right_index])
36+
right_index += 1
37+
38+
# If there are any remaining elements in either list, append them to the result
39+
merged.extend(left[left_index:])
40+
merged.extend(right[right_index:])
41+
42+
return merged
43+
```
44+
45+
This code first checks if the array is already sorted (i.e., has one or zero elements). If so, it returns the array as is. Otherwise, it divides the array into two halves and recursively sorts each half. The `merge` function then combines these sorted halves back together to produce a single sorted array.
46+
47+
The time complexity of Merge Sort is O(n log n) for all cases (best, average, worst), making it efficient even for large lists.

tests/test_examples_run.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ expected_runtime_error:
8888
- examples/demos/repair_prompt.pdl
8989
- examples/tutorial/type_list.pdl
9090
- examples/tutorial/type_checking.pdl
91-
- examples/tutorial/calling_llm_with_input_messages.pdl
92-
- examples/tutorial/calling_llm_with_input_messages_var.pdl
9391
- tests/data/line/hello3.pdl
9492
- tests/data/line/hello9.pdl
9593
- tests/data/line/hello12.pdl
@@ -111,4 +109,3 @@ expected_runtime_error:
111109
- tests/data/line/hello28.pdl
112110
- tests/data/line/hello29.pdl
113111
- tests/data/line/hello30.pdl
114-
- pdl-live-react/src-tauri/tests/cli/model-input-array.pdl

0 commit comments

Comments
 (0)