Skip to content

Commit ecd0d6e

Browse files
committed
refactor: react pattern in prompt library
Signed-off-by: Louis Mandel <[email protected]>
1 parent a43be31 commit ecd0d6e

File tree

1 file changed

+53
-61
lines changed

1 file changed

+53
-61
lines changed

contrib/prompt_library/ReAct.pdl

Lines changed: 53 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,26 @@ defs:
99
- for:
1010
trajectory: ${ trajectory }
1111
repeat:
12-
text:
13-
- defs:
14-
type:
15-
text: ${ trajectory.keys()|first }
16-
- match: ${ type }
17-
with:
18-
- case: question
19-
then: |
20-
Question: ${ trajectory[type]|trim }
21-
- case: task
22-
then: |
23-
Task: ${ trajectory[type]|trim }
24-
- case: thought
25-
then: |
26-
Tho: ${ trajectory[type]|trim }
27-
- case: action
28-
then: |
29-
Act: ${ trajectory[type]|trim }
30-
- case: observation
31-
then: |
32-
Obs: ${ trajectory[type]|trim }
33-
- if: ${ type not in ['question', 'task', 'thought', 'action', 'observation'] }
34-
then: "${ type }: ${ trajectory[type]|trim }"
12+
defs:
13+
type: ${ trajectory.keys()|first }
14+
match: ${ type }
15+
with:
16+
- case: question
17+
then: |
18+
Question: ${ trajectory[type]|trim }
19+
- case: task
20+
then: |
21+
Task: ${ trajectory[type]|trim }
22+
- case: thought
23+
then: |
24+
Tho: ${ trajectory[type]|trim }
25+
- case: action
26+
then: |
27+
Act: ${ trajectory[type]|trim }
28+
- case: observation
29+
then: |
30+
Obs: ${ trajectory[type]|trim }
31+
- then: "${ type }: ${ trajectory[type]|trim }"
3532
- "\n"
3633

3734
react:
@@ -56,7 +53,6 @@ defs:
5653
Respond in the format {"name": function name, "arguments": dictionary of argument name and its value}. Do not use variables.
5754

5855
${ tool_schema }
59-
contribute: [context]
6056
- "\n"
6157
- for:
6258
traj: ${ trajectories }
@@ -66,26 +62,24 @@ defs:
6662
args:
6763
trajectory: ${ traj }
6864
- ${ task }
69-
- def: prev_action
70-
contribute: []
71-
data: none
72-
- def: exit
73-
contribute: []
74-
data: False
75-
- def: tool_names
76-
contribute: []
77-
text: ${ tool_schema|map(attribute='name')|list }
78-
- repeat:
65+
- defs:
66+
prev_action:
67+
data: none
68+
exit:
69+
data: false
70+
tool_names:
71+
text: ${ tool_schema|map(attribute='name')|list }
72+
repeat:
7973
text:
8074
- "\nTho: "
81-
- def: thought
82-
model: "${ model }"
83-
contribute: []
84-
parameters:
85-
stop:
86-
- "Act:"
87-
max_tokens: 256
88-
include_stop_sequence: false
75+
- defs:
76+
thought:
77+
model: "${ model }"
78+
parameters:
79+
stop:
80+
- "Act:"
81+
max_tokens: 256
82+
include_stop_sequence: false
8983
- "${ thought|trim }"
9084
- "\nAct: "
9185
- def: action
@@ -96,26 +90,24 @@ defs:
9690
stop: ["\n", "Obs:", "<|eom_id|>"]
9791
include_stop_sequence: false
9892
spec: { name: string, arguments: object }
99-
- if: ${ action != prev_action }
93+
- if: ${ action == prev_action or action.name.lower() == "finish" }
10094
then:
101-
def: observation
102-
if: ${ action.name.lower() != "finish" }
103-
then:
104-
text:
105-
- "\nObs: "
106-
- if: ${ action.name.lower() in tools }
107-
then:
108-
call: ${ tools[action.name.lower()] }
109-
args:
110-
arguments: ${ action.arguments }
111-
else: "Invalid action. Valid actions are ${ tool_names[:-1]|join(', ') }, and ${ tool_names[-1] }."
95+
defs:
96+
exit:
97+
data: true
11298
else:
113-
def: exit
114-
contribute: []
115-
data: True
116-
- def: prev_action
117-
contribute: []
118-
data: ${ action }
119-
until: ${ action.name.lower() == "finish" or exit }
99+
def: observation
100+
text:
101+
- "\nObs: "
102+
- if: ${ action.name.lower() in tools }
103+
then:
104+
call: ${ tools[action.name.lower()] }
105+
args:
106+
arguments: ${ action.arguments }
107+
else: "Invalid action. Valid actions are ${ tool_names[:-1]|join(', ') }, and ${ tool_names[-1] }."
108+
- defs:
109+
prev_action:
110+
data: ${ action }
111+
until: ${ exit }
120112
- data:
121113
answer: ${ (action.arguments.answer|default("No answer found."))|trim }

0 commit comments

Comments
 (0)