Skip to content

Commit 970aef0

Browse files
authored
feat: change type syntax (#951)
Signed-off-by: Louis Mandel <[email protected]>
1 parent 8bc69de commit 970aef0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+676
-1147
lines changed

contrib/prompt_library/CoT.pdl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@ defs:
33
# Chain of Thought
44
cot_block:
55
function:
6-
question: str
7-
reasoning: str
8-
answer: str
6+
question: string
7+
reasoning: string
8+
answer: string
99
return: |-
1010
Question: ${ question }
1111
Answer: Let's think step by step. ${ reasoning }
1212
The answer is ${ answer }
1313

1414
fewshot_cot:
1515
function:
16-
examples:
17-
{ list: { obj: { question: str, reasoning: str, answer: str } } }
16+
examples: [{ question: string, reasoning: string, answer: string }]
1817
return:
1918
text:
2019
- for:
@@ -30,10 +29,9 @@ defs:
3029

3130
chain_of_thought:
3231
function:
33-
question: str
34-
model: str
35-
examples:
36-
{ list: { obj: { question: str, reasoning: str, answer: str } } }
32+
question: string
33+
model: string
34+
examples: [{ question: string, reasoning: string, answer: string }]
3735
return:
3836
lastOf:
3937
- call: ${ fewshot_cot }

contrib/prompt_library/ReAct.pdl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: ReAct pattern from Yao et al., [ICLR 2023](https://openreview.net/f
33
defs:
44
react_block:
55
function:
6-
trajectory: { list: obj }
6+
trajectory: [ object ]
77
return:
88
text:
99
- for:
@@ -36,11 +36,11 @@ defs:
3636

3737
react:
3838
function:
39-
task: str
40-
model: str
41-
tool_schema: { list: obj }
42-
tools: obj
43-
trajectories: { list: list }
39+
task: string
40+
model: string
41+
tool_schema: [ object ]
42+
tools: object
43+
trajectories: [ array ]
4444
return:
4545
lastOf:
4646
- role: system
@@ -95,7 +95,7 @@ defs:
9595
temperature: 0
9696
stop: ["\n", "Obs:", "<|eom_id|>"]
9797
include_stop_sequence: false
98-
spec: { name: str, arguments: obj }
98+
spec: { name: string, arguments: object }
9999
- if: ${ action != prev_action }
100100
then:
101101
def: observation

contrib/prompt_library/ReWoo.pdl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: ReWOO (Reasoning without observation) pattern from Xu et al., (http
55
defs:
66
rewoo_block:
77
function:
8-
trajectory: { list: obj }
8+
trajectory: [ object ]
99
return:
1010
text:
1111
- defs:
@@ -47,12 +47,12 @@ defs:
4747

4848
rewoo:
4949
function:
50-
task: str
51-
model: str
52-
tool_schema: { list: obj }
53-
tools: obj
54-
trajectories: { list: list }
55-
show_plans: bool
50+
task: string
51+
model: string
52+
tool_schema: [object]
53+
tools: object
54+
trajectories: array
55+
show_plans: boolean
5656
return:
5757
lastOf:
5858
- |

contrib/prompt_library/tools.pdl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ defs:
1212

1313
filter_tools_by_name:
1414
function:
15-
tools: { list: obj }
16-
tool_names: { list: str }
15+
tools: [object]
16+
tool_names: [string]
1717
return:
1818
data: ${ tools|selectattr('name', 'in', tool_names)|list }
1919

@@ -58,7 +58,7 @@ defs:
5858
object:
5959
calculator:
6060
function:
61-
arguments: obj
61+
arguments: object
6262
return:
6363
lang: python
6464
code: |
@@ -81,7 +81,7 @@ defs:
8181
result = main(**arguments)
8282
search:
8383
function:
84-
arguments: obj
84+
arguments: object
8585
return:
8686
lastOf:
8787
- def: result

docs/tutorial.md

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ tools:
535535
object:
536536
hello:
537537
function:
538-
arguments: obj
538+
arguments: object
539539
return:
540540
lang: python
541541
code: |
@@ -569,7 +569,7 @@ tool_schema:
569569
type: object
570570
properties:
571571
answer:
572-
type: str
572+
type: string
573573
description: The answer
574574
required:
575575
- answer
@@ -586,7 +586,7 @@ finish_action:
586586
type: object
587587
properties:
588588
answer:
589-
type: str
589+
type: string
590590
description: The answer
591591
required:
592592
- answer
@@ -916,12 +916,9 @@ some JSON data.
916916
--8<-- "./examples/tutorial/type_checking.pdl"
917917
```
918918

919-
Upon reading the data we use a parser to parse it into a YAML. The `spec` field indicates the expected type for the
920-
data, which is an object with 2 fields: `questions` and `answers` that are a list of string and a list of objects,
921-
respectively. When the interpreter is executed, it checks this type dynamically and throws errors if necessary.
919+
Upon reading the data we use a parser to parse it into a YAML. The `spec` field indicates the expected type for the data, which is an object with 2 fields: `questions` and `answers` that are an array of string and an array of objects, respectively. When the interpreter is executed, it checks this type dynamically and throws errors if necessary.
922920

923-
Similarly, the output of the model call is parsed as YAML, and the `spec` indicates that we expect an object with
924-
2 fields: `name` of type string, and `age` of type integer.
921+
Similarly, the output of the model call is parsed as YAML, and the `spec` indicates that we expect an object with two fields: `name` of type string, and `age` of type integer.
925922

926923
When we run this program, we obtain the output:
927924

@@ -933,26 +930,27 @@ type_checking.pdl:9 - twentyfive should be of type <class 'int'>
933930

934931
Notice that since we asked the age to be produced in letters, we got a string back and this causes a type error indicated above.
935932

936-
In general, `spec` definitions can be a subset of JSON schema, or use a shorthand notation as illustrated by
937-
the examples below:
938-
939-
- `bool`: boolean
940-
- `str`: string
941-
- `int`: integer
942-
- `float`: float
943-
- `{str: {pattern: '^[A-Za-z][A-Za-z0-9_]*$'}}`: a string satisfying the indicated pattern
944-
- `{float: {minimum: 0, exclusiveMaximum: 1}}`: a float satisfying the indicated constraints
945-
- `{list: int}`: a list of integers
946-
- `[int]`: a list of integers
947-
- `{list: {int: {minimum: 0}}}`: a list of integers satisfying the indicated constraints
948-
- `[{int: {minimum: 0}}]`: same as above
949-
- `{list: {minItems: 1, int: {}}}`, a list satisfying the indicated constraints
950-
- `{obj: {latitude: float, longitude: float}}`: an object with fields `latitude` and `longitude`
951-
- `{latitude: float, longitude: float}`: same as above
952-
- `{obj: {question: str, answer: str, context: {optional: str}}}`: an object with an optional field
953-
- `{question: str, answer: str, context: {optional: str}}`: same as above
954-
- `{list: {obj: {question: str, answer: str}}}`: a list of objects
955-
- `[{question: str, answer: str}]`: same as above
933+
In general, `spec` definitions can be a subset of JSON schema, or use a shorthand notation as illustrated by the examples below:
934+
935+
- `boolean` or `{type: boolean}`: boolean
936+
- `string` or `{type: string}`: string
937+
- `integer` or `{type: integer}`: integer
938+
- `number` or `{type: number}`: floating point numbers
939+
- `"null"` or `{type: "null"}`: type of the `null` value
940+
- `array` or `{type: array}`: array with elements of any type
941+
- `object` or `{type: object}`: object with any fields
942+
- `{type: string, pattern: '^[A-Za-z][A-Za-z0-9_]*$'}`: a string satisfying the indicated pattern
943+
- `{type: number, minimum: 0, exclusiveMaximum: 1}`: a float satisfying the indicated constraints
944+
- `[integer]`: an array of integers
945+
- `{type: array, items: { type: integer }}`: same as above
946+
- `[{ type: integer, minimum: 0}]`: a list of integers satisfying the indicated constraints
947+
- `{type: array, items: { type: integer, minimum: 0}}`: same as above
948+
- `{type: array, minItems: 1}`, a list with at least one element
949+
- `{latitude: number, longitude: number}`: an object with fields `latitude` and `longitude`
950+
- `{object: {latitude: number, longitude: number}}`: same as above
951+
- `{question: string, answer: string, context: {optional: string}}`: an object with an optional field `context`
952+
- `{object: {question: string, answer: string, context: {optional: string}}}`: same as above
953+
- `[{question: string, answer: string}]`: a list of objects
956954
- `{enum: [red, green, blue]}`: an enumeration
957955

958956
Another example of type checking a list can be found [here](https://github.com/IBM/prompt-declaration-language//blob/main/examples/tutorial/type_list.pdl).

examples/callback/repair_prompt.pdl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ lastOf:
1515

1616
- lang: python
1717
def: parsed_output
18-
spec: {thought: str, code_line: str}
18+
spec: {thought: string, code_line: string}
1919
code: |
2020
import repair_main
2121
# (In PDL, set `result` to the output you wish for your code block.)
2222
result = repair_main.parse_output(raw_output)
2323

24-
- spec: {before: str, after: str}
24+
- spec: {before: string, after: string}
2525
object:
2626
before: ${code_line}
2727
after: ${parsed_output.code_line}

0 commit comments

Comments
 (0)