Skip to content

Commit 90f2183

Browse files
authored
Provide a map function on the PDL ast (#131)
1 parent 22f2bee commit 90f2183

File tree

7 files changed

+369
-50
lines changed

7 files changed

+369
-50
lines changed

pdl-live/src/pdl_ast.d.ts

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,30 @@ export type Trace =
508508
| IncludeBlock
509509
| ErrorBlock
510510
| EmptyBlock
511+
| (
512+
| number
513+
| string
514+
| FunctionBlock
515+
| CallBlock
516+
| LitellmModelBlock
517+
| BamModelBlock
518+
| CodeBlock
519+
| GetBlock
520+
| DataBlock
521+
| IfBlock
522+
| RepeatBlock
523+
| RepeatUntilBlock
524+
| ForBlock
525+
| TextBlock
526+
| LastOfBlock
527+
| ArrayBlock
528+
| ObjectBlock
529+
| MessageBlock
530+
| ReadBlock
531+
| IncludeBlock
532+
| ErrorBlock
533+
| EmptyBlock
534+
)[]
511535
| null;
512536
/**
513537
* Name of the variable used to store the result of the execution of the block.
@@ -581,11 +605,6 @@ export type Fallback3 =
581605
*/
582606
export type Role3 = string | null;
583607
export type Kind3 = "read";
584-
/**
585-
* Name of the file to read. If `None`, read the standard input.
586-
*
587-
*/
588-
export type Read = string | null;
589608
/**
590609
* Message to prompt the user to enter a value.
591610
*
@@ -813,7 +832,31 @@ export type Object =
813832
| ReadBlock
814833
| IncludeBlock
815834
| ErrorBlock
816-
| EmptyBlock;
835+
| EmptyBlock
836+
| (
837+
| number
838+
| string
839+
| FunctionBlock
840+
| CallBlock
841+
| LitellmModelBlock
842+
| BamModelBlock
843+
| CodeBlock
844+
| GetBlock
845+
| DataBlock
846+
| IfBlock
847+
| RepeatBlock
848+
| RepeatUntilBlock
849+
| ForBlock
850+
| TextBlock
851+
| LastOfBlock
852+
| ArrayBlock
853+
| ObjectBlock
854+
| MessageBlock
855+
| ReadBlock
856+
| IncludeBlock
857+
| ErrorBlock
858+
| EmptyBlock
859+
)[];
817860
}
818861
| (
819862
| number
@@ -2287,7 +2330,6 @@ export type Fallback16 =
22872330
*/
22882331
export type Role16 = string | null;
22892332
export type Kind16 = "model";
2290-
export type Model = string;
22912333
export type Input =
22922334
| number
22932335
| string
@@ -2490,7 +2532,6 @@ export type Fallback17 =
24902532
*/
24912533
export type Role17 = string | null;
24922534
export type Kind17 = "model";
2493-
export type Model1 = string;
24942535
export type Input1 =
24952536
| number
24962537
| string
@@ -2689,11 +2730,6 @@ export type Fallback18 =
26892730
*/
26902731
export type Role18 = string | null;
26912732
export type Kind18 = "call";
2692-
/**
2693-
* Function to call.
2694-
*
2695-
*/
2696-
export type Call = string;
26972733
export type Trace6 =
26982734
| number
26992735
| string
@@ -3119,7 +3155,7 @@ export interface LitellmModelBlock {
31193155
result?: unknown;
31203156
location?: LocationType | null;
31213157
kind?: Kind17;
3122-
model: Model1;
3158+
model: unknown;
31233159
input?: Input1;
31243160
trace?: Trace5;
31253161
platform?: Platform1;
@@ -3197,7 +3233,7 @@ export interface BamModelBlock {
31973233
result?: unknown;
31983234
location?: LocationType | null;
31993235
kind?: Kind16;
3200-
model: Model;
3236+
model: unknown;
32013237
input?: Input;
32023238
trace?: Trace4;
32033239
platform: Platform;
@@ -4220,7 +4256,7 @@ export interface ReadBlock {
42204256
result?: unknown;
42214257
location?: LocationType | null;
42224258
kind?: Kind3;
4223-
read: Read;
4259+
read: unknown;
42244260
message?: Message;
42254261
multiline?: Multiline;
42264262
}
@@ -4681,6 +4717,13 @@ export interface LitellmParameters {
46814717
max_retries?: MaxRetries;
46824718
[k: string]: unknown;
46834719
}
4720+
/**
4721+
* Function to call.
4722+
*
4723+
*/
4724+
export interface Call {
4725+
[k: string]: unknown;
4726+
}
46844727
/**
46854728
* Arguments of the function with their values.
46864729
*

pdl-live/src/pdl_ast_utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function map_block_children(
5757
object = block.object.map(f);
5858
} else {
5959
object = Object.fromEntries(
60-
Object.entries(block.object).map(([k, v]) => [k, f(v)])
60+
Object.entries(block.object).map(([k, v]) => [k, map_blocks(f, v)])
6161
);
6262
}
6363
return {...block, object: object};
@@ -154,7 +154,7 @@ export function iter_block_children(
154154
if (block.object instanceof Array) {
155155
iter_blocks(f, block.object);
156156
} else {
157-
Object.entries(block.object).forEach(([_, v]) => f(v));
157+
Object.entries(block.object).forEach(([_, v]) => iter_blocks(f, v));
158158
}
159159
return {...block, object: object};
160160
})

src/pdl/pdl-schema.json

Lines changed: 168 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,8 +1005,13 @@
10051005
"type": "string"
10061006
},
10071007
"model": {
1008-
"title": "Model",
1009-
"type": "string"
1008+
"anyOf": [
1009+
{
1010+
"type": "string"
1011+
},
1012+
{}
1013+
],
1014+
"title": "Model"
10101015
},
10111016
"input": {
10121017
"anyOf": [
@@ -1960,8 +1965,7 @@
19601965
},
19611966
"call": {
19621967
"description": "Function to call.\n ",
1963-
"title": "Call",
1964-
"type": "string"
1968+
"title": "Call"
19651969
},
19661970
"args": {
19671971
"default": {},
@@ -7257,6 +7261,82 @@
72577261
{
72587262
"$ref": "#/$defs/EmptyBlock"
72597263
},
7264+
{
7265+
"items": {
7266+
"anyOf": [
7267+
{
7268+
"type": "integer"
7269+
},
7270+
{
7271+
"type": "number"
7272+
},
7273+
{
7274+
"type": "string"
7275+
},
7276+
{
7277+
"$ref": "#/$defs/FunctionBlock"
7278+
},
7279+
{
7280+
"$ref": "#/$defs/CallBlock"
7281+
},
7282+
{
7283+
"$ref": "#/$defs/LitellmModelBlock"
7284+
},
7285+
{
7286+
"$ref": "#/$defs/BamModelBlock"
7287+
},
7288+
{
7289+
"$ref": "#/$defs/CodeBlock"
7290+
},
7291+
{
7292+
"$ref": "#/$defs/GetBlock"
7293+
},
7294+
{
7295+
"$ref": "#/$defs/DataBlock"
7296+
},
7297+
{
7298+
"$ref": "#/$defs/IfBlock"
7299+
},
7300+
{
7301+
"$ref": "#/$defs/RepeatBlock"
7302+
},
7303+
{
7304+
"$ref": "#/$defs/RepeatUntilBlock"
7305+
},
7306+
{
7307+
"$ref": "#/$defs/ForBlock"
7308+
},
7309+
{
7310+
"$ref": "#/$defs/TextBlock"
7311+
},
7312+
{
7313+
"$ref": "#/$defs/LastOfBlock"
7314+
},
7315+
{
7316+
"$ref": "#/$defs/ArrayBlock"
7317+
},
7318+
{
7319+
"$ref": "#/$defs/ObjectBlock"
7320+
},
7321+
{
7322+
"$ref": "#/$defs/MessageBlock"
7323+
},
7324+
{
7325+
"$ref": "#/$defs/ReadBlock"
7326+
},
7327+
{
7328+
"$ref": "#/$defs/IncludeBlock"
7329+
},
7330+
{
7331+
"$ref": "#/$defs/ErrorBlock"
7332+
},
7333+
{
7334+
"$ref": "#/$defs/EmptyBlock"
7335+
}
7336+
]
7337+
},
7338+
"type": "array"
7339+
},
72607340
{
72617341
"type": "null"
72627342
}
@@ -8371,8 +8451,13 @@
83718451
"type": "string"
83728452
},
83738453
"model": {
8374-
"title": "Model",
8375-
"type": "string"
8454+
"anyOf": [
8455+
{
8456+
"type": "string"
8457+
},
8458+
{}
8459+
],
8460+
"title": "Model"
83768461
},
83778462
"input": {
83788463
"anyOf": [
@@ -10415,6 +10500,82 @@
1041510500
},
1041610501
{
1041710502
"$ref": "#/$defs/EmptyBlock"
10503+
},
10504+
{
10505+
"items": {
10506+
"anyOf": [
10507+
{
10508+
"type": "integer"
10509+
},
10510+
{
10511+
"type": "number"
10512+
},
10513+
{
10514+
"type": "string"
10515+
},
10516+
{
10517+
"$ref": "#/$defs/FunctionBlock"
10518+
},
10519+
{
10520+
"$ref": "#/$defs/CallBlock"
10521+
},
10522+
{
10523+
"$ref": "#/$defs/LitellmModelBlock"
10524+
},
10525+
{
10526+
"$ref": "#/$defs/BamModelBlock"
10527+
},
10528+
{
10529+
"$ref": "#/$defs/CodeBlock"
10530+
},
10531+
{
10532+
"$ref": "#/$defs/GetBlock"
10533+
},
10534+
{
10535+
"$ref": "#/$defs/DataBlock"
10536+
},
10537+
{
10538+
"$ref": "#/$defs/IfBlock"
10539+
},
10540+
{
10541+
"$ref": "#/$defs/RepeatBlock"
10542+
},
10543+
{
10544+
"$ref": "#/$defs/RepeatUntilBlock"
10545+
},
10546+
{
10547+
"$ref": "#/$defs/ForBlock"
10548+
},
10549+
{
10550+
"$ref": "#/$defs/TextBlock"
10551+
},
10552+
{
10553+
"$ref": "#/$defs/LastOfBlock"
10554+
},
10555+
{
10556+
"$ref": "#/$defs/ArrayBlock"
10557+
},
10558+
{
10559+
"$ref": "#/$defs/ObjectBlock"
10560+
},
10561+
{
10562+
"$ref": "#/$defs/MessageBlock"
10563+
},
10564+
{
10565+
"$ref": "#/$defs/ReadBlock"
10566+
},
10567+
{
10568+
"$ref": "#/$defs/IncludeBlock"
10569+
},
10570+
{
10571+
"$ref": "#/$defs/ErrorBlock"
10572+
},
10573+
{
10574+
"$ref": "#/$defs/EmptyBlock"
10575+
}
10576+
]
10577+
},
10578+
"type": "array"
1041810579
}
1041910580
]
1042010581
},
@@ -11515,9 +11676,7 @@
1151511676
},
1151611677
"read": {
1151711678
"anyOf": [
11518-
{
11519-
"type": "string"
11520-
},
11679+
{},
1152111680
{
1152211681
"type": "null"
1152311682
}

0 commit comments

Comments
 (0)