Skip to content

Commit ac7af43

Browse files
authored
Add pdl__model_input field to model blocks and trace fix (#785)
1 parent af4e501 commit ac7af43

File tree

6 files changed

+60
-22
lines changed

6 files changed

+60
-22
lines changed

pdl-live-react/src/pdl_ast.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2180,6 +2180,11 @@ export type Input =
21802180
export type Modelresponse = string | null
21812181
export type CompletionTokens = number | null
21822182
export type PromptTokens = number | null
2183+
export type PdlModelInput =
2184+
| {
2185+
[k: string]: unknown
2186+
}[]
2187+
| null
21832188
/**
21842189
* Optional field to ensure that the block is using granite-io.
21852190
*
@@ -2326,6 +2331,11 @@ export type Input1 =
23262331
*
23272332
*/
23282333
export type Modelresponse1 = string | null
2334+
export type PdlModelInput1 =
2335+
| {
2336+
[k: string]: unknown
2337+
}[]
2338+
| null
23292339
/**
23302340
* Optional field to ensure that the block is using LiteLLM.
23312341
*
@@ -2787,6 +2797,7 @@ export interface LitellmModelBlock {
27872797
*
27882798
*/
27892799
pdl__usage?: PdlUsage | null
2800+
pdl__model_input?: PdlModelInput1
27902801
platform?: Platform1
27912802
parameters?: Parameters1
27922803
}
@@ -2856,6 +2867,7 @@ export interface GraniteioModelBlock {
28562867
*
28572868
*/
28582869
pdl__usage?: PdlUsage | null
2870+
pdl__model_input?: PdlModelInput
28592871
platform?: Platform
28602872
backend: Backend
28612873
processor?: Processor

src/pdl/pdl-schema.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4236,6 +4236,21 @@
42364236
"default": null,
42374237
"description": "Tokens consumed during model call\n "
42384238
},
4239+
"pdl__model_input": {
4240+
"anyOf": [
4241+
{
4242+
"items": {
4243+
"type": "object"
4244+
},
4245+
"type": "array"
4246+
},
4247+
{
4248+
"type": "null"
4249+
}
4250+
],
4251+
"default": null,
4252+
"title": "Pdl Model Input"
4253+
},
42394254
"platform": {
42404255
"const": "granite-io",
42414256
"default": "granite-io",
@@ -6686,6 +6701,21 @@
66866701
"default": null,
66876702
"description": "Tokens consumed during model call\n "
66886703
},
6704+
"pdl__model_input": {
6705+
"anyOf": [
6706+
{
6707+
"items": {
6708+
"type": "object"
6709+
},
6710+
"type": "array"
6711+
},
6712+
{
6713+
"type": "null"
6714+
}
6715+
],
6716+
"default": null,
6717+
"title": "Pdl Model Input"
6718+
},
66896719
"platform": {
66906720
"const": "litellm",
66916721
"default": "litellm",

src/pdl/pdl_ast.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ class ModelBlock(LeafBlock):
410410
pdl__usage: Optional[PdlUsage] = None
411411
"""Tokens consumed during model call
412412
"""
413+
pdl__model_input: Optional[ModelInput] = None
413414

414415

415416
class LitellmModelBlock(ModelBlock):

src/pdl/pdl_ast_utils.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ def iter_block_children(f: Callable[[BlockType], None], block: BlockType) -> Non
4343
if block.pdl__trace is not None:
4444
f(block.pdl__trace)
4545
case ModelBlock():
46-
if block.input is not None:
47-
f(block.input)
46+
f(block.input)
4847
case CodeBlock():
4948
f(block.code)
5049
case GetBlock():
@@ -133,12 +132,10 @@ def map_block_children(f: MappedFunctions, block: BlockType) -> BlockType:
133132
block.pdl__trace = f.f_block(block.pdl__trace)
134133
case LitellmModelBlock():
135134
block.model = f.f_expr(block.model)
136-
if block.input is not None:
137-
block.input = f.f_block(block.input)
135+
block.input = f.f_block(block.input)
138136
case GraniteioModelBlock():
139137
block.model = f.f_expr(block.model)
140-
if block.input is not None:
141-
block.input = f.f_block(block.input)
138+
block.input = f.f_block(block.input)
142139
if block.parameters is not None:
143140
block.parameters = f.f_expr(block.parameters)
144141
case CodeBlock():

src/pdl/pdl_dumper.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ def block_to_dict( # noqa: C901
127127
d["modelResponse"] = block.modelResponse
128128
if block.pdl__usage is not None:
129129
d["pdl__usage"] = usage_to_dict(block.pdl__usage)
130+
if block.pdl__model_input is not None:
131+
d["pdl__model_input"] = block.pdl__model_input
130132
case GraniteioModelBlock():
131133
d["model"] = expr_to_dict(block.model, json_compatible)
132134
d["platform"] = str(block.platform)

src/pdl/pdl_interpreter.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,25 +1277,21 @@ def process_call_model(
12771277
assert False
12781278
# evaluate input
12791279
model_input: ModelInput
1280-
if concrete_block.input is not None: # If not implicit, then input must be a block
1281-
model_input_future, _, _, input_trace = process_block_of(
1282-
concrete_block,
1283-
"input",
1284-
state.with_yield_result(False).with_yield_background(False),
1285-
scope,
1286-
loc,
1287-
)
1288-
model_input_result = model_input_future.result()
1289-
if isinstance(model_input_result, str):
1290-
model_input = [{"role": state.role, "content": model_input_result}]
1291-
else:
1292-
model_input = model_input_result
1280+
model_input_future, _, _, concrete_block = process_block_of(
1281+
concrete_block,
1282+
"input",
1283+
state.with_yield_result(False).with_yield_background(False),
1284+
scope,
1285+
loc,
1286+
)
1287+
model_input_result = model_input_future.result()
1288+
if isinstance(model_input_result, str):
1289+
model_input = [{"role": state.role, "content": model_input_result}]
12931290
else:
1294-
model_input = scope["pdl_context"] # pyright: ignore
1295-
input_trace = None
1291+
model_input = model_input_result
12961292
concrete_block = concrete_block.model_copy(
12971293
update={
1298-
"input": input_trace,
1294+
"pdl__model_input": model_input,
12991295
}
13001296
)
13011297
# Execute model call

0 commit comments

Comments
 (0)