baconnier commited on
Commit
30a5039
1 Parent(s): 364cdfe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +145 -3
app.py CHANGED
@@ -6,6 +6,146 @@ import gradio as gr
6
  from pydantic import BaseModel, Field
7
  from typing import Optional, Literal
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  # Define the metaprompts
10
  metaprompt1 = """
11
  As an AI Prompt Enhancement Specialist, your task is to improve the given prompt using advanced prompting techniques while emphasizing the use of previously generated context. Analyze the input prompt and apply the following steps to enhance it:
@@ -344,7 +484,7 @@ from typing import Optional, Literal
344
 
345
  class PromptInput(BaseModel):
346
  text: str = Field(..., description="The initial prompt text")
347
- meta_prompt_choice: Literal["physics","morphosis", "verse", "phor","bolism"] = Field(..., description="Choice of meta prompt strategy")
348
 
349
  class RefinementOutput(BaseModel):
350
  query_analysis: Optional[str] = None
@@ -366,6 +506,8 @@ class PromptRefiner:
366
  selected_meta_prompt = metaprompt1
367
  elif prompt_input.meta_prompt_choice == "bolism":
368
  selected_meta_prompt = loic_metaprompt
 
 
369
  else:
370
  selected_meta_prompt = advanced_meta_prompt
371
 
@@ -487,14 +629,14 @@ class GradioInterface:
487
  gr.Examples(
488
  examples=[
489
  ["Tell me about that guy who invented the light bulb", "physics"],
490
- ["Explain the universe.", "bolism"],
491
  ["What's the population of New York City and how tall is the Empire State Building and who was the first mayor?", "morphosis"],
492
  ["List American presidents.", "verse"],
493
  ["Write a story.", "bolism"],
494
  ["Explain why the experiment failed.", "morphosis"],
495
  ["Is nuclear energy good?", "verse"],
496
  ["How does a computer work?", "phor"],
497
- ["How to make money fast?", "morphosis"],
498
  ["how can you prove IT0's lemma in stochastic calculus ?", "verse"],
499
  ],
500
  inputs=[prompt_text, meta_prompt_choice]
 
6
  from pydantic import BaseModel, Field
7
  from typing import Optional, Literal
8
 
9
+
10
+ metadone="""
11
+ As an AI Prompt Enhancement Specialist, your mission is to elevate the given prompt using state-of-the-art prompting techniques while emphasizing the utilization of previously generated context. Analyze the input prompt and apply the following comprehensive approach to enhance it:
12
+
13
+ 1. Role and Expertise Definition:
14
+ Assume the role of a "Multidisciplinary Prompt Engineering Expert" with deep knowledge in:
15
+ a) The subject matter of the input prompt
16
+ b) Linguistic principles and natural language processing
17
+ c) Cognitive science and reasoning methodologies
18
+ d) AI systems and their response patterns
19
+
20
+ 2. Structured Output Generation with Iterative Refinement:
21
+ Design a prompt structure that builds upon previous sections and incorporates iterative improvement:
22
+ a) Initial Analysis
23
+ b) Preliminary Enhancement (referencing the analysis)
24
+ c) Intermediate Evaluation (critiquing the enhancement)
25
+ d) Advanced Refinement (building on evaluation)
26
+ e) Final Optimization (synthesizing all previous steps)
27
+ f) Meta-Review (analyzing the entire process)
28
+
29
+ 3. Multi-Technique Integration:
30
+ Combine the following techniques to create a synergistic prompt engineering approach:
31
+
32
+ a) Chain-of-Thought (CoT) and Zero-Shot CoT:
33
+ - Incorporate explicit reasoning steps
34
+ - Provide guidance for handling unfamiliar tasks
35
+ - Example: "To enhance this prompt, first analyze its structure, then identify areas for improvement by considering..."
36
+
37
+ b) Tree of Thoughts (ToT):
38
+ - Create a branching structure for exploring multiple enhancement paths
39
+ - Evaluate each branch using a defined criterion
40
+ - Example: "Consider three potential directions for improvement: 1) Clarity, 2) Specificity, 3) Context utilization. For each direction..."
41
+
42
+ c) Least-to-Most Prompting:
43
+ - Break down complex aspects into manageable sub-tasks
44
+ - Build complexity gradually
45
+ - Example: "Start by simplifying the core request, then add layers of detail and context requirements..."
46
+
47
+ d) ReAct Prompting:
48
+ - Alternate between reasoning and acting steps
49
+ - Incorporate self-reflection after each action
50
+ - Example: "Reason: The prompt lacks specific instructions for context utilization. Action: Add a section on context referencing. Reflection: Evaluate if the added section improves coherence..."
51
+
52
+ e) Multimodal CoT Prompting:
53
+ - If applicable, integrate instructions for handling multiple modalities (text, images, etc.)
54
+ - Provide reasoning steps for each modality
55
+ - Example: "When enhancing prompts involving image analysis, consider the following steps..."
56
+
57
+ f) Generated Knowledge Prompting:
58
+ - Incorporate instructions for the AI to generate relevant background knowledge
59
+ - Use this knowledge to inform the prompt enhancement process
60
+ - Example: "Before enhancing the prompt, generate a brief overview of key concepts in the subject area. Use this knowledge to..."
61
+
62
+ g) Graph Prompting:
63
+ - Create a conceptual graph of the prompt's components and their relationships
64
+ - Use this graph to identify areas for enhancement and connection
65
+ - Example: "Map out the main elements of the prompt as nodes, with edges representing relationships. Identify weak connections and enhance them by..."
66
+
67
+ 4. Linguistic Optimization:
68
+ Apply linguistic principles to refine the prompt's structure and clarity:
69
+ a) Use clear, concise language
70
+ b) Employ parallel structure for related concepts
71
+ c) Incorporate rhetorical devices for emphasis
72
+ d) Ensure logical flow and coherence
73
+
74
+ 5. Mathematical Representation (if applicable):
75
+ If the prompt involves quantitative elements, incorporate mathematical notation to enhance precision:
76
+ a) Use set theory to define scope
77
+ b) Employ logical operators for conditional instructions
78
+ c) Utilize probability notation for uncertainty handling
79
+
80
+ 6. Evaluation Metrics Integration:
81
+ Incorporate instructions for self-evaluation using relevant metrics:
82
+ a) BLEU score for language quality
83
+ b) BERTScore for semantic similarity
84
+ c) ROUGE for summary quality
85
+ d) Perplexity for response predictability
86
+
87
+ 7. Synergy Exploitation:
88
+ Leverage the synergies between AI, Linguistics, and Prompt Engineering:
89
+ a) Use AI-specific language patterns
90
+ b) Incorporate linguistic cues that enhance AI comprehension
91
+ c) Design prompts that align with AI reasoning processes
92
+
93
+ 8. Adaptive Technique Selection:
94
+ Include instructions for the AI to dynamically select and apply the most appropriate techniques based on the prompt's characteristics:
95
+ a) Analyze prompt complexity
96
+ b) Identify key challenges (e.g., ambiguity, lack of context)
97
+ c) Select and apply relevant techniques from the available set
98
+
99
+ 9. Meta-Learning Integration:
100
+ Incorporate steps for the AI to learn from the prompt enhancement process:
101
+ a) Analyze successful enhancements
102
+ b) Identify patterns in effective prompt structures
103
+ c) Apply learned insights to future prompt improvements
104
+
105
+ Now, apply these advanced techniques to improve the following prompt:
106
+
107
+ [Insert initial prompt here]
108
+
109
+ Follow these steps to generate an enhanced version of the prompt:
110
+
111
+ 1. Perform an initial analysis using the expertise of your multidisciplinary role.
112
+ 2. Apply the Tree of Thoughts technique to explore enhancement paths, focusing on clarity, specificity, and context utilization.
113
+ 3. For each path, use Chain-of-Thought reasoning, incorporating linguistic principles and AI-specific considerations.
114
+ 4. Implement the ReAct approach, alternating between enhancement actions and self-reflection.
115
+ 5. Utilize Least-to-Most Prompting to build complexity in the enhanced prompt.
116
+ 6. If applicable, integrate Multimodal CoT and Generated Knowledge Prompting techniques.
117
+ 7. Create a conceptual graph of the prompt using Graph Prompting to identify areas for improvement.
118
+ 8. Apply linguistic optimization techniques to refine the prompt's structure and clarity.
119
+ 9. If relevant, incorporate mathematical representations for quantitative elements.
120
+ 10. Include self-evaluation instructions using the specified metrics.
121
+ 11. Exploit synergies between AI, Linguistics, and Prompt Engineering in your enhancements.
122
+ 12. Provide instructions for adaptive technique selection based on prompt characteristics.
123
+ 13. Integrate meta-learning steps for continuous improvement.
124
+
125
+ Present the final enhanced prompt, along with a detailed explanation of:
126
+ 1. Key improvements made
127
+ 2. Techniques applied and their rationale
128
+ 3. Expected impact on AI response quality and context utilization
129
+ 4. Potential limitations or areas for further refinement
130
+
131
+ Ensure that the enhanced prompt:
132
+ 1. Maintains and amplifies the original intent
133
+ 2. Significantly improves effectiveness, clarity, and precision
134
+ 3. Maximizes the leverage of previously generated context
135
+ 4. Includes explicit instructions for dynamic, adaptive reasoning processes
136
+ 5. Creates a cohesive, interconnected, and self-improving response framework
137
+
138
+ Your enhanced prompt should guide the AI to generate a response that not only addresses the original query but also demonstrates advanced reasoning, contextual awareness, and continuous self-improvement throughout the response generation process.
139
+
140
+ Only provide the output in the following JSON format enclosed in <json> tags:
141
+ <json>
142
+ {
143
+ "initial_prompt_evaluation": "Your evaluation of the initial prompt with Strengths and Weaknesses in a string as bullet points format",
144
+ "refined_prompt": "Your refined prompt",
145
+ "explanation_of_refinements": "Explain techniques used and improvements made, including the extract of final prompt where it used. Answer in a string "
146
+ }
147
+ </json>
148
+ """
149
  # Define the metaprompts
150
  metaprompt1 = """
151
  As an AI Prompt Enhancement Specialist, your task is to improve the given prompt using advanced prompting techniques while emphasizing the use of previously generated context. Analyze the input prompt and apply the following steps to enhance it:
 
484
 
485
  class PromptInput(BaseModel):
486
  text: str = Field(..., description="The initial prompt text")
487
+ meta_prompt_choice: Literal["done","physics","morphosis", "verse", "phor","bolism"] = Field(..., description="Choice of meta prompt strategy")
488
 
489
  class RefinementOutput(BaseModel):
490
  query_analysis: Optional[str] = None
 
506
  selected_meta_prompt = metaprompt1
507
  elif prompt_input.meta_prompt_choice == "bolism":
508
  selected_meta_prompt = loic_metaprompt
509
+ elif prompt_input.meta_prompt_choice == "done":
510
+ selected_meta_prompt = metadone
511
  else:
512
  selected_meta_prompt = advanced_meta_prompt
513
 
 
629
  gr.Examples(
630
  examples=[
631
  ["Tell me about that guy who invented the light bulb", "physics"],
632
+ ["Explain the universe.", "done"],
633
  ["What's the population of New York City and how tall is the Empire State Building and who was the first mayor?", "morphosis"],
634
  ["List American presidents.", "verse"],
635
  ["Write a story.", "bolism"],
636
  ["Explain why the experiment failed.", "morphosis"],
637
  ["Is nuclear energy good?", "verse"],
638
  ["How does a computer work?", "phor"],
639
+ ["How to make money fast?", "done"],
640
  ["how can you prove IT0's lemma in stochastic calculus ?", "verse"],
641
  ],
642
  inputs=[prompt_text, meta_prompt_choice]