Skip to content

Commit ffc84cc

Browse files
committed
fix: import should yield the result in streaming mode
Signed-off-by: Louis Mandel <[email protected]>
1 parent f9a619f commit ffc84cc

File tree

6 files changed

+72
-54
lines changed

6 files changed

+72
-54
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/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.

0 commit comments

Comments
 (0)