You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tutorial.md
+26-28Lines changed: 26 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -535,7 +535,7 @@ tools:
535
535
object:
536
536
hello:
537
537
function:
538
-
arguments: obj
538
+
arguments: object
539
539
return:
540
540
lang: python
541
541
code: |
@@ -569,7 +569,7 @@ tool_schema:
569
569
type: object
570
570
properties:
571
571
answer:
572
-
type: str
572
+
type: string
573
573
description: The answer
574
574
required:
575
575
- answer
@@ -586,7 +586,7 @@ finish_action:
586
586
type: object
587
587
properties:
588
588
answer:
589
-
type: str
589
+
type: string
590
590
description: The answer
591
591
required:
592
592
- answer
@@ -916,12 +916,9 @@ some JSON data.
916
916
--8<-- "./examples/tutorial/type_checking.pdl"
917
917
```
918
918
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.
922
920
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.
925
922
926
923
When we run this program, we obtain the output:
927
924
@@ -933,26 +930,27 @@ type_checking.pdl:9 - twentyfive should be of type <class 'int'>
933
930
934
931
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.
935
932
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
956
954
- `{enum: [red, green, blue]}`: an enumeration
957
955
958
956
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).
0 commit comments