Skip to content

Commit

Permalink
Use $\{ syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiosv committed Sep 30, 2024
1 parent 0e32217 commit 5921b9f
Show file tree
Hide file tree
Showing 16 changed files with 241 additions and 241 deletions.
26 changes: 13 additions & 13 deletions examples/prompt_library/CoT.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ defs:
reasoning: str
answer: str
return: |+
Question: {{ question }}
Answer: Let's think step by step. {{ reasoning }}
The answer is {{ answer }}
Question: ${ question }
Answer: Let's think step by step. ${ reasoning }
The answer is ${ answer }

# Auto Chain of Thought Zhang et al. (2022)
# The idea is to use a _model_ to generate a reasoning path, even if not very accurate.
Expand All @@ -21,30 +21,30 @@ defs:
answer: str
return:
- |-
Question: {{ question }}
Question: ${ question }
- "Answer: Let's think step by step. "
- model: "{{ model }}"
- model: "${ model }"
parameters:
decoding_method: "greedy"
stop_sequences:
- "The answer is"
include_stop_sequence: false
- "The answer is {{ answer }}"
- "The answer is ${ answer }"

fewshot_cot:
function:
examples:
{ list: { obj: { question: str, reasoning: str, answer: str } } }
return:
for:
example: "{{ examples }}"
example: "${ examples }"
repeat:
document:
call: cot_block
args:
question: "{{ example.question }}"
reasoning: "{{ example.reasoning }}"
answer: "{{ example.answer }}"
question: "${ example.question }"
reasoning: "${ example.reasoning }"
answer: "${ example.answer }"
as: document

chain_of_thought:
Expand All @@ -56,11 +56,11 @@ defs:
return:
- call: fewshot_cot
args:
examples: "{{ examples }}"
examples: "${ examples }"
- |
Question: {{ question }}
Question: ${ question }
- "Answer: Let's think step by step. "
- model: "{{ model }}"
- model: "${ model }"
parameters:
decoding_method: greedy
stop_sequences:
Expand Down
12 changes: 6 additions & 6 deletions examples/prompt_library/PoT.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ defs:
total_hours = total_minutes / 60
result = 5 - total_hours

Question: {{ question }}
Question: ${ question }
# Python code, return ans

- def: PROGRAM
model: "{{ model }}"
model: "${ model }"
parameters:
stop_sequences: ["\nAnswer: "]
include_stop_sequence: false
- def: ANSWER
lan: python
code: "{{ PROGRAM }}"
code: "${ PROGRAM }"
- get: ANSWER

program_of_thought_backtick:
Expand Down Expand Up @@ -211,10 +211,10 @@ defs:
result = 5 - total_hours
```

Question: {{ question }}
Question: ${ question }
# Python code, return ans
- def: PROGRAM
model: "{{ model }}"
model: "${ model }"
parser:
regex: '```.*\n((?:.|\n|$)*?)$\n\s*```' # extracts code from backtick blocks
mode: findall
Expand All @@ -223,5 +223,5 @@ defs:
include_stop_sequence: false
- def: ANSWER
lan: python
code: "{{ PROGRAM|join('\n') }}"
code: "${ PROGRAM|join('\n') }"
- get: ANSWER
142 changes: 71 additions & 71 deletions examples/prompt_library/ReAct.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ defs:
trajectory: { list: obj }
return:
- for:
trajectory: "{{ trajectory }}"
trajectory: "${ trajectory }"
repeat:
- defs:
type: "{{ trajectory.keys()|first }}"
- if: "{{ type == 'question'}}"
type: "${ trajectory.keys()|first }"
- if: "${ type == 'question'}"
then: |
Question: {{ trajectory[type]|trim }}
- if: "{{ type == 'task'}}"
Question: ${ trajectory[type]|trim }
- if: "${ type == 'task'}"
then: |
Task: {{ trajectory[type]|trim }}
- if: "{{ type == 'thought'}}"
Task: ${ trajectory[type]|trim }
- if: "${ type == 'thought'}"
then: |
Tho: {{ trajectory[type]|trim }}
- if: "{{ type == 'action'}}"
Tho: ${ trajectory[type]|trim }
- if: "${ type == 'action'}"
then: |
Act: {{ trajectory[type]|trim }}
- if: "{{ type == 'observation'}}"
Act: ${ trajectory[type]|trim }
- if: "${ type == 'observation'}"
then: |
Obs: {{ trajectory[type]|trim }}
- if: "{{ type not in ['question', 'task', 'thought', 'action', 'observation'] }}"
then: "{{ type }}: {{ trajectory[type]|trim }}"
Obs: ${ trajectory[type]|trim }
- if: "${ type not in ['question', 'task', 'thought', 'action', 'observation'] }"
then: "${ type }: ${ trajectory[type]|trim }"
- "\n"

finish_action:
Expand All @@ -45,14 +45,14 @@ defs:
tools: { list: obj }
return:
for:
tool: "{{ tools }}"
tool: "${ tools }"
repeat:
for:
example: "{{ tool.examples }}"
example: "${ tool.examples }"
repeat:
call: react_block
args:
trajectory: "{{ example }}"
trajectory: "${ example }"

react:
function:
Expand All @@ -65,94 +65,94 @@ defs:
TOOL_INFO:
call: list_tools
args:
tools: "{{ tools.append(finish_action) or tools }}"
tools: "${ tools.append(finish_action) or tools }"
- "Available tools:\n"
- for:
name: "{{ TOOL_INFO.display_names }}"
sig: "{{ TOOL_INFO.signatures }}"
desc: "{{ TOOL_INFO.descriptions }}"
name: "${ TOOL_INFO.display_names }"
sig: "${ TOOL_INFO.signatures }"
desc: "${ TOOL_INFO.descriptions }"
repeat: |
{{ name }}: {{ desc }}
${ name }: ${ desc }
- "\n"
- call: demonstrate_tools
args:
tools: "{{ tools }}"
tools: "${ tools }"
- for:
traj: "{{ trajectories }}"
traj: "${ trajectories }"
repeat:
call: react_block
args:
trajectory: "{{ traj }}"
- "{{ task }}\nTho:"
trajectory: "${ traj }"
- "${ task }\nTho:"
- defs:
temperature: 0.7
iterations: 0
repeat:
- repeat:
- defs:
iterations: "{{ iterations+1 }}"
iterations: "${ iterations+1 }"
- def: THOUGHT
model: "{{ model }}"
model: "${ model }"
parameters:
time_limit: 60000
random_seed: 42
truncate_input_tokens: 8191
decoding_method: sample
repetition_penalty: 1.1
temperature: "{{ temperature }}"
temperature: "${ temperature }"
stop_sequences: ["\n", "Act:", "Obs:", "Tho:"]
include_stop_sequence: true
until: "{{ THOUGHT.endswith('Act:') or iterations>20 }}"
until: "${ THOUGHT.endswith('Act:') or iterations>20 }"
- def: action_raw
model: "{{ model }}"
model: "${ model }"
parameters:
time_limit: 60000
random_seed: 42
truncate_input_tokens: 8191
decoding_method: sample
repetition_penalty: 1.1
temperature: "{{ temperature }}"
temperature: "${ temperature }"
stop_sequences: ["[", "\n"]
include_stop_sequence: false
- defs:
ACTION: "{{ action_raw|trim }}"
ACTION: "${ action_raw|trim }"
- "["
- def: SUBJECT
model: "{{ model }}"
model: "${ model }"
parameters:
time_limit: 60000
random_seed: 42
truncate_input_tokens: 8191
decoding_method: sample
repetition_penalty: 1.1
temperature: "{{ temperature }}"
temperature: "${ temperature }"
stop_sequences: ["]", "\n"]
include_stop_sequence: false
- "]"
- if: "{{ ACTION != 'Finish' }}"
- if: "${ ACTION != 'Finish' }"
then:
- "\nObs: "
- if: "{{ ACTION in TOOL_INFO.display_names }}"
- if: "${ ACTION in TOOL_INFO.display_names }"
then:
- call: "{{ TOOL_INFO.name_map[ACTION] }}"
- call: "${ TOOL_INFO.name_map[ACTION] }"
args:
subject: "{{ SUBJECT }}"
subject: "${ SUBJECT }"
- "\nTho:"
- model: "{{ model }}"
- model: "${ model }"
fallback: "Error calling model"
parameters:
time_limit: 60000
random_seed: 42
truncate_input_tokens: 8191
repetition_penalty: 1.1
decoding_method: sample
temperature: "{{ temperature }}"
temperature: "${ temperature }"
stop_sequences: ["\n", "Act:", "Obs:", "Tho:"]
include_stop_sequence: false
else: "Invalid action. Valid actions are {{ TOOL_INFO.signatures[:-1]|join(', ') }}, and {{ TOOL_INFO.signatures[-1] }}."
until: "{{ ACTION == 'Finish' or iterations>20 }}"
else: "Invalid action. Valid actions are ${ TOOL_INFO.signatures[:-1]|join(', ') }, and ${ TOOL_INFO.signatures[-1] }."
until: "${ ACTION == 'Finish' or iterations>20 }"
- data:
answer: "{{ SUBJECT|trim }}"
answer: "${ SUBJECT|trim }"

react_json:
function:
Expand All @@ -165,65 +165,65 @@ defs:
TOOL_INFO:
call: list_tools
args:
tools: "{{ tools.append(finish_action) or tools }}"
tools: "${ tools.append(finish_action) or tools }"
- "Available tools:\n" # The preprompt!
- for:
name: "{{ TOOL_INFO.display_names }}"
sig: "{{ TOOL_INFO.signatures }}"
desc: "{{ TOOL_INFO.descriptions }}"
name: "${ TOOL_INFO.display_names }"
sig: "${ TOOL_INFO.signatures }"
desc: "${ TOOL_INFO.descriptions }"
repeat: |
{{ name }}: {{ desc }}
${ name }: ${ desc }
- "\n"
- call: demonstrate_tools
args:
tools: "{{ tools }}"
tools: "${ tools }"
- for:
traj: "{{ trajectories }}"
traj: "${ trajectories }"
repeat:
call: react_block
args:
trajectory: "{{ traj }}"
- "{{ task }}\nTho:"
trajectory: "${ traj }"
- "${ task }\nTho:"
- defs:
temperature: 0.05
decoding_method: greedy
iterations: 0
repeat:
- repeat:
- defs:
iterations: "{{ iterations+1 }}"
iterations: "${ iterations+1 }"
- def: THOUGHT
model: "{{ model }}"
model: "${ model }"
parameters:
decoding_method: "{{ decoding_method }}"
temperature: "{{ temperature }}"
decoding_method: "${ decoding_method }"
temperature: "${ temperature }"
stop_sequences: ["\n", "Act:", "Obs:", "Tho:"]
include_stop_sequence: true
until: "{{ THOUGHT.endswith('Act:') or iterations>20 }}"
until: "${ THOUGHT.endswith('Act:') or iterations>20 }"
- def: action
model: "{{ model }}"
model: "${ model }"
parser: json
spec: {name: str, arguments: obj}
parameters:
decoding_method: "{{ decoding_method }}"
temperature: "{{ temperature }}"
decoding_method: "${ decoding_method }"
temperature: "${ temperature }"
stop_sequences: ["\n", "<|endoftext|>"]
include_stop_sequence: false
- if: "{{ action.name != 'Finish' }}"
- if: "${ action.name != 'Finish' }"
then:
- "\nObs: "
- if: "{{ action.name in TOOL_INFO.display_names }}"
- if: "${ action.name in TOOL_INFO.display_names }"
then:
- call: "{{ TOOL_INFO.name_map[action.name] }}"
- call: "${ TOOL_INFO.name_map[action.name] }"
args:
arguments: "{{ action.arguments }}"
- model: "{{ model }}"
arguments: "${ action.arguments }"
- model: "${ model }"
parameters:
decoding_method: "{{ decoding_method }}"
temperature: "{{ temperature }}"
decoding_method: "${ decoding_method }"
temperature: "${ temperature }"
stop_sequences: ["\n", "Act:", "Obs:", "Tho:"]
include_stop_sequence: false
else: "Invalid action. Valid actions are {{ TOOL_INFO.signatures|join(', ') }} and Finish[<answer>]."
until: "{{ action.name == 'Finish' or iterations>20 }}"
else: "Invalid action. Valid actions are ${ TOOL_INFO.signatures|join(', ') } and Finish[<answer>]."
until: "${ action.name == 'Finish' or iterations>20 }"
- data:
answer: "{{ action.arguments }}"
answer: "${ action.arguments }"
Loading

0 comments on commit 5921b9f

Please sign in to comment.