Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions contrib/prompt_library/CoT.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ defs:
# Chain of Thought
cot_block:
function:
question: str
reasoning: str
answer: str
question: string
reasoning: string
answer: string
return: |-
Question: ${ question }
Answer: Let's think step by step. ${ reasoning }
The answer is ${ answer }

fewshot_cot:
function:
examples:
{ list: { obj: { question: str, reasoning: str, answer: str } } }
examples: [{ question: string, reasoning: string, answer: string }]
return:
text:
- for:
Expand All @@ -30,10 +29,9 @@ defs:

chain_of_thought:
function:
question: str
model: str
examples:
{ list: { obj: { question: str, reasoning: str, answer: str } } }
question: string
model: string
examples: [{ question: string, reasoning: string, answer: string }]
return:
lastOf:
- call: ${ fewshot_cot }
Expand Down
14 changes: 7 additions & 7 deletions contrib/prompt_library/ReAct.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: ReAct pattern from Yao et al., [ICLR 2023](https://openreview.net/f
defs:
react_block:
function:
trajectory: { list: obj }
trajectory: [ object ]
return:
text:
- for:
Expand Down Expand Up @@ -36,11 +36,11 @@ defs:

react:
function:
task: str
model: str
tool_schema: { list: obj }
tools: obj
trajectories: { list: list }
task: string
model: string
tool_schema: [ object ]
tools: object
trajectories: [ array ]
return:
lastOf:
- role: system
Expand Down Expand Up @@ -95,7 +95,7 @@ defs:
temperature: 0
stop: ["\n", "Obs:", "<|eom_id|>"]
include_stop_sequence: false
spec: { name: str, arguments: obj }
spec: { name: string, arguments: object }
- if: ${ action != prev_action }
then:
def: observation
Expand Down
14 changes: 7 additions & 7 deletions contrib/prompt_library/ReWoo.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: ReWOO (Reasoning without observation) pattern from Xu et al., (http
defs:
rewoo_block:
function:
trajectory: { list: obj }
trajectory: [ object ]
return:
text:
- defs:
Expand Down Expand Up @@ -47,12 +47,12 @@ defs:

rewoo:
function:
task: str
model: str
tool_schema: { list: obj }
tools: obj
trajectories: { list: list }
show_plans: bool
task: string
model: string
tool_schema: [object]
tools: object
trajectories: array
show_plans: boolean
return:
lastOf:
- |
Expand Down
8 changes: 4 additions & 4 deletions contrib/prompt_library/tools.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ defs:

filter_tools_by_name:
function:
tools: { list: obj }
tool_names: { list: str }
tools: [object]
tool_names: [string]
return:
data: ${ tools|selectattr('name', 'in', tool_names)|list }

Expand Down Expand Up @@ -58,7 +58,7 @@ defs:
object:
calculator:
function:
arguments: obj
arguments: object
return:
lang: python
code: |
Expand All @@ -81,7 +81,7 @@ defs:
result = main(**arguments)
search:
function:
arguments: obj
arguments: object
return:
lastOf:
- def: result
Expand Down
54 changes: 26 additions & 28 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ tools:
object:
hello:
function:
arguments: obj
arguments: object
return:
lang: python
code: |
Expand Down Expand Up @@ -569,7 +569,7 @@ tool_schema:
type: object
properties:
answer:
type: str
type: string
description: The answer
required:
- answer
Expand All @@ -586,7 +586,7 @@ finish_action:
type: object
properties:
answer:
type: str
type: string
description: The answer
required:
- answer
Expand Down Expand Up @@ -916,12 +916,9 @@ some JSON data.
--8<-- "./examples/tutorial/type_checking.pdl"
```

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 a list of string and a list of objects,
respectively. When the interpreter is executed, it checks this type dynamically and throws errors if necessary.
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.

Similarly, the output of the model call is parsed as YAML, and the `spec` indicates that we expect an object with
2 fields: `name` of type string, and `age` of type integer.
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.

When we run this program, we obtain the output:

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

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.

In general, `spec` definitions can be a subset of JSON schema, or use a shorthand notation as illustrated by
the examples below:

- `bool`: boolean
- `str`: string
- `int`: integer
- `float`: float
- `{str: {pattern: '^[A-Za-z][A-Za-z0-9_]*$'}}`: a string satisfying the indicated pattern
- `{float: {minimum: 0, exclusiveMaximum: 1}}`: a float satisfying the indicated constraints
- `{list: int}`: a list of integers
- `[int]`: a list of integers
- `{list: {int: {minimum: 0}}}`: a list of integers satisfying the indicated constraints
- `[{int: {minimum: 0}}]`: same as above
- `{list: {minItems: 1, int: {}}}`, a list satisfying the indicated constraints
- `{obj: {latitude: float, longitude: float}}`: an object with fields `latitude` and `longitude`
- `{latitude: float, longitude: float}`: same as above
- `{obj: {question: str, answer: str, context: {optional: str}}}`: an object with an optional field
- `{question: str, answer: str, context: {optional: str}}`: same as above
- `{list: {obj: {question: str, answer: str}}}`: a list of objects
- `[{question: str, answer: str}]`: same as above
In general, `spec` definitions can be a subset of JSON schema, or use a shorthand notation as illustrated by the examples below:

- `boolean` or `{type: boolean}`: boolean
- `string` or `{type: string}`: string
- `integer` or `{type: integer}`: integer
- `number` or `{type: number}`: floating point numbers
- `"null"` or `{type: "null"}`: type of the `null` value
- `array` or `{type: array}`: array with elements of any type
- `object` or `{type: object}`: object with any fields
- `{type: string, pattern: '^[A-Za-z][A-Za-z0-9_]*$'}`: a string satisfying the indicated pattern
- `{type: number, minimum: 0, exclusiveMaximum: 1}`: a float satisfying the indicated constraints
- `[integer]`: an array of integers
- `{type: array, items: { type: integer }}`: same as above
- `[{ type: integer, minimum: 0}]`: a list of integers satisfying the indicated constraints
- `{type: array, items: { type: integer, minimum: 0}}`: same as above
- `{type: array, minItems: 1}`, a list with at least one element
- `{latitude: number, longitude: number}`: an object with fields `latitude` and `longitude`
- `{object: {latitude: number, longitude: number}}`: same as above
- `{question: string, answer: string, context: {optional: string}}`: an object with an optional field `context`
- `{object: {question: string, answer: string, context: {optional: string}}}`: same as above
- `[{question: string, answer: string}]`: a list of objects
- `{enum: [red, green, blue]}`: an enumeration

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).
Expand Down
4 changes: 2 additions & 2 deletions examples/callback/repair_prompt.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ lastOf:

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

- spec: {before: str, after: str}
- spec: {before: string, after: string}
object:
before: ${code_line}
after: ${parsed_output.code_line}
Loading
Loading