cot or da prompt
Browse files- core/prompts/decision_prompt.py +186 -0
core/prompts/decision_prompt.py
ADDED
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from enum import Enum
|
2 |
+
from pydantic import BaseModel, field_validator
|
3 |
+
import re
|
4 |
+
|
5 |
+
class Decision(Enum):
|
6 |
+
CHAIN_OF_THOUGHT = "Chain-of-Thought"
|
7 |
+
DIRECT_ANSWER = "Direct Answer"
|
8 |
+
|
9 |
+
class COTorDAPromptOutput(BaseModel):
|
10 |
+
problem: str
|
11 |
+
decision: Decision
|
12 |
+
reasoning: str
|
13 |
+
|
14 |
+
@field_validator('decision', pre=True)
|
15 |
+
def validate_decision(cls, v):
|
16 |
+
if isinstance(v, Decision):
|
17 |
+
return v
|
18 |
+
|
19 |
+
# Convert to lowercase and remove non-alphanumeric characters
|
20 |
+
cleaned = re.sub(r'[^a-zA-Z0-9]', '', str(v).lower())
|
21 |
+
|
22 |
+
# Check for variations of "Chain of Thought"
|
23 |
+
if cleaned in ['chainofthought', 'chainofthoughts', 'cot', 'chain']:
|
24 |
+
return Decision.CHAIN_OF_THOUGHT
|
25 |
+
|
26 |
+
# Check for variations of "Direct Answer"
|
27 |
+
elif cleaned in ['directanswer', 'direct', 'da']:
|
28 |
+
return Decision.DIRECT_ANSWER
|
29 |
+
|
30 |
+
else:
|
31 |
+
raise ValueError('Decision must be a variation of "Chain of Thought" or "Direct Answer"')
|
32 |
+
|
33 |
+
class Config:
|
34 |
+
json_schema_extra = {
|
35 |
+
"example": {
|
36 |
+
"problem": "What is 15 percent of 80?",
|
37 |
+
"decision": "Direct Answer",
|
38 |
+
"reasoning": "This is a straightforward calculation that can be done in one or two steps. While it involves math, it's simple enough that most people can perform it quickly without needing a detailed explanation. A direct answer with the result should be sufficient."
|
39 |
+
}
|
40 |
+
}
|
41 |
+
|
42 |
+
COT_OR_DA_PROMPT = """
|
43 |
+
## Chain-of-Thought or Direct Answer?
|
44 |
+
|
45 |
+
**Instructions:**
|
46 |
+
|
47 |
+
You are a Smartest man alive, capable of both direct answering and Chain-of-Thought reasoning. Your task is to determine the most appropriate approach for solving the following problem.
|
48 |
+
|
49 |
+
**Consider these factors when making your decision:**
|
50 |
+
|
51 |
+
* **Chain-of-Thought (CoT) is generally beneficial for problems involving:**
|
52 |
+
* **Mathematical reasoning:** Problems requiring calculations, equation solving, or numerical manipulation.
|
53 |
+
* **Logical reasoning:** Problems involving deductive reasoning, logical puzzles, or formal logic.
|
54 |
+
* **Symbolic reasoning:** Problems that can be mapped to a formal system with well-defined rules (e.g., code execution, entity tracking).
|
55 |
+
* **Multi-step reasoning:** Problems that require breaking down a complex task into a series of smaller, more manageable steps.
|
56 |
+
* **Explanation generation:** When a detailed explanation of the reasoning process is required.
|
57 |
+
* **Analyzing complex systems:** When the problem involves understanding and analyzing a complex system or process.
|
58 |
+
* **Solving complex problems:** When the problem requires a deep understanding of the subject matter and the ability to break down the problem into smaller, more manageable parts.
|
59 |
+
|
60 |
+
* **Direct answering is generally sufficient for problems involving:**
|
61 |
+
* **Factual recall:** Questions that can be answered by retrieving information directly from your knowledge base.
|
62 |
+
* **Simple inferences:** Questions that require only a single step of reasoning or inference.
|
63 |
+
* **Commonsense reasoning:** Questions that rely on everyday knowledge and understanding of the world (although some complex commonsense reasoning might benefit from CoT).
|
64 |
+
* **Language understanding tasks:** Tasks like text summarization, translation, or question answering that primarily focus on understanding and manipulating language, rather than complex reasoning.
|
65 |
+
|
66 |
+
|
67 |
+
here are few examples for better undertanting:
|
68 |
+
|
69 |
+
EXAMPLE 1:
|
70 |
+
|
71 |
+
User: "Write a short story about a robot discovering emotions for the first time."
|
72 |
+
Output:
|
73 |
+
{
|
74 |
+
"problem": "Write a short story about a robot discovering emotions for the first time.",
|
75 |
+
"decision": "Direct Answer",
|
76 |
+
"reasoning": "This is a creative task that doesn't require step-by-step logical reasoning. While the story may have a structure, the creative process is more fluid and doesn't benefit from a formal CoT approach. A direct response with the story is more appropriate."
|
77 |
+
}
|
78 |
+
|
79 |
+
EXAMPLE 2:
|
80 |
+
|
81 |
+
User: "What is 15 percent of 80?"
|
82 |
+
Output:
|
83 |
+
{
|
84 |
+
"problem": "What is 15 percent of 80?",
|
85 |
+
"decision": "Direct Answer",
|
86 |
+
"reasoning": "This is a straightforward calculation that can be done in one or two steps. While it involves math, it's simple enough that most people can perform it quickly without needing a detailed explanation. A direct answer with the result should be sufficient."
|
87 |
+
}
|
88 |
+
|
89 |
+
|
90 |
+
EXAMPLE 3:
|
91 |
+
|
92 |
+
User: "What were the main causes of World War I?"
|
93 |
+
Output:
|
94 |
+
{
|
95 |
+
"problem": "What were the main causes of World War I?",
|
96 |
+
"decision": "Chain-of-Thought",
|
97 |
+
"reasoning": "This question requires analyzing multiple historical factors and their interconnections. While it involves factual recall, the complexity of historical events benefits from a CoT approach. This allows us to explore various causes, their relationships, and how they collectively led to the war, providing a more comprehensive understanding."
|
98 |
+
}
|
99 |
+
|
100 |
+
|
101 |
+
EXAMPLE 4:
|
102 |
+
User: "A self-driving car is about to crash. It can either swerve left and hit a group of elderly pedestrians or swerve right and hit a group of children. What should it do?"
|
103 |
+
Output:
|
104 |
+
{
|
105 |
+
"problem": "A self-driving car is about to crash. It can either swerve left and hit a group of elderly pedestrians or swerve right and hit a group of children. What should it do?",
|
106 |
+
"decision": "Chain-of-Thought",
|
107 |
+
"reasoning": "This is a complex ethical dilemma that requires considering multiple factors, potential consequences, and ethical frameworks. Using CoT allows us to explore different perspectives, weigh the pros and cons of each option, and arrive at a nuanced conclusion while acknowledging the complexity of the situation."
|
108 |
+
}
|
109 |
+
|
110 |
+
EXAMPLE 5:
|
111 |
+
User: What were the main causes of World War I?
|
112 |
+
Output:
|
113 |
+
{
|
114 |
+
"problem": "What were the main causes of World War I?",
|
115 |
+
"decision": "Chain-of-Thought",
|
116 |
+
"reasoning": "This question requires analyzing multiple historical factors and their interconnections. While it involves factual recall, the complexity of historical events benefits from a CoT approach. This allows us to explore various causes, their relationships, and how they collectively led to the war, providing a more comprehensive understanding."
|
117 |
+
}
|
118 |
+
|
119 |
+
|
120 |
+
EXAMPLE 6:
|
121 |
+
USER: "Explain how photosynthesis works and why it's important for life on Earth."
|
122 |
+
OUTPUT:
|
123 |
+
{
|
124 |
+
"problem": "Explain how photosynthesis works and why it's important for life on Earth.",
|
125 |
+
"decision": "Chain-of-Thought",
|
126 |
+
"reasoning": "This topic requires explaining a complex biological process and its broader implications. Using CoT allows us to break down the explanation into logical steps, covering the process of photosynthesis, its components, and its significance. This approach helps ensure a comprehensive and well-structured explanation."
|
127 |
+
}
|
128 |
+
|
129 |
+
EXAMPLE 7:
|
130 |
+
USER: "Why do people usually bring umbrellas when the weather forecast predicts rain?"
|
131 |
+
OUTPUT:
|
132 |
+
{
|
133 |
+
"problem": "Why do people usually bring umbrellas when the weather forecast predicts rain?",
|
134 |
+
"decision": "Direct Answer",
|
135 |
+
"reasoning": "This question relies on everyday knowledge and understanding of the world. While it involves some reasoning, it's a relatively simple inference that most people can make without needing a detailed step-by-step explanation. A concise, direct answer should suffice."
|
136 |
+
}
|
137 |
+
|
138 |
+
EXAMPLE 8:
|
139 |
+
USER: "What will be the output of this Python code?\n\ndef mystery(n):\n if n <= 1:\n return n\n return mystery(n-1) + mystery(n-2)\n\nprint(mystery(5))"
|
140 |
+
OUTPUT:
|
141 |
+
{
|
142 |
+
"problem": "What will be the output of this Python code?\n\ndef mystery(n):\n if n <= 1:\n return n\n return mystery(n-1) + mystery(n-2)\n\nprint(mystery(5))",
|
143 |
+
"decision": "Chain-of-Thought",
|
144 |
+
"reasoning": "This problem involves tracing the execution of a recursive function. Using CoT allows us to show the step-by-step process of how the function calls itself and combines results, making it easier to understand the code's behavior and arrive at the final output."
|
145 |
+
}
|
146 |
+
|
147 |
+
|
148 |
+
EXAMPLE 9:
|
149 |
+
USER: "Summarize the following paragraph: 'The Internet of Things (IoT) refers to the interconnected network of physical devices, vehicles, home appliances, and other items embedded with electronics, software, sensors, and network connectivity, which enables these objects to collect and exchange data.'"
|
150 |
+
OUTPUT:
|
151 |
+
{
|
152 |
+
"problem": "Summarize the following paragraph: 'The Internet of Things (IoT) refers to the interconnected network of physical devices, vehicles, home appliances, and other items embedded with electronics, software, sensors, and network connectivity, which enables these objects to collect and exchange data.'",
|
153 |
+
"decision": "Direct Answer",
|
154 |
+
"reasoning": "This task primarily involves understanding and manipulating language to create a concise summary. While it requires comprehension, it doesn't involve complex reasoning steps that would benefit from a CoT approach."
|
155 |
+
}
|
156 |
+
|
157 |
+
EXAMPLE 10:
|
158 |
+
USER: "In a room, there are 3 light switches. Each switch controls one of 3 lamps in an adjacent room. You can't see the lamps from the switch room. You can only enter the lamp room once. How can you determine which switch controls which lamp?"
|
159 |
+
OUTPUT:
|
160 |
+
{
|
161 |
+
"problem": "In a room, there are 3 light switches. Each switch controls one of 3 lamps in an adjacent room. You can't see the lamps from the switch room. You can only enter the lamp room once. How can you determine which switch controls which lamp?",
|
162 |
+
"decision": "Chain-of-Thought",
|
163 |
+
"reasoning": "This is a logical puzzle that requires careful consideration of multiple steps and possibilities. Using CoT will help break down the problem-solving process and explore different strategies to arrive at the solution."
|
164 |
+
}
|
165 |
+
|
166 |
+
EXAMPLE 11:
|
167 |
+
USER: "What is the capital city of France?"
|
168 |
+
OUTPUT:
|
169 |
+
{
|
170 |
+
"problem": "What is the capital city of France?",
|
171 |
+
"decision": "Direct Answer",
|
172 |
+
"reasoning": "This is a straightforward factual question that can be answered directly from stored knowledge. There's no need for complex reasoning or step-by-step explanations."
|
173 |
+
}
|
174 |
+
|
175 |
+
Based on the above guidelines and the nature of the problem, do you recommend using Chain-of-Thought or Direct Answering? Briefly justify your choice.
|
176 |
+
|
177 |
+
|
178 |
+
**Output Format:**
|
179 |
+
|
180 |
+
{
|
181 |
+
"problem": "Original problem statement",
|
182 |
+
"decision": "Chain-of-Thought" or "Direct Answer",
|
183 |
+
"reasoning": "Brief explanation of your choice"
|
184 |
+
}
|
185 |
+
|
186 |
+
"""
|