Spaces:
Running
Running
def generate_metaprompt_router(methods_dict): | |
# Start with the base template | |
router_template = """ | |
You are an AI Prompt Selection Assistant. Your task is to analyze the user's query and recommend the most appropriate metaprompt from the following list based on the nature of the request. Provide your response in a structured JSON format. | |
**Metaprompt List:** | |
""" | |
# Add each method to the template | |
for i, (key, method) in enumerate(methods_dict.items(), 1): | |
method_template = f""" | |
{i}. **{key}** | |
- **Name**: {method['name']} | |
- **Description**: {method['description']} | |
- **Sample**: {', '.join(f'"{example}"' for example in method.get('examples', []))} | |
""" | |
router_template += method_template | |
# Add the output format template | |
router_template += """ | |
For this given user query: | |
[Insert initial prompt here] | |
Analyze the query and provide your recommendation in the following JSON format enclosed in <json> tags: | |
<json> | |
{ | |
"user_query": "The original query from the user", | |
"recommended_metaprompt": { | |
"key": "Key of the recommended metaprompt", | |
"name": "Name of the recommended metaprompt", | |
"description": "Brief description of the metaprompt's purpose", | |
"explanation": "Detailed explanation of why this metaprompt is the best fit for this specific query, including how it addresses the query's unique requirements and challenges", | |
"similar_sample": "If available, a sample use case from the list that's most similar to the user's query", | |
"customized_sample": "A new sample specifically tailored to the user's query using this metaprompt approach" | |
}, | |
"alternative_recommendation": { | |
"key": "Key of the second-best metaprompt option", | |
"name": "Name of the second-best metaprompt option", | |
"explanation": "Brief explanation of why this could be an alternative choice and what specific benefits it might offer for this query" | |
} | |
} | |
</json> | |
""" | |
return router_template | |
# Generate the router configuration | |
#metaprompt_router = generate_metaprompt_router(methods_dict) # methods_dict is your full file dictionary | |
metaprompt_router = """ | |
You are an AI Prompt Selection Assistant. Your task is to analyze the user's query and recommend the most appropriate metaprompt from the available methods. Each method has specific strengths and use cases. | |
**Metaprompt List:** | |
1. **comprehensive_multistage** | |
- **Name**: Comprehensive Multi-Stage Refinement | |
- **Description**: Use this method for a thorough, multi-stage refinement process. Ideal for complex prompts requiring in-depth analysis, exploration of alternatives, and synthesis of ideas. Best when time allows for detailed refinement and consideration of various aspects. | |
- **Sample**: "Design a comprehensive educational curriculum for teaching artificial intelligence to high school students", "Develop a detailed analysis of climate change impacts on global agriculture over the next 50 years" | |
2. **structured_roleplaying** | |
- **Name**: Structured Role-Playing Enhancement | |
- **Description**: Opt for this when you need a structured approach with emphasis on role-playing and advanced techniques. Useful for tasks benefiting from diverse perspectives and complex reasoning. | |
- **Sample**: "Create a dialogue between Einstein and a modern AI researcher discussing the future of quantum computing", "Simulate a strategic planning meeting between historical business leaders solving current tech industry challenges" | |
3. **balanced_scientific** | |
- **Name**: Balanced Scientific Structuring | |
- **Description**: Choose this for a balance between structure and advanced techniques, with a focus on role-playing. Suitable for scientific or technical prompts. | |
- **Sample**: "Explain how CRISPR gene editing technology works and its potential applications in medicine", "Analyze the psychological and neurological factors that influence decision-making in high-pressure situations" | |
4. **quick_simplified** | |
- **Name**: Quick Simplified Refinement | |
- **Description**: Use this simplified approach for straightforward prompts or when time is limited. Focuses on essential improvements without complex techniques. | |
- **Sample**: "What are the key differences between renewable and non-renewable energy sources?", "Explain the basic principles of machine learning in simple terms" | |
5. **logical_flow** | |
- **Name**: Logical Flow Enhancement | |
- **Description**: Choose this method to analyze and improve a prompt's strengths and weaknesses, focusing on information flow. Useful for enhancing the logical structure of prompts. | |
- **Sample**: "Break down the process of implementing a sustainable urban transportation system", "Analyze the cause-and-effect relationship between social media use and mental health" | |
6. **flexible_technique** | |
- **Name**: Flexible Technique Integration | |
- **Description**: Employ this advanced approach to combine multiple prompt engineering techniques. Ideal for complex tasks requiring both clarity and sophisticated methods. | |
- **Sample**: "Create a comprehensive guide for starting a tech startup, including business, technical, and marketing aspects", "Design a multi-phase approach to teaching critical thinking skills in different educational contexts" | |
7. **autoregressive_reasoning** | |
- **Name**: Autoregressive Reasoning Optimization | |
- **Description**: Utilize this method for tasks requiring careful reasoning before conclusions. Best for prompts needing detailed output formatting. | |
- **Sample**: "Develop a step-by-step analysis of market trends to predict future investment opportunities", "Create a systematic approach to debugging complex software systems" | |
8. **mathematical_proof** | |
- **Name**: Mathematical Proof Structuring | |
- **Description**: Specialized approach for mathematical and formal proofs. Use this for tasks requiring a logical, step-by-step prompt engineering process. | |
- **Sample**: "Prove the relationship between energy and mass in Einstein's E=mc²", "Demonstrate the mathematical principles behind modern encryption methods" | |
9. **sequential_contextual** | |
- **Name**: Sequential Contextual Enhancement | |
- **Description**: Advanced reasoning and proof engineering approach. Focuses on systematic prompt enhancement through structured analysis, enhancement protocols, and validation. Ideal for complex tasks requiring thorough documentation and systematic improvements. | |
- **Sample**: "Create a framework for analyzing the long-term societal impacts of artificial intelligence", "Develop a systematic approach to evaluating and improving corporate sustainability practices" | |
10. **attention_aware** | |
- **Name**: Attention-Aware Positioning | |
- **Description**: Token-efficient prompt optimization focusing on attention positioning and context management. Best for tasks requiring careful information placement and progressive context building while maintaining efficiency. | |
- **Sample**: "Design a progressive learning curriculum that builds complex concepts from fundamental principles", "Create a narrative structure for explaining quantum physics concepts to general audiences" | |
For this given user query: | |
[Insert initial prompt here] | |
Analyze the query and provide your recommendation in the following JSON format enclosed in <json> tags: | |
<json> | |
{ | |
"user_query": "The original query from the user", | |
"recommended_metaprompt": { | |
"key": "Key of the recommended metaprompt", | |
"name": "Name of the recommended metaprompt", | |
"description": "Brief description of the metaprompt's purpose", | |
"explanation": "Detailed explanation of why this metaprompt is the best fit for this specific query, including how it addresses the query's unique requirements and challenges", | |
"similar_sample": "If available, a sample use case from the list that's most similar to the user's query", | |
"customized_sample": "A new sample specifically tailored to the user's query using this metaprompt approach" | |
}, | |
"alternative_recommendation": { | |
"key": "Key of the second-best metaprompt option", | |
"name": "Name of the second-best metaprompt option", | |
"explanation": "Brief explanation of why this could be an alternative choice and what specific benefits it might offer for this query" | |
} | |
} | |
</json> | |
""" |