Spaces:
Sleeping
Sleeping
Update core/prompt_generation_agent.py
Browse files- core/prompt_generation_agent.py +21 -21
core/prompt_generation_agent.py
CHANGED
|
@@ -11,47 +11,47 @@ class PromptGenerationAgent:
|
|
| 11 |
# Template patterns for different techniques
|
| 12 |
self.technique_templates = {
|
| 13 |
"zero_shot": {
|
| 14 |
-
"template": "{
|
| 15 |
-
"instruction": "
|
| 16 |
},
|
| 17 |
"few_shot": {
|
| 18 |
-
"template": "
|
| 19 |
-
"instruction": "
|
| 20 |
-
"examples": "Example 1: [Input] -> [Output]\nExample 2: [Input] -> [Output]"
|
| 21 |
},
|
| 22 |
"chain_of_thought": {
|
| 23 |
-
"template": "
|
| 24 |
-
"instruction": "
|
| 25 |
},
|
| 26 |
"react": {
|
| 27 |
-
"template": "
|
| 28 |
-
"instruction": "
|
| 29 |
},
|
| 30 |
"tree_of_thoughts": {
|
| 31 |
-
"template": "
|
| 32 |
-
"instruction": "
|
| 33 |
},
|
| 34 |
"self_consistency": {
|
| 35 |
-
"template": "
|
| 36 |
-
"instruction": "
|
| 37 |
},
|
| 38 |
"generated_knowledge": {
|
| 39 |
-
"template": "
|
| 40 |
-
"instruction": "
|
| 41 |
},
|
| 42 |
"prompt_chaining": {
|
| 43 |
-
"template": "
|
| 44 |
-
"instruction": "
|
| 45 |
},
|
| 46 |
"meta_prompting": {
|
| 47 |
-
"template": "
|
| 48 |
-
"instruction": "
|
| 49 |
},
|
| 50 |
"pal": {
|
| 51 |
-
"template": "
|
| 52 |
-
"instruction": "
|
| 53 |
}
|
| 54 |
}
|
|
|
|
| 55 |
|
| 56 |
def generate_prompt(self, user_prompt: str, technique_key: str,
|
| 57 |
analysis_result: Dict[str, Any]) -> Dict[str, Any]:
|
|
|
|
| 11 |
# Template patterns for different techniques
|
| 12 |
self.technique_templates = {
|
| 13 |
"zero_shot": {
|
| 14 |
+
"template": "{user_prompt}",
|
| 15 |
+
"instruction": ""
|
| 16 |
},
|
| 17 |
"few_shot": {
|
| 18 |
+
"template": "Study the following examples and apply the same pattern.\n\n{examples}\n\nNow complete this:\n{user_prompt}",
|
| 19 |
+
"instruction": ""
|
|
|
|
| 20 |
},
|
| 21 |
"chain_of_thought": {
|
| 22 |
+
"template": "You're a helpful assistant. Answer the following by reasoning step by step:\n\nQ: {user_prompt}\n\nA:\nLet's think it through:\n1.",
|
| 23 |
+
"instruction": ""
|
| 24 |
},
|
| 25 |
"react": {
|
| 26 |
+
"template": "You're a reasoning agent who can both think and act using tools. Follow the ReAct format.\n\nTask: {user_prompt}\n\nThought: Let's analyze the problem.\nAction: [what action to take]\nObservation: [result of action]\nThought: [next reasoning step]",
|
| 27 |
+
"instruction": ""
|
| 28 |
},
|
| 29 |
"tree_of_thoughts": {
|
| 30 |
+
"template": "Let's explore several possible strategies to solve this task:\n\nProblem: {user_prompt}\n\nApproach 1:\n- ...\n\nApproach 2:\n- ...\n\nApproach 3:\n- ...\n\nNow compare the approaches and choose the best one.",
|
| 31 |
+
"instruction": ""
|
| 32 |
},
|
| 33 |
"self_consistency": {
|
| 34 |
+
"template": "Answer the following using three independent reasoning paths. Then choose the most consistent answer.\n\nPrompt: {user_prompt}\n\nPath 1:\n...\n\nPath 2:\n...\n\nPath 3:\n...\n\nFinal Answer:",
|
| 35 |
+
"instruction": ""
|
| 36 |
},
|
| 37 |
"generated_knowledge": {
|
| 38 |
+
"template": "Before answering, first generate helpful background knowledge. Then use it to respond.\n\nPrompt: {user_prompt}\n\nRelevant Knowledge:\n...\n\nAnswer:",
|
| 39 |
+
"instruction": ""
|
| 40 |
},
|
| 41 |
"prompt_chaining": {
|
| 42 |
+
"template": "Break the task below into logical steps and solve each one. Then combine the results.\n\nPrompt: {user_prompt}\n\nStep 1:\nSubtask: ...\nResult: ...\n\nStep 2:\nSubtask: ...\nResult: ...\n\nFinal Answer:",
|
| 43 |
+
"instruction": ""
|
| 44 |
},
|
| 45 |
"meta_prompting": {
|
| 46 |
+
"template": "Analyze the prompt structure and respond in a format that matches its intent.\n\nPrompt: {user_prompt}\n\nStructure Analysis:\n- Pattern:\n- Format:\n- Constraints:\n\nResponse:",
|
| 47 |
+
"instruction": ""
|
| 48 |
},
|
| 49 |
"pal": {
|
| 50 |
+
"template": "Write Python code to solve the following problem. Explain the logic as comments.\n\nTask: {user_prompt}\n\n```python\n# Step 1:\n# ...\n\n# Step 2:\n# ...\n\n# Final step:\nprint(...)\n```\n\nAnswer:",
|
| 51 |
+
"instruction": ""
|
| 52 |
}
|
| 53 |
}
|
| 54 |
+
|
| 55 |
|
| 56 |
def generate_prompt(self, user_prompt: str, technique_key: str,
|
| 57 |
analysis_result: Dict[str, Any]) -> Dict[str, Any]:
|