Skip to content

Commit 1799b6e

Browse files
authored
Docstrings and examples for PDL concepts (#693)
* Docstrings and examples for PDL concepts
1 parent 9a52e8a commit 1799b6e

File tree

3 files changed

+240
-75
lines changed

3 files changed

+240
-75
lines changed

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

Lines changed: 112 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ export type Fallback =
225225
| null
226226
/**
227227
* Role associated to the block and sub-blocks.
228-
*
228+
* Typical roles are `system`, `user`, and `assistant`,
229+
* but there may be other roles such as `available_tools`.
229230
*/
230231
export type Role = string | null
231232
/**
@@ -303,7 +304,8 @@ export type Fallback1 =
303304
| null
304305
/**
305306
* Role associated to the block and sub-blocks.
306-
*
307+
* Typical roles are `system`, `user`, and `assistant`,
308+
* but there may be other roles such as `available_tools`.
307309
*/
308310
export type Role1 = string | null
309311
/**
@@ -409,7 +411,8 @@ export type Fallback2 =
409411
| null
410412
/**
411413
* Role associated to the block and sub-blocks.
412-
*
414+
* Typical roles are `system`, `user`, and `assistant`,
415+
* but there may be other roles such as `available_tools`.
413416
*/
414417
export type Role2 = string | null
415418
/**
@@ -511,7 +514,8 @@ export type Fallback3 =
511514
| null
512515
/**
513516
* Role associated to the block and sub-blocks.
514-
*
517+
* Typical roles are `system`, `user`, and `assistant`,
518+
* but there may be other roles such as `available_tools`.
515519
*/
516520
export type Role3 = string | null
517521
/**
@@ -613,7 +617,8 @@ export type Fallback4 =
613617
| null
614618
/**
615619
* Role associated to the block and sub-blocks.
616-
*
620+
* Typical roles are `system`, `user`, and `assistant`,
621+
* but there may be other roles such as `available_tools`.
617622
*/
618623
export type Role4 = string | null
619624
/**
@@ -642,7 +647,7 @@ export type Read = string | LocalizedExpression | null
642647
*/
643648
export type Message = string | null
644649
/**
645-
* Indicate if one or multiple lines shoud be read.
650+
* Indicate if one or multiple lines should be read.
646651
*
647652
*/
648653
export type Multiline = boolean
@@ -700,6 +705,8 @@ export type Fallback5 =
700705
| null
701706
/**
702707
* Role of associated to the message.
708+
* Typical roles are `system`, `user`, and `assistant`,
709+
* but there may be other roles such as `available_tools`.
703710
*/
704711
export type Role5 = string | null
705712
/**
@@ -799,7 +806,8 @@ export type Fallback6 =
799806
| null
800807
/**
801808
* Role associated to the block and sub-blocks.
802-
*
809+
* Typical roles are `system`, `user`, and `assistant`,
810+
* but there may be other roles such as `available_tools`.
803811
*/
804812
export type Role6 = string | null
805813
/**
@@ -925,7 +933,8 @@ export type Fallback7 =
925933
| null
926934
/**
927935
* Role associated to the block and sub-blocks.
928-
*
936+
* Typical roles are `system`, `user`, and `assistant`,
937+
* but there may be other roles such as `available_tools`.
929938
*/
930939
export type Role7 = string | null
931940
/**
@@ -1026,7 +1035,8 @@ export type Fallback8 =
10261035
| null
10271036
/**
10281037
* Role associated to the block and sub-blocks.
1029-
*
1038+
* Typical roles are `system`, `user`, and `assistant`,
1039+
* but there may be other roles such as `available_tools`.
10301040
*/
10311041
export type Role8 = string | null
10321042
/**
@@ -1127,7 +1137,8 @@ export type Fallback9 =
11271137
| null
11281138
/**
11291139
* Role associated to the block and sub-blocks.
1130-
*
1140+
* Typical roles are `system`, `user`, and `assistant`,
1141+
* but there may be other roles such as `available_tools`.
11311142
*/
11321143
export type Role9 = string | null
11331144
/**
@@ -1254,7 +1265,8 @@ export type Fallback10 =
12541265
| null
12551266
/**
12561267
* Role associated to the block and sub-blocks.
1257-
*
1268+
* Typical roles are `system`, `user`, and `assistant`,
1269+
* but there may be other roles such as `available_tools`.
12581270
*/
12591271
export type Role10 = string | null
12601272
/**
@@ -1435,7 +1447,8 @@ export type Fallback11 =
14351447
| null
14361448
/**
14371449
* Role associated to the block and sub-blocks.
1438-
*
1450+
* Typical roles are `system`, `user`, and `assistant`,
1451+
* but there may be other roles such as `available_tools`.
14391452
*/
14401453
export type Role11 = string | null
14411454
/**
@@ -1575,7 +1588,8 @@ export type Fallback12 =
15751588
| null
15761589
/**
15771590
* Role associated to the block and sub-blocks.
1578-
*
1591+
* Typical roles are `system`, `user`, and `assistant`,
1592+
* but there may be other roles such as `available_tools`.
15791593
*/
15801594
export type Role12 = string | null
15811595
/**
@@ -1599,7 +1613,7 @@ export type Kind12 = "if"
15991613
*/
16001614
export type If1 = boolean | string | LocalizedExpression
16011615
/**
1602-
* Branch to exectute if the condition is true.
1616+
* Branch to execute if the condition is true.
16031617
*
16041618
*/
16051619
export type Then1 =
@@ -1711,7 +1725,8 @@ export type Fallback13 =
17111725
| null
17121726
/**
17131727
* Role associated to the block and sub-blocks.
1714-
*
1728+
* Typical roles are `system`, `user`, and `assistant`,
1729+
* but there may be other roles such as `available_tools`.
17151730
*/
17161731
export type Role13 = string | null
17171732
/**
@@ -1787,7 +1802,8 @@ export type Fallback14 =
17871802
| null
17881803
/**
17891804
* Role associated to the block and sub-blocks.
1790-
*
1805+
* Typical roles are `system`, `user`, and `assistant`,
1806+
* but there may be other roles such as `available_tools`.
17911807
*/
17921808
export type Role14 = string | null
17931809
/**
@@ -1863,7 +1879,8 @@ export type Fallback15 =
18631879
| null
18641880
/**
18651881
* Role associated to the block and sub-blocks.
1866-
*
1882+
* Typical roles are `system`, `user`, and `assistant`,
1883+
* but there may be other roles such as `available_tools`.
18671884
*/
18681885
export type Role15 = string | null
18691886
/**
@@ -1969,7 +1986,8 @@ export type Fallback16 =
19691986
| null
19701987
/**
19711988
* Role associated to the block and sub-blocks.
1972-
*
1989+
* Typical roles are `system`, `user`, and `assistant`,
1990+
* but there may be other roles such as `available_tools`.
19731991
*/
19741992
export type Role16 = string | null
19751993
/**
@@ -2052,7 +2070,7 @@ export type PdlTrace3 =
20522070
*/
20532071
export type Platform = "granite-io"
20542072
/**
2055-
* Backend name and configuartion.
2073+
* Backend name and configuration.
20562074
*
20572075
*/
20582076
export type Backend =
@@ -2062,7 +2080,7 @@ export type Backend =
20622080
}
20632081
| LocalizedExpression
20642082
/**
2065-
* IO Processir name.
2083+
* IO Processor name.
20662084
*
20672085
*/
20682086
export type Processor = string | LocalizedExpression | null
@@ -2131,7 +2149,8 @@ export type Fallback17 =
21312149
| null
21322150
/**
21332151
* Role associated to the block and sub-blocks.
2134-
*
2152+
* Typical roles are `system`, `user`, and `assistant`,
2153+
* but there may be other roles such as `available_tools`.
21352154
*/
21362155
export type Role17 = string | null
21372156
/**
@@ -2150,7 +2169,7 @@ export type Context17 =
21502169
export type PdlId17 = string | null
21512170
export type Kind17 = "model"
21522171
/**
2153-
* Name of he model following the LiteLLM convension.
2172+
* Name of the model following the LiteLLM convention.
21542173
*
21552174
*/
21562175
export type Model1 = string | LocalizedExpression
@@ -2331,7 +2350,8 @@ export type Fallback18 =
23312350
| null
23322351
/**
23332352
* Role associated to the block and sub-blocks.
2334-
*
2353+
* Typical roles are `system`, `user`, and `assistant`,
2354+
* but there may be other roles such as `available_tools`.
23352355
*/
23362356
export type Role18 = string | null
23372357
/**
@@ -2428,7 +2448,8 @@ export type Fallback19 =
24282448
| null
24292449
/**
24302450
* Role associated to the block and sub-blocks.
2431-
*
2451+
* Typical roles are `system`, `user`, and `assistant`,
2452+
* but there may be other roles such as `available_tools`.
24322453
*/
24332454
export type Role19 = string | null
24342455
/**
@@ -2628,7 +2649,14 @@ export interface Defs1 {
26282649
| null
26292650
}
26302651
/**
2631-
* Call a LLM through the LiteLLM API: https://docs.litellm.ai/.
2652+
* Call an LLM through [the LiteLLM API](https://docs.litellm.ai/).
2653+
*
2654+
* Example:
2655+
* ```PDL
2656+
* - model: ollama/granite-code:8b
2657+
* parameters:
2658+
* stop: ['!']
2659+
* ```
26322660
*/
26332661
export interface LitellmModelBlock {
26342662
description?: Description2
@@ -2691,7 +2719,7 @@ export interface Defs2 {
26912719
| null
26922720
}
26932721
/**
2694-
* Call a LLM through the granite-io API.
2722+
* Call an LLM through the granite-io API.
26952723
*/
26962724
export interface GraniteioModelBlock {
26972725
description?: Description3
@@ -2757,6 +2785,16 @@ export interface Defs3 {
27572785
}
27582786
/**
27592787
* Execute a piece of code.
2788+
*
2789+
* Example:
2790+
* ```PDL
2791+
* - def: N
2792+
* lang: python
2793+
* code: |
2794+
* import random
2795+
* # (In PDL, set `result` to the output you wish for your code block.)
2796+
* result = random.randint(1, 20)
2797+
* ```
27602798
*/
27612799
export interface CodeBlock {
27622800
description?: Description4
@@ -2816,6 +2854,8 @@ export interface Defs4 {
28162854
}
28172855
/**
28182856
* Get the value of a variable.
2857+
*
2858+
* The GetBlock is deprecated. Use DataBlock instead.
28192859
*/
28202860
export interface GetBlock {
28212861
description?: Description5
@@ -2873,7 +2913,28 @@ export interface Defs5 {
28732913
| null
28742914
}
28752915
/**
2876-
* Arbitrary JSON value.
2916+
* Arbitrary value, equivalent to JSON.
2917+
*
2918+
* Example. As part of a `defs` section, set `numbers` to the list `[1, 2, 3, 4]`:
2919+
* ```PDL
2920+
* defs:
2921+
* numbers:
2922+
* data: [1, 2, 3, 4]
2923+
* ```
2924+
*
2925+
* Example. Evaluate `${ TEST.answer }` in
2926+
* [Jinja](https://jinja.palletsprojects.com/en/stable/), passing
2927+
* the result to a regex parser with capture groups. Set
2928+
* `EXTRACTED_GROUND_TRUTH` to an object with attribute `answer`,
2929+
* a string, containing the value of the capture group.
2930+
* ```PDL
2931+
* - data: ${ TEST.answer }
2932+
* parser:
2933+
* regex: "(.|\n)*#### (?P<answer>([0-9])*)\n*"
2934+
* spec:
2935+
* answer: str
2936+
* def: EXTRACTED_GROUND_TRUTH
2937+
* ```
28772938
*/
28782939
export interface DataBlock {
28792940
description?: Description6
@@ -2933,6 +2994,15 @@ export interface Defs6 {
29332994
}
29342995
/**
29352996
* Conditional control structure.
2997+
*
2998+
* Example:
2999+
* ```PDL
3000+
* - if: ${ eval == 'no' }
3001+
* then:
3002+
* text:
3003+
* - read:
3004+
* message: "Why not?\n"
3005+
* ```
29363006
*/
29373007
export interface IfBlock {
29383008
description?: Description7
@@ -3053,6 +3123,15 @@ export interface Defs8 {
30533123
}
30543124
/**
30553125
* Repeat the execution of a block.
3126+
*
3127+
* For loop example:
3128+
* ```PDL
3129+
* for:
3130+
* number: [1, 2, 3, 4]
3131+
* name: ["Bob", "Carol", "David", "Ernest"]
3132+
* repeat:
3133+
* "${ name }'s number is ${ number }\n"
3134+
* ```
30563135
*/
30573136
export interface RepeatBlock {
30583137
description?: Description9
@@ -3707,6 +3786,9 @@ export interface PdlParser {
37073786
spec?: Spec20
37083787
pdl: Pdl
37093788
}
3789+
/**
3790+
* A regular expression parser
3791+
*/
37103792
export interface RegexParser {
37113793
description?: Description21
37123794
spec?: Spec21
@@ -3792,7 +3874,9 @@ export interface AnyPattern {
37923874
any: Any
37933875
}
37943876
/**
3795-
* Parameters passed to LiteLLM. More details at https://docs.litellm.ai/docs/completion/input.
3877+
* Parameters passed to LiteLLM. More details at [https://docs.litellm.ai/docs/completion/input](https://docs.litellm.ai/docs/completion/input).
3878+
*
3879+
* Note that not all models and platforms accept all parameters.
37963880
*/
37973881
export interface LitellmParameters {
37983882
timeout?: Timeout

0 commit comments

Comments
 (0)