Skip to content

Commit 9d9cbda

Browse files
authored
feat: do not stringify messages content (#858)
* feat: do not stringify messages content Signed-off-by: Louis Mandel <[email protected]> * Fix examples Signed-off-by: Louis Mandel <[email protected]> --------- Signed-off-by: Louis Mandel <[email protected]>
1 parent 1614b26 commit 9d9cbda

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

examples/demo/8-tools.pdl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ text:
1313
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.
1414
contribute: [context]
1515
- role: tools
16-
text: ${ tools }
16+
content:
17+
text: ${ tools }
1718
contribute: [context]
1819
- "Out of 1400 participants, 400 passed the test. What percentage is that?\n"
1920
- def: actions

examples/demo/9-react.pdl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ text:
3030
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.
3131
contribute: [context]
3232
- role: tools
33-
text: ${ tools }
33+
content:
34+
text: ${ tools }
3435
contribute: [context]
3536
- text:
3637
|

examples/react/demo.pdl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ text:
3030
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.
3131
contribute: [context]
3232
- role: tools
33-
text: ${ tools }
33+
content:
34+
text: ${ tools }
3435
contribute: [context]
3536
- text:
3637
|

examples/tools/calc.pdl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ text:
1313
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.
1414
contribute: [context]
1515
- role: tools
16-
text: ${ tools }
16+
content:
17+
text: ${ tools }
1718
contribute: [context]
1819
- "Out of 1400 participants, 400 passed the test. What percentage is that?\n"
1920
- def: actions

src/pdl/pdl_interpreter.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,12 @@ def process_block(
252252
trace=ErrorBlock(msg=exc.message, pdl__location=loc, program=block),
253253
) from exc
254254
result = PdlConst(v)
255-
stringified_result = lazy_apply(stringify, result)
256255
background = PdlList(
257256
[
258257
PdlDict( # type: ignore
259258
{
260259
"role": state.role,
261-
"content": stringified_result,
260+
"content": result,
262261
"defsite": ".".join(
263262
state.id_stack
264263
), # Warning: defsite for a literal value
@@ -268,7 +267,7 @@ def process_block(
268267
)
269268
trace = DataBlock(
270269
data=expr,
271-
pdl__result=stringified_result,
270+
pdl__result=result,
272271
pdl__timing=PdlTiming(start_nanos=start, end_nanos=time.time_ns()),
273272
pdl__id=".".join(state.id_stack),
274273
)
@@ -475,9 +474,8 @@ def process_block_body(
475474
loc=exc.loc or loc,
476475
trace=ErrorBlock(msg=exc.message, pdl__location=loc, program=block),
477476
) from exc
478-
stringified_result = lazy_apply(stringify, result)
479477
background = PdlList(
480-
[PdlDict({"role": state.role, "content": stringified_result})] # type: ignore
478+
[PdlDict({"role": state.role, "content": result})] # type: ignore
481479
)
482480
trace = block.model_copy()
483481
if state.yield_result:
@@ -492,9 +490,8 @@ def process_block_body(
492490
else:
493491
v, trace = process_expr_of(block, "data", scope, loc)
494492
result = PdlConst(v)
495-
stringified_result = stringify(v)
496493
background = PdlList(
497-
[PdlDict({"role": state.role, "content": stringified_result})] # type: ignore
494+
[PdlDict({"role": state.role, "content": result})] # type: ignore
498495
)
499496
if state.yield_result:
500497
yield_result(result.result(), block.kind)
@@ -1601,9 +1598,8 @@ def process_call_code(
16011598
case "pdl":
16021599
try:
16031600
result = call_pdl(code_s, scope)
1604-
stringified_result = lazy_apply(stringify, result)
16051601
background = PdlList(
1606-
[PdlDict({"role": state.role, "content": stringified_result, "defsite": block.pdl__id})] # type: ignore
1602+
[PdlDict({"role": state.role, "content": result, "defsite": block.pdl__id})] # type: ignore
16071603
)
16081604
except Exception as exc:
16091605
raise PDLRuntimeError(

0 commit comments

Comments
 (0)