From 777c2482650efe9116a3abdc640246a9f770ec69 Mon Sep 17 00:00:00 2001 From: Louis Mandel Date: Wed, 26 Mar 2025 16:45:22 -0400 Subject: [PATCH 1/3] fix: remove some `type: ignore` --- src/pdl/pdl_interpreter.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/pdl/pdl_interpreter.py b/src/pdl/pdl_interpreter.py index fc748d5af..df3f23727 100644 --- a/src/pdl/pdl_interpreter.py +++ b/src/pdl/pdl_interpreter.py @@ -577,21 +577,18 @@ def process_block_body( scope, loc, ) - name, block = process_expr_of( - block, "name", scope, loc # pyright: ignore - ) # pyright: ignore - tool_call_id, block = process_expr_of( - block, "tool_call_id", scope, loc # pyright: ignore - ) # pyright: ignore - result = PdlDict( - { - "role": state.role, - "content": content, - "name": name, - "tool_call_id": tool_call_id, - "defsite": block.pdl__id, - } - ) + message = { + "role": state.role, + "content": content, + "defsite": block.pdl__id, + } + if block.name is not None: + name, block = process_expr_of(block, "name", scope, loc) + message["name"] = name + if block.tool_call_id is not None: + tool_call_id, block = process_expr_of(block, "tool_call_id", scope, loc) + message["tool_call_id"] = tool_call_id + result = PdlDict(message) case IfBlock(): b, if_trace = process_condition_of(block, "condition", scope, loc, "if") if b: From 0c16321587efc453d33505b8358c86a03e15e1c0 Mon Sep 17 00:00:00 2001 From: Louis Mandel Date: Thu, 27 Mar 2025 09:23:32 -0400 Subject: [PATCH 2/3] Add tests --- tests/test_messages.py | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/tests/test_messages.py b/tests/test_messages.py index 828488435..49d0aedf9 100644 --- a/tests/test_messages.py +++ b/tests/test_messages.py @@ -17,15 +17,11 @@ def test_messages1(): "role": "system", "content": "You are a helpful software engineer. You write clear, concise, well-commented code.", "defsite": "array.0.message", - "name": None, - "tool_call_id": None, }, { "role": "user", "content": "Write a Python function that implement merge sort.", "defsite": "array.1.message", - "name": None, - "tool_call_id": None, }, ] assert context == [ @@ -40,3 +36,34 @@ def test_messages1(): "defsite": "array.1.message", }, ] + + +def test_messages2(): + prog_str = """ +description: Messages block +array: + - role: tool + content: 42 + name: f + tool_call_id: id +""" + result = exec_str(prog_str, output="all") + context = result["scope"]["pdl_context"] + assert result["result"] == [ + { + "role": "tool", + "content": 42, + "name": "f", + "tool_call_id": "id", + "defsite": "array.0.message", + }, + ] + assert context == [ + { + "role": "tool", + "content": 42, + "name": "f", + "tool_call_id": "id", + "defsite": "array.0.message", + }, + ] From 3824377b3518464360567e8aa389dc9dd5964c31 Mon Sep 17 00:00:00 2001 From: Louis Mandel Date: Fri, 4 Apr 2025 15:17:58 -0400 Subject: [PATCH 3/3] Fix merge Signed-off-by: Louis Mandel --- src/pdl/pdl_interpreter.py | 1 + tests/test_messages.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pdl/pdl_interpreter.py b/src/pdl/pdl_interpreter.py index 3ee3b2763..58814ca98 100644 --- a/src/pdl/pdl_interpreter.py +++ b/src/pdl/pdl_interpreter.py @@ -589,6 +589,7 @@ def process_block_body( tool_call_id, block = process_expr_of(block, "tool_call_id", scope, loc) message["tool_call_id"] = tool_call_id result = PdlDict(message) + background = PdlList([result]) case IfBlock(): b, if_trace = process_condition_of(block, "condition", scope, loc, "if") if b: diff --git a/tests/test_messages.py b/tests/test_messages.py index 8bc857f46..993ed9fd5 100644 --- a/tests/test_messages.py +++ b/tests/test_messages.py @@ -134,4 +134,6 @@ def test_messages5(): "content": 42, "name": "f", "tool_call_id": "id", - "defsite": "array.0.message", } ] \ No newline at end of file + "defsite": "array.0.message", + } + ]