Skip to content

Commit 3cd740e

Browse files
authored
Fix in MessageBlock (#1410)
Signed-off-by: Mandana Vaziri <mvaziri@us.ibm.com>
1 parent 7b63b89 commit 3cd740e

File tree

7 files changed

+43
-0
lines changed

7 files changed

+43
-0
lines changed

examples/test.pdl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
defs:
2+
b: hi
3+
text:
4+
- role: assistant
5+
content: hello
6+
tool_calls:
7+
- data:
8+
a: ${ b }
9+
c: d
10+
- ${ pdl_context }

src/pdl/pdl-schema.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3629,6 +3629,21 @@
36293629
"$ref": "#/$defs/OptionalExpressionStr",
36303630
"default": null,
36313631
"description": "The id of the tool invocation for which this message is the tool response."
3632+
},
3633+
"tool_calls": {
3634+
"anyOf": [
3635+
{
3636+
"items": {
3637+
"$ref": "#/$defs/BlockType"
3638+
},
3639+
"type": "array"
3640+
},
3641+
{
3642+
"type": "null"
3643+
}
3644+
],
3645+
"default": null,
3646+
"title": "Tool Calls"
36323647
}
36333648
},
36343649
"required": [

src/pdl/pdl_ast.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,7 @@ class MessageBlock(LeafBlock):
867867
"""For example, the name of the tool that was invoked, for which this message is the tool response."""
868868
tool_call_id: OptionalExpressionStr = None
869869
"""The id of the tool invocation for which this message is the tool response."""
870+
tool_calls: Optional[list["BlockType"]] = None
870871

871872

872873
class IfBlock(StructuredBlock):

src/pdl/pdl_dumper.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ def block_to_dict( # noqa: C901
216216
d["object"] = [block_to_dict(b, json_compatible) for b in block.object]
217217
case MessageBlock():
218218
d["content"] = block_to_dict(block.content, json_compatible)
219+
if block.tool_calls:
220+
d["tool_calls"] = [
221+
block_to_dict(b, json_compatible) for b in block.tool_calls
222+
]
219223
case ReadBlock():
220224
d["read"] = expr_to_dict(block.read, json_compatible)
221225
d["message"] = block.message

src/pdl/pdl_interpreter.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,16 @@ def process_block_body(
838838
if block.tool_call_id is not None:
839839
tool_call_id, block = process_expr_of(block, "tool_call_id", scope, loc)
840840
message["tool_call_id"] = tool_call_id
841+
if block.tool_calls is not None:
842+
result, _, _, _ = process_blocks_of(
843+
block,
844+
"tool_calls",
845+
JoinArray(as_="array"), # pyright: ignore
846+
state,
847+
scope,
848+
loc,
849+
)
850+
message["tool_calls"] = result
841851
result = PdlConst(SingletonContext(PdlDict(message)))
842852
background = SingletonContext(PdlDict(message))
843853
case IfBlock():

src/pdl/pdl_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ def message_post_processing(message: dict) -> dict[str, Any]:
125125
for key, value in message.items():
126126
if key == "content" and value is not None:
127127
ret[key] = value
128+
if key == "tools_calls" and value is not None:
129+
ret[key] = value
128130
if value is not None:
129131
if isinstance(value, dict):
130132
ret[key] = message_post_processing(value)

tests/test_examples_run.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ skip:
3939
- examples/skeleton-of-thought/tips.pdl
4040
- examples/tutorial/sdk/lib.pdl
4141
- build/lib/pdl/pdl_stdlib.pdl
42+
- examples/test.pdl
4243

4344
with_inputs:
4445
examples/tutorial/programs/chatbot.pdl:

0 commit comments

Comments
 (0)