Skip to content

Commit ae96a00

Browse files
committed
Finish prompt lib docs
Signed-off-by: Claudio Spiess <[email protected]>
1 parent f29cc4a commit ae96a00

File tree

12 files changed

+506
-786
lines changed

12 files changed

+506
-786
lines changed

contrib/prompt_library/CoT.pdl

+29-100
Original file line numberDiff line numberDiff line change
@@ -11,47 +11,24 @@ defs:
1111
Answer: Let's think step by step. ${ reasoning }
1212
The answer is ${ answer }
1313

14-
# Auto Chain of Thought Zhang et al. (2022)
15-
# The idea is to use a _model_ to generate a reasoning path, even if not very accurate.
16-
# It is best combined with some fewshot examples
17-
auto_chain_of_thought:
18-
function:
19-
question: str
20-
model: str
21-
answer: str
22-
return:
23-
text:
24-
- |-
25-
Question: ${ question }
26-
- "Answer: Let's think step by step. "
27-
- model: ${ model }
28-
parameters:
29-
# decoding_method: "greedy"
30-
max_tokens: 1024
31-
temperature: 0
32-
stop:
33-
- "The answer is"
34-
include_stop_sequence: false
35-
- "The answer is ${ answer }"
36-
3714
fewshot_cot:
3815
function:
3916
examples:
4017
{ list: { obj: { question: str, reasoning: str, answer: str } } }
4118
return:
4219
text:
43-
- for:
44-
example: ${ examples }
45-
repeat:
46-
text:
47-
- call: ${ cot_block }
48-
args:
49-
question: ${ example.question }
50-
reasoning: ${ example.reasoning }
51-
answer: ${ example.answer }
52-
- "\n\n"
53-
join:
54-
with: ""
20+
- for:
21+
example: ${ examples }
22+
repeat:
23+
text:
24+
- call: ${ cot_block }
25+
args:
26+
question: ${ example.question }
27+
reasoning: ${ example.reasoning }
28+
answer: ${ example.answer }
29+
- "\n\n"
30+
join:
31+
with: ""
5532

5633
chain_of_thought:
5734
function:
@@ -60,68 +37,20 @@ defs:
6037
examples:
6138
{ list: { obj: { question: str, reasoning: str, answer: str } } }
6239
return:
63-
text:
64-
- call: ${ fewshot_cot }
65-
args:
66-
examples: ${ examples }
67-
- "Question: ${ question }\n"
68-
- "Answer: Let's think step by step. "
69-
- model: ${ model }
70-
parameters:
71-
max_tokens: 1024
72-
temperature: 0
73-
stop:
74-
- "<|endoftext|>"
75-
- "Question:"
76-
include_stop_sequence: false
77-
78-
claim_cot:
79-
function:
80-
question: str
81-
reasoning: str
82-
answer: str
83-
return: |-
84-
Task: On June 2017, the following claim was made: ${ question }
85-
Q: Was this claim true or false?
86-
Thought: Let's think step by step. ${ reasoning|trim }
87-
Answer: The claim is ${ answer }
88-
89-
fewshot_cot_claim:
90-
function:
91-
examples:
92-
{ list: { obj: { question: str, reasoning: str, answer: str } } }
93-
return:
94-
text:
95-
- for:
96-
example: ${ examples }
97-
repeat:
98-
text:
99-
- call: ${ claim_cot }
100-
args:
101-
question: ${ example.question }
102-
reasoning: ${ example.reasoning }
103-
answer: ${ example.answer }
104-
- "\n\n"
105-
join:
106-
with: ""
107-
108-
chain_of_thought_claim:
109-
function:
110-
question: str
111-
model: str
112-
examples:
113-
{ list: { obj: { question: str, reasoning: str, answer: str } } }
114-
return:
115-
text:
116-
- call: ${ fewshot_cot_claim }
117-
args:
118-
examples: ${ examples }
119-
- "${ question }\n"
120-
- "Thought: Let's think step by step. "
121-
- model: ${ model }
122-
parameters:
123-
temperature: 0
124-
stop:
125-
- "<|endoftext|>"
126-
max_tokens: 1024
127-
include_stop_sequence: false
40+
lastOf:
41+
- call: ${ fewshot_cot }
42+
args:
43+
examples: ${ examples }
44+
- "Question: ${ question }\n"
45+
- "Answer: Let's think step by step. "
46+
- model: ${ model }
47+
def: answer
48+
parameters:
49+
max_tokens: 1024
50+
temperature: 0
51+
stop:
52+
- "<|endoftext|>"
53+
- "Question:"
54+
include_stop_sequence: false
55+
- data:
56+
answer: ${ answer|trim }

contrib/prompt_library/ReAct.pdl

+25-123
Original file line numberDiff line numberDiff line change
@@ -32,132 +32,29 @@ defs:
3232
then: "${ type }: ${ trajectory[type]|trim }"
3333
- "\n"
3434

35-
react_code_block:
36-
function:
37-
trajectory: { list: obj }
38-
return:
39-
text:
40-
- for:
41-
trajectory: ${ trajectory }
42-
repeat:
43-
text:
44-
- def: type
45-
text: ${ trajectory.keys()|first }
46-
contribute: []
47-
- if: ${ type == 'task'}
48-
then: |
49-
Task:
50-
${ trajectory[type]|trim }
51-
- if: ${ type == 'thought'}
52-
then:
53-
text:
54-
- "\n"
55-
- |
56-
Assistant:
57-
<thought>${ trajectory[type]|trim }</thought>
58-
- if: ${ type == 'action'}
59-
then: |
60-
<execute>
61-
${ trajectory[type]|trim }
62-
</execute>
63-
- if: ${ type == 'observation'}
64-
then:
65-
text:
66-
- "\n"
67-
- |
68-
Observation:
69-
${ trajectory[type]|trim }
70-
- if: ${ type == 'solution'}
71-
then: |-
72-
<solution>
73-
${ trajectory[type]|trim }
74-
</solution>
75-
- if: ${ type not in ['question', 'task', 'thought', 'action', 'observation', 'solution'] }
76-
then: "${ type }: ${ trajectory[type]|trim }"
77-
- "\n"
78-
79-
finish_action:
80-
data:
81-
display_name: Finish
82-
pdl_function:
83-
description: Respond with the Answer
84-
parameters:
85-
- name: answer
86-
type: string
87-
description: The answer
88-
examples: []
89-
90-
demonstrate_tools:
91-
function:
92-
tools: { list: obj }
93-
return:
94-
for:
95-
tool: ${ tools }
96-
repeat:
97-
for:
98-
example: ${ tool.examples }
99-
repeat:
100-
call: ${ react_block }
101-
args:
102-
trajectory: ${ example }
103-
10435
react:
10536
function:
10637
task: str
10738
model: str
108-
tools: { list: obj }
39+
tool_schema: { list: obj }
40+
tools: obj
10941
trajectories: { list: list }
110-
system_prompt: str
11142
return:
11243
lastOf:
113-
- if: ${ system_prompt == "llama3"}
114-
then:
115-
text:
116-
- role: system
117-
contribute: [context]
118-
text:
119-
- "Cutting Knowledge Date: December 2023\nToday Date: "
120-
- lang: python
121-
code: |
122-
from datetime import datetime
123-
result = datetime.today().strftime('%d %B %Y\n\n')
124-
- role: system
125-
text: You are a helpful assistant with tool calling capabilities. When you receive a tool call response, use the output to format an answer to the orginal use question.
126-
contribute: [context]
127-
- role: user
128-
text: |
129-
Given the following functions, please respond with a JSON for a function call with its proper arguments that best answers the given prompt.
130-
131-
Respond in the format {"name": function name, "arguments": dictionary of argument name and its value}. Do not use variables.
132-
133-
${ tools }
134-
contribute: [context]
135-
- if: ${ system_prompt == "granite_llama" }
136-
then:
137-
text:
138-
- role: system
139-
text: |
140-
You are a helpful assistant with access to the following function calls. Your task is to produce a sequence of function calls necessary to generate response to the user utterance. Use the following function calls as required.
44+
- role: system
45+
text:
46+
- "Today's Date: "
47+
- lang: python
48+
code: |
49+
from datetime import datetime
50+
result = datetime.today().strftime('%B %d, %Y.\n')
51+
- |
52+
You are a helpful assistant with access to the following function calls. Your task is to produce a sequence of function calls necessary to generate response to the user utterance. Use the following function calls as required.
14153

142-
Respond in the format {"name": function name, "arguments": dictionary of argument name and its value}. Do not use variables.
54+
Respond in the format {"name": function name, "arguments": dictionary of argument name and its value}. Do not use variables.
14355

144-
${ tools }
145-
contribute: [context]
146-
- if: ${ system_prompt == "granite_tools" }
147-
then:
148-
text:
149-
- role: system
150-
contribute: [context]
151-
text:
152-
- "Knowledge Cutoff Date: April 2024.\nToday's Date: "
153-
- lang: python
154-
code: |
155-
from datetime import datetime
156-
result = datetime.today().strftime('%B %d, %Y.\n')
157-
- |
158-
You are Granite, developed by IBM. You are a helpful AI assistant with access to the following tools. When a tool is required to answer the user's query, respond with a JSON object of the tool to use. If a tool does not exist in the provided list of tools, notify the user that you do not have the ability to fulfill the request.
159-
160-
${ tools }
56+
${ tool_schema }
57+
contribute: [context]
16158
- "\n"
16259
- for:
16360
traj: ${ trajectories }
@@ -173,16 +70,21 @@ defs:
17370
- def: exit
17471
contribute: []
17572
data: False
73+
- def: tool_names
74+
contribute: []
75+
text: ${ tool_schema|map(attribute='function.name')|list }
17676
- repeat:
17777
text:
17878
- "\nTho: "
17979
- def: thought
18080
model: "${ model }"
81+
contribute: []
18182
parameters:
18283
stop:
18384
- "Act:"
18485
max_tokens: 256
18586
include_stop_sequence: false
87+
- "${ thought|trim }"
18688
- "\nAct: "
18789
- def: action
18890
model: "${ model }"
@@ -195,17 +97,17 @@ defs:
19597
- if: ${ action != prev_action }
19698
then:
19799
def: observation
198-
if: ${ action.name.lower() != 'finish' }
100+
if: ${ action.name.lower() != "finish" }
199101
then:
200102
text:
201103
- "\nObs: "
202-
- if: ${ action.name.lower() in pdl_tools }
104+
- if: ${ action.name in tools }
203105
then:
204-
call: ${ pdl_tools[action.name.lower()] }
106+
call: ${ tools[action.name] }
205107
args:
206108
arguments: ${ action.arguments }
207-
else: "Invalid action. Valid actions are ${ (pdl_tools.keys()|list)[:-1]|join(', ') }, and ${ (pdl_tools.keys()|list)[-1] }."
208-
- "\n"
109+
else: "Invalid action. Valid actions are ${ tool_names[:-1]|join(', ') }, and ${ tool_names[-1] }."
110+
# - "\n"
209111
else:
210112
def: exit
211113
contribute: []
@@ -215,4 +117,4 @@ defs:
215117
data: ${ action }
216118
until: ${ action.name.lower() == "finish" or exit }
217119
- data:
218-
answer: ${ (action.arguments.answer|default("No answer found."))|trim } # Factor 5: answer argument name. some models really like putting answer in.
120+
answer: ${ (action.arguments.answer|default("No answer found."))|trim }

0 commit comments

Comments
 (0)