Skip to content

Commit 20fff9f

Browse files
committed
Fixes
1 parent c302e31 commit 20fff9f

File tree

6 files changed

+42
-62
lines changed

6 files changed

+42
-62
lines changed

pdl-live/src/pdl_ast.d.ts

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3076,7 +3076,7 @@ export interface CallBlock {
30763076
result?: unknown;
30773077
location?: LocationType | null;
30783078
kind?: Kind18;
3079-
call: Call;
3079+
call: unknown;
30803080
args?: Args;
30813081
trace?: Trace6;
30823082
}
@@ -3473,7 +3473,7 @@ export interface DataBlock {
34733473
result?: unknown;
34743474
location?: LocationType | null;
34753475
kind?: Kind13;
3476-
data: Data;
3476+
data: unknown;
34773477
raw?: Raw;
34783478
}
34793479
/**
@@ -3551,7 +3551,7 @@ export interface IfBlock {
35513551
result?: unknown;
35523552
location?: LocationType | null;
35533553
kind?: Kind12;
3554-
if: If;
3554+
if: unknown;
35553555
then: Then;
35563556
else?: Else;
35573557
if_result?: IfResult;
@@ -3712,7 +3712,7 @@ export interface RepeatUntilBlock {
37123712
location?: LocationType | null;
37133713
kind?: Kind10;
37143714
repeat: Repeat1;
3715-
until: Until;
3715+
until: unknown;
37163716
join?: Join1;
37173717
trace?: Trace2;
37183718
}
@@ -4585,26 +4585,6 @@ export interface JoinArray {
45854585
export interface JoinLastOf {
45864586
as: As2;
45874587
}
4588-
/**
4589-
* Condition of the loop.
4590-
*
4591-
*/
4592-
export interface Until {
4593-
[k: string]: unknown;
4594-
}
4595-
/**
4596-
* Condition.
4597-
*
4598-
*/
4599-
export interface If {
4600-
[k: string]: unknown;
4601-
}
4602-
/**
4603-
* Value defined.
4604-
*/
4605-
export interface Data {
4606-
[k: string]: unknown;
4607-
}
46084588
export interface BamTextGenerationParameters {
46094589
beam_width?: BeamWidth;
46104590
decoding_method?: DecodingMethod | null;
@@ -4717,13 +4697,6 @@ export interface LitellmParameters {
47174697
max_retries?: MaxRetries;
47184698
[k: string]: unknown;
47194699
}
4720-
/**
4721-
* Function to call.
4722-
*
4723-
*/
4724-
export interface Call {
4725-
[k: string]: unknown;
4726-
}
47274700
/**
47284701
* Arguments of the function with their values.
47294702
*

src/pdl/pdl-schema.json

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,10 @@
10091009
{
10101010
"type": "string"
10111011
},
1012-
{}
1012+
{},
1013+
{
1014+
"$ref": "#/$defs/LocalizedExpression"
1015+
}
10131016
],
10141017
"title": "Model"
10151018
},
@@ -1964,6 +1967,12 @@
19641967
"type": "string"
19651968
},
19661969
"call": {
1970+
"anyOf": [
1971+
{},
1972+
{
1973+
"$ref": "#/$defs/LocalizedExpression"
1974+
}
1975+
],
19671976
"description": "Function to call.\n ",
19681977
"title": "Call"
19691978
},
@@ -4627,6 +4636,14 @@
46274636
"type": "string"
46284637
},
46294638
"for": {
4639+
"additionalProperties": {
4640+
"anyOf": [
4641+
{},
4642+
{
4643+
"$ref": "#/$defs/LocalizedExpression"
4644+
}
4645+
]
4646+
},
46304647
"description": "Arrays to iterate over.\n ",
46314648
"title": "For",
46324649
"type": "object"
@@ -8467,7 +8484,10 @@
84678484
{
84688485
"type": "string"
84698486
},
8470-
{}
8487+
{},
8488+
{
8489+
"$ref": "#/$defs/LocalizedExpression"
8490+
}
84718491
],
84728492
"title": "Model"
84738493
},
@@ -9134,7 +9154,7 @@
91349154
},
91359155
"LocalizedExpression": {
91369156
"additionalProperties": false,
9137-
"description": "Expression with location information\n ",
9157+
"description": "Expression with location information",
91389158
"properties": {
91399159
"expr": {
91409160
"title": "Expr"
@@ -11714,6 +11734,9 @@
1171411734
"read": {
1171511735
"anyOf": [
1171611736
{},
11737+
{
11738+
"$ref": "#/$defs/LocalizedExpression"
11739+
},
1171711740
{
1171811741
"type": "null"
1171911742
}

src/pdl/pdl_ast_utils.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@
3232
)
3333

3434

35-
def is_block_list(blocks: BlocksType) -> bool:
36-
return not isinstance(blocks, str) and isinstance(blocks, Sequence)
37-
38-
3935
def iter_block_children(f: Callable[[BlockType], None], block: BlockType) -> None:
4036
if not isinstance(block, Block):
4137
return
@@ -114,7 +110,8 @@ def iter_block_children(f: Callable[[BlockType], None], block: BlockType) -> Non
114110

115111

116112
def iter_blocks(f: Callable[[BlockType], None], blocks: BlocksType) -> None:
117-
if is_block_list(blocks):
113+
if not isinstance(blocks, str) and isinstance(blocks, Sequence):
114+
# Is a list of blocks
118115
for block in blocks:
119116
f(block)
120117
else:
@@ -219,7 +216,7 @@ def map_block_children(f: MappedFunctions, block: BlockType) -> BlockType:
219216

220217
def map_blocks(f: MappedFunctions, blocks: BlocksType) -> BlocksType:
221218
if not isinstance(blocks, str) and isinstance(blocks, Sequence):
222-
# is a list of blocks
219+
# Is a list of blocks
223220
blocks = [f.f_block(block) for block in blocks]
224221
else:
225222
blocks = f.f_block(blocks)

src/pdl/pdl_dumper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
from typing import Any, TypeAlias
2+
from typing import Any, Sequence, TypeAlias
33

44
import yaml
55

@@ -35,7 +35,6 @@
3535
RepeatUntilBlock,
3636
TextBlock,
3737
)
38-
from .pdl_ast_utils import is_block_list
3938

4039
yaml.SafeDumper.org_represent_str = yaml.SafeDumper.represent_str # type: ignore
4140

@@ -236,7 +235,8 @@ def blocks_to_dict(
236235
result: (
237236
int | float | str | dict[str, Any] | list[int | float | str | dict[str, Any]]
238237
)
239-
if is_block_list(blocks):
238+
if not isinstance(blocks, str) and isinstance(blocks, Sequence):
239+
# Is a list of blocks
240240
result = [block_to_dict(block, json_compatible) for block in blocks]
241241
else:
242242
result = block_to_dict(blocks, json_compatible)

src/pdl/pdl_interpreter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
# from itertools import batched
1010
from pathlib import Path
11-
from typing import Any, Generator, Optional, TypeVar
11+
from typing import Any, Generator, Optional, Sequence, TypeVar
1212

1313
import litellm
1414
import yaml
@@ -65,7 +65,6 @@
6565
TextBlock,
6666
empty_block_location,
6767
)
68-
from .pdl_ast_utils import is_block_list
6968
from .pdl_dumper import blocks_to_dict
7069
from .pdl_llms import BamModel, LitellmModel
7170
from .pdl_location_utils import append, get_loc_string
@@ -806,7 +805,8 @@ def step_blocks(
806805
background: Messages
807806
trace: BlocksType
808807
results = []
809-
if is_block_list(blocks):
808+
if not isinstance(blocks, str) and isinstance(blocks, Sequence):
809+
# Is a list of blocks
810810
iteration_state = state.with_yield_result(
811811
state.yield_result and iteration_type != IterationType.ARRAY
812812
)

src/pdl/pdl_parser.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,13 @@
11
import json
22
from pathlib import Path
3-
from typing import Any, Optional
3+
from typing import Any
44

55
import strictyaml
66
import yaml
77
from pydantic import ValidationError
88

9-
from .pdl_ast import (
10-
Block,
11-
BlocksType,
12-
CallBlock,
13-
DataBlock,
14-
FunctionBlock,
15-
LastOfBlock,
16-
LocationType,
17-
ModelBlock,
18-
PDLException,
19-
Program,
20-
YamlSource,
21-
)
22-
from .pdl_ast_utils import is_block_list
23-
from .pdl_location_utils import append, get_line_map
9+
from .pdl_ast import LocationType, PDLException, Program, YamlSource
10+
from .pdl_location_utils import get_line_map
2411
from .pdl_schema_error_analyzer import analyze_errors
2512

2613

0 commit comments

Comments
 (0)