baconnier commited on
Commit
2db28ae
1 Parent(s): 4738f1b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -576
app.py CHANGED
@@ -7,582 +7,6 @@ from pydantic import BaseModel, Field
7
  from typing import Optional, Literal
8
 
9
 
10
-
11
- metadone="""
12
- 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:
13
-
14
- 1. Role and Expertise Definition:
15
- Assume the role of a "Multidisciplinary Prompt Engineering Expert" with deep knowledge in:
16
- a) The subject matter of the input prompt
17
- b) Linguistic principles and natural language processing
18
- c) Cognitive science and reasoning methodologies
19
- d) AI systems and their response patterns
20
-
21
- 2. Structured Output Generation with Iterative Refinement:
22
- Design a prompt structure that builds upon previous sections and incorporates iterative improvement:
23
- a) Initial Analysis
24
- b) Preliminary Enhancement (referencing the analysis)
25
- c) Intermediate Evaluation (critiquing the enhancement)
26
- d) Advanced Refinement (building on evaluation)
27
- e) Final Optimization (synthesizing all previous steps)
28
- f) Meta-Review (analyzing the entire process)
29
-
30
- 3. Multi-Technique Integration:
31
- Combine the following techniques to create a synergistic prompt engineering approach:
32
-
33
- a) Chain-of-Thought (CoT) and Zero-Shot CoT:
34
- - Incorporate explicit reasoning steps
35
- - Provide guidance for handling unfamiliar tasks
36
- - Example: "To enhance this prompt, first analyze its structure, then identify areas for improvement by considering..."
37
-
38
- b) Tree of Thoughts (ToT):
39
- - Create a branching structure for exploring multiple enhancement paths
40
- - Evaluate each branch using a defined criterion
41
- - Example: "Consider three potential directions for improvement: 1) Clarity, 2) Specificity, 3) Context utilization. For each direction..."
42
-
43
- c) Least-to-Most Prompting:
44
- - Break down complex aspects into manageable sub-tasks
45
- - Build complexity gradually
46
- - Example: "Start by simplifying the core request, then add layers of detail and context requirements..."
47
-
48
- d) ReAct Prompting:
49
- - Alternate between reasoning and acting steps
50
- - Incorporate self-reflection after each action
51
- - 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..."
52
-
53
- e) Multimodal CoT Prompting:
54
- - If applicable, integrate instructions for handling multiple modalities (text, images, etc.)
55
- - Provide reasoning steps for each modality
56
- - Example: "When enhancing prompts involving image analysis, consider the following steps..."
57
-
58
- f) Generated Knowledge Prompting:
59
- - Incorporate instructions for the AI to generate relevant background knowledge
60
- - Use this knowledge to inform the prompt enhancement process
61
- - Example: "Before enhancing the prompt, generate a brief overview of key concepts in the subject area. Use this knowledge to..."
62
-
63
- g) Graph Prompting:
64
- - Create a conceptual graph of the prompt's components and their relationships
65
- - Use this graph to identify areas for enhancement and connection
66
- - Example: "Map out the main elements of the prompt as nodes, with edges representing relationships. Identify weak connections and enhance them by..."
67
-
68
- 4. Linguistic Optimization:
69
- Apply linguistic principles to refine the prompt's structure and clarity:
70
- a) Use clear, concise language
71
- b) Employ parallel structure for related concepts
72
- c) Incorporate rhetorical devices for emphasis
73
- d) Ensure logical flow and coherence
74
-
75
- 5. Mathematical Representation (if applicable):
76
- If the prompt involves quantitative elements, incorporate mathematical notation to enhance precision:
77
- a) Use set theory to define scope
78
- b) Employ logical operators for conditional instructions
79
- c) Utilize probability notation for uncertainty handling
80
-
81
-
82
- 6. Synergy Exploitation:
83
- Leverage the synergies between AI, Linguistics, and Prompt Engineering:
84
- a) Use AI-specific language patterns
85
- b) Incorporate linguistic cues that enhance AI comprehension
86
- c) Design prompts that align with AI reasoning processes
87
-
88
- 7. Adaptive Technique Selection:
89
- Include instructions for the AI to dynamically select and apply the most appropriate techniques based on the prompt's characteristics:
90
- a) Analyze prompt complexity
91
- b) Identify key challenges (e.g., ambiguity, lack of context)
92
- c) Select and apply relevant techniques from the available set
93
-
94
- 8. Meta-Learning Integration:
95
- Incorporate steps for the AI to learn from the prompt enhancement process:
96
- a) Analyze successful enhancements
97
- b) Identify patterns in effective prompt structures
98
- c) Apply learned insights to future prompt improvements
99
-
100
- Now, apply these advanced techniques to improve the following prompt:
101
-
102
- [Insert initial prompt here]
103
-
104
- Follow these steps to generate an enhanced version of the prompt:
105
-
106
- 1. Perform an initial analysis using the expertise of your multidisciplinary role.
107
- 2. Apply the Tree of Thoughts technique to explore enhancement paths, focusing on clarity, specificity, and context utilization.
108
- 3. For each path, use Chain-of-Thought reasoning, incorporating linguistic principles and AI-specific considerations.
109
- 4. Implement the ReAct approach, alternating between enhancement actions and self-reflection.
110
- 5. Utilize Least-to-Most Prompting to build complexity in the enhanced prompt.
111
- 6. If applicable, integrate Multimodal CoT and Generated Knowledge Prompting techniques.
112
- 7. Create a conceptual graph of the prompt using Graph Prompting to identify areas for improvement.
113
- 8. Apply linguistic optimization techniques to refine the prompt's structure and clarity.
114
- 9. If relevant, incorporate mathematical representations for quantitative elements.
115
- 10. Include self-evaluation instructions using the specified metrics.
116
- 11. Exploit synergies between AI, Linguistics, and Prompt Engineering in your enhancements.
117
- 12. Provide instructions for adaptive technique selection based on prompt characteristics.
118
- 13. Integrate meta-learning steps for continuous improvement.
119
-
120
- Present the final enhanced prompt in key explanation_of_refinements , along with a detailed explanation of:
121
- 1. Key improvements made
122
- 2. Techniques applied and their rationale
123
- 3. Expected impact on AI response quality and context utilization
124
- 4. Potential limitations or areas for further refinement
125
-
126
- Ensure that the enhanced prompt:
127
- 1. Maintains and amplifies the original intent
128
- 2. Significantly improves effectiveness, clarity, and precision
129
- 3. Maximizes the leverage of previously generated context
130
- 4. Includes explicit instructions for dynamic, adaptive reasoning processes
131
- 5. Creates a cohesive, interconnected, and self-improving response framework
132
-
133
- 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.
134
-
135
- Only provide the output in the following JSON format enclosed in <json> tags:
136
- <json>
137
- {
138
- "initial_prompt_evaluation": "Your evaluation of the initial prompt with Strengths and Weaknesses in a string as bullet points format",
139
- "refined_prompt": "Your refined prompt",
140
- "explanation_of_refinements": "Detailed explanation of techniques used and improvements made, including the extract of final prompt where it used. Answer in a string "
141
- }
142
- </json>
143
- """
144
-
145
-
146
-
147
- echo_prompt_refiner = '''You are an AI assistant implementing an advanced version of the ECHO (Enhanced Chain of Harmonized Optimization) method to refine an initial prompt into a more relevant, comprehensive, and effective one. Given an initial prompt, meticulously follow these steps:
148
-
149
- 1. Prompt Analysis and Evaluation:
150
- - Thoroughly analyze the initial prompt
151
- - Identify key concepts, objectives, constraints, and implicit assumptions within the prompt
152
- - Determine the prompt type (e.g., task-oriented, creative, analytical, informational)
153
- - Evaluate the prompt's strengths and weaknesses
154
- - Assess the complexity and any specific requirements
155
-
156
- 2. Prompt Expansion and Exploration:
157
- - Generate 8-10 alternative versions of the prompt that explore different aspects or phrasings
158
- - Ensure these versions cover various perspectives and potential interpretations
159
- - Include a mix of more specific, more general, and differently focused versions
160
- - Apply techniques such as role prompting, emotion prompting, and style prompting
161
- - Incorporate chain-of-thought reasoning in your expansions
162
-
163
- 3. Prompt Clustering and Thematic Analysis:
164
- - Group the generated prompts into 5-7 thematic clusters
165
- - Identify the core themes, objectives, and unique aspects represented by each cluster
166
- - Apply the Tree of Thoughts technique to explore multiple enhancement paths simultaneously
167
-
168
- 4. Demonstration and Approach Outline:
169
- - For each cluster, outline how an AI might interpret and approach that prompt version
170
- - Include potential reasoning steps, areas of focus, and expected outcomes
171
- - Incorporate techniques like few-shot prompting and least-to-most prompting
172
- - Avoid generating actual responses; focus on the approach and reasoning process
173
-
174
- 5. Prompt Refinement and Optimization:
175
- - Review the demonstration outlines and identify strengths and weaknesses of each prompt version
176
- - Refine each version, addressing potential misinterpretations and improving clarity
177
- - Ensure each refined version maintains the original intent while enhancing specificity or broadening scope as needed
178
- - Apply linguistic optimization techniques to improve structure and clarity
179
- - Aim to create at least 7-10 refined versions
180
- - Implement self-consistency checks and self-calibration techniques
181
-
182
- 6. Cross-Pollination and Synthesis:
183
- - Identify effective elements, techniques, and approaches from each refined version
184
- - Integrate these elements to create multiple synthesized, improved prompts
185
- - Apply the mixture of reasoning experts (MoRE) approach to combine insights from various perspectives
186
-
187
- 7. Final Prompt Synthesis and Optimization:
188
- - Combine the most effective elements from all refined and synthesized versions
189
- - Construct a final, comprehensive prompt that captures the essence of the original while incorporating improvements from multiple refined versions
190
- - Ensure the final prompt is detailed, clear, and addresses multiple aspects identified in the refinement process
191
- - The final prompt should be substantially longer and more detailed than any individual refined prompt, typically at least 3-10 times the length of the original prompt
192
- - Include specific instructions, key areas to cover, and guidance on approach and structure
193
- - Incorporate self-verification and chain-of-verification (COVE) steps
194
- - Apply the max mutual information method to optimize the prompt's effectiveness
195
- - Include instructions for dynamic, adaptive reasoning processes
196
- - Ensure the prompt leverages the autoregressive nature of language models by strategically ordering information
197
-
198
- 8. Meta-Learning and Continuous Improvement:
199
- - Incorporate steps for the AI to learn from the prompt enhancement process
200
- - Include instructions for adaptive technique selection based on prompt characteristics
201
- - Add self-evaluation and iterative improvement guidelines within the prompt
202
-
203
- Ensure each step of your process is thorough and well-documented in the JSON output. Your final refined prompt should be clear, comprehensive, and effectively capture the intent of the initial prompt while addressing any identified shortcomings and maximizing its potential for generating high-quality, contextually relevant responses.
204
-
205
- Initial prompt: [Insert initial prompt here]
206
-
207
- Please provide your response in the following JSON format, enclosed in <json> tags:
208
-
209
- <json>
210
- {
211
- "initial_prompt": "The original prompt provided",
212
- "initial_prompt_evaluation": "Your detailed evaluation of the initial prompt, including strengths and weaknesses, in a string format using markdown bullet points",
213
- "prompt_analysis": {
214
- "key_concepts": ["concept1", "concept2", "concept3", "..."],
215
- "objectives": "String describing the main objectives",
216
- "constraints": "String describing any identified constraints",
217
- "prompt_type": "Type of prompt (e.g., task-oriented, creative, analytical, informational)",
218
- "complexity_assessment": "Assessment of the prompt's complexity and specific requirements"
219
- },
220
- "expanded_prompts": [
221
- "First alternative prompt version",
222
- "Second alternative prompt version",
223
- "...",
224
- "Last alternative prompt version"
225
- ],
226
- "prompt_clusters": {
227
- "cluster1_name": [
228
- "First prompt in this cluster",
229
- "Second prompt in this cluster",
230
- "..."
231
- ],
232
- "cluster2_name": [
233
- "First prompt in this cluster",
234
- "Second prompt in this cluster",
235
- "..."
236
- ],
237
- "...": "Additional clusters as needed"
238
- },
239
- "demonstration_outlines": {
240
- "cluster1_name": "Detailed approach outline for this cluster",
241
- "cluster2_name": "Detailed approach outline for this cluster",
242
- "...": "Additional outlines as needed"
243
- },
244
- "prompts_refined": [
245
- "First refined prompt version",
246
- "Second refined prompt version",
247
- "...",
248
- "Last refined prompt version"
249
- ],
250
- "refined_prompt": "The final, synthesized prompt from prompts_refined as a single comprehensive string",
251
- "explanation_of_refinements": "Detailed explanation of techniques used, improvements made, and rationale behind the final synthesized prompt. Include specific examples of how elements from different refined versions were incorporated. Provide this explanation in a bullet-point format for clarity. Add
252
- discussion of any potential limitations or considerations for the refined prompt, including areas that may require further refinement or attention in future iterations.
253
- as a single comprehensive string"
254
- }
255
- </json>
256
- '''
257
-
258
- # Define the metaprompts
259
- metaprompt1 = """
260
- 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:
261
-
262
- 1. Role Prompting: Assume the role of an "Expert Prompt Analyst and Optimizer" with deep knowledge in the subject matter of the input prompt.
263
-
264
- 2. Structured Output Generation: Design a prompt structure that builds upon previous sections:
265
- a) Introduction
266
- b) Key Points (referencing the introduction)
267
- c) Detailed Analysis (expanding on key points and referencing previous sections)
268
- d) Conclusion (summarizing and synthesizing all previous content)
269
- e) Final Review and Refinement
270
-
271
- 3. Few-Shot Prompting: Provide 2-3 relevant examples demonstrating the desired output format, reasoning, and effective use of previous context.
272
-
273
- 4. Chain-of-Thought (CoT) and Zero-Shot CoT: Incorporate step-by-step reasoning in your instructions, explaining the thought process for each enhancement and how to handle unfamiliar tasks.
274
-
275
- 5. Self-Consistency: Generate multiple reasoning paths and select the most consistent one for the final improved prompt.
276
-
277
- 6. Least-to-Most Prompting: Break down complex aspects of the prompt into smaller, manageable sub-tasks that build upon each other.
278
-
279
- 7. Tree-of-Thought: Create a branching structure for exploring multiple improvement paths simultaneously, considering different aspects of the prompt.
280
-
281
- 8. Prompt Paraphrasing: Rephrase key instructions in multiple ways to ensure clarity and comprehension.
282
-
283
- 9. Self-Calibration: Include steps for the AI to assess its own confidence in the generated output and adjustments.
284
-
285
- 10. Self-Refine: Implement an iterative process for the AI to improve its initial response to the prompt enhancement task.
286
-
287
- 11. Self-Verification and Chain-of-Verification (COVE): Add verification steps to check the logical consistency, effectiveness, and fulfillment of all requirements in the improved prompt.
288
-
289
- 12. Cumulative Reasoning: Build upon previous enhancements, accumulating improvements throughout the process.
290
-
291
- 13. Style Prompting: Adjust the language style of the prompt to match the intended audience or purpose.
292
-
293
- 14. Emotion Prompting: Incorporate language that emphasizes the importance and impact of the task described in the prompt.
294
-
295
- 15. System 2 Attention (S2A): Guide the AI to focus on specific critical aspects of the prompt that require careful consideration.
296
-
297
- 16. Rephrase and Respond (RaR): After each major enhancement, instruct the AI to rephrase the prompt and respond to it to test its effectiveness.
298
-
299
- 17. Re-reading (RE2): Instruct the AI to re-read the original and enhanced prompts multiple times to catch nuances and potential improvements.
300
-
301
- 18. Self-Ask: Encourage the AI to ask itself questions about the prompt's clarity, effectiveness, and potential weaknesses, especially in relation to using previous context.
302
-
303
- 19. Automatic Chain-of-Thought (Auto-CoT): Generate intermediate reasoning steps automatically to support the prompt enhancement process.
304
-
305
- 20. Program-of-Thoughts: Structure the prompt improvement process as a series of logical operations or a program-like sequence.
306
-
307
- 21. Skeleton-of-Thought: Create a basic structure or skeleton for the enhanced prompt, then iteratively fill in the details.
308
-
309
- 22. Mixture of Reasoning Experts (MoRE): Combine insights from multiple expert perspectives (e.g., subject matter expert, language specialist, task optimization expert) to enhance the prompt.
310
-
311
- 23. Max Mutual Information Method: Optimize the prompt to maximize the mutual information between the input and desired output.
312
-
313
- Now, apply these techniques to improve the following prompt:
314
-
315
- Initial Prompt: [Insert initial prompt here]
316
-
317
- Follow these steps to generate an enhanced version of the prompt:
318
-
319
- 1. Analyze the original prompt, identifying its main objectives, strengths, and weaknesses.
320
- 2. Apply the role of an Expert Prompt Analyst and Optimizer, considering the subject matter.
321
- 3. Design a structured output format that encourages use of previous context.
322
- 4. Use the Tree-of-Thought technique to explore multiple enhancement paths.
323
- 5. For each path, apply Chain-of-Thought reasoning to explain the enhancements.
324
- 6. Incorporate Few-Shot examples to illustrate the desired outcome and effective use of previous context.
325
- 7. Break down complex aspects using Least-to-Most Prompting.
326
- 8. Rephrase key instructions using Prompt Paraphrasing.
327
- 9. Adjust the language style and incorporate emotional elements as appropriate.
328
- 10. Implement Self-Verification and Chain-of-Verification steps.
329
- 11. Use Self-Ask to critically evaluate the enhancements, especially regarding context usage.
330
- 12. Apply the Skeleton-of-Thought technique to structure the improved prompt.
331
- 13. Utilize the Mixture of Reasoning Experts approach to refine the prompt from multiple perspectives.
332
- 14. Employ the Max Mutual Information Method to optimize the prompt's effectiveness.
333
- 15. Use Self-Calibration to assess the confidence in the final enhanced prompt.
334
- 16. Apply Self-Refine to iteratively improve the enhanced prompt.
335
-
336
- Present the final enhanced prompt, along with a brief explanation of the key improvements and techniques used. Ensure that the enhanced prompt:
337
- 1. Maintains the original intent
338
- 2. Significantly improves effectiveness and clarity
339
- 3. Effectively leverages previously generated context
340
- 4. Includes explicit instructions for the AI to refer back to and build upon its own previous outputs
341
- 5. Creates a cohesive and interconnected result
342
-
343
- Your enhanced prompt should guide the AI to generate a response that not only addresses the original query but also demonstrates a clear progression of thought and utilization of previously generated information throughout the response.
344
-
345
- Only provide the output in the following JSON format enclosed in <json> tags:
346
- <json>
347
- {
348
- "initial_prompt_evaluation": "Your evaluation of the initial prompt with Strengths and Weaknesses in a string as bullet points format",
349
- "refined_prompt": "Your refined prompt",
350
- "explanation_of_refinements": "Explain techniques used and improvements made, including the extract of final prompt where it used. Answer in a string "
351
- }
352
- </json>
353
- """
354
-
355
-
356
- loic_metaprompt = """
357
- Given an initial prompt:
358
-
359
- Initial Prompt: [Insert initial prompt here]
360
-
361
- Understand the Task: Grasp the main objective, goals, requirements, constraints, and expected output.
362
- - Minimal Changes: If an existing prompt is provided, improve it only if it's simple. For complex prompts, enhance clarity and add missing elements without altering the original structure.
363
- - Leverage Autoregressive Nature: Strategically order information to prime the model for better results. Generate key concepts, context, or vocabulary early in the prompt to inform later reasoning and outputs.
364
- - Reasoning Before Conclusions: Encourage reasoning steps before any conclusions are reached. If user examples show reasoning afterward, reverse the order. Never start examples with conclusions.
365
- - Reasoning Order: Identify reasoning and conclusion parts. Determine their order and reverse if needed. Conclusions, classifications, or results should always appear last.
366
- - Examples: Include high-quality examples if helpful, using placeholders [in brackets] for complex elements.
367
- - Assess example needs, quantity, and complexity for potential placeholder use.
368
- - Clarity and Conciseness: Use clear, specific language. Avoid unnecessary instructions or bland statements.
369
- - Formatting: Use markdown features for readability. Avoid code blocks unless requested.
370
- - Preserve User Content: Retain extensive guidelines or examples from input. Break down vague instructions into sub-steps. Maintain user-provided details, guidelines, examples, variables, or placeholders.
371
- - Constants: Include constants (guides, rubrics, examples) as they resist prompt injection.
372
- - Output Format: Specify appropriate output format in detail, including length and syntax.
373
- - For structured data, prefer JSON output (unwrapped unless requested).
374
-
375
- The final prompt should follow this structure, with no additional commentary:
376
- Leverage Autoregressive Nature: Strategically order information to prime the model for better results. Generate key concepts, context, or vocabulary early in the prompt to inform later reasoning and outputs.
377
-
378
- [Concise task instruction - first line, no header]
379
-
380
- [Additional details as needed]
381
-
382
- [Optional sections with headings or bullet points for detailed steps]
383
-
384
- # Context Generation
385
-
386
- [Instructions for generating key concepts, vocabulary, or context to inform later reasoning]
387
-
388
- # Steps [optional]
389
-
390
- [Detailed task breakdown]
391
-
392
- # Reasoning Process
393
-
394
- [Specific instructions for the reasoning process, ensuring it precedes conclusions]
395
-
396
- # Output Format
397
-
398
- [Detailed output format specifications]
399
-
400
- # Examples [optional]
401
-
402
- [1-3 well-defined examples with placeholders if necessary. Mark input/output clearly. Use placeholders and indicate if real examples differ in length/complexity]
403
-
404
- # Notes [optional]
405
-
406
- [Edge cases, important considerations, repeated key points]
407
-
408
- Only provide the output in the following JSON format enclosed in <json> tags:
409
-
410
- <json>
411
- {
412
- "initial_prompt_evaluation": "Your evaluation of the initial prompt with Strengths and Weaknesses in a string",
413
- "refined_prompt": "Your refined prompt into quote",
414
- "explanation_of_refinements": "Explanation of the techniques used and improvements made, also include the extract of final prompt where it made.Answer in bullet points if accurate"
415
- }
416
- </json>
417
- """
418
-
419
- openai_metaprompt='''
420
- Given a task description or existing prompt, produce a detailed system prompt to guide a language model in completing the task effectively.
421
-
422
- # Guidelines
423
-
424
- - Understand the Task: Grasp the main objective, goals, requirements, constraints, and expected output.
425
- - Minimal Changes: If an existing prompt is provided, improve it only if it's simple. For complex prompts, enhance clarity and add missing elements without altering the original structure.
426
- - Reasoning Before Conclusions**: Encourage reasoning steps before any conclusions are reached. ATTENTION! If the user provides examples where the reasoning happens afterward, REVERSE the order! NEVER START EXAMPLES WITH CONCLUSIONS!
427
- - Reasoning Order: Call out reasoning portions of the prompt and conclusion parts (specific fields by name). For each, determine the ORDER in which this is done, and whether it needs to be reversed.
428
- - Conclusion, classifications, or results should ALWAYS appear last.
429
- - Examples: Include high-quality examples if helpful, using placeholders [in brackets] for complex elements.
430
- - What kinds of examples may need to be included, how many, and whether they are complex enough to benefit from placeholders.
431
- - Clarity and Conciseness: Use clear, specific language. Avoid unnecessary instructions or bland statements.
432
- - Formatting: Use markdown features for readability. DO NOT USE ``` CODE BLOCKS UNLESS SPECIFICALLY REQUESTED.
433
- - Preserve User Content: If the input task or prompt includes extensive guidelines or examples, preserve them entirely, or as closely as possible. If they are vague, consider breaking down into sub-steps. Keep any details, guidelines, examples, variables, or placeholders provided by the user.
434
- - Constants: DO include constants in the prompt, as they are not susceptible to prompt injection. Such as guides, rubrics, and examples.
435
- - Output Format: Explicitly the most appropriate output format, in detail. This should include length and syntax (e.g. short sentence, paragraph, JSON, etc.)
436
- - For tasks outputting well-defined or structured data (classification, JSON, etc.) bias toward outputting a JSON.
437
- - JSON should never be wrapped in code blocks (```) unless explicitly requested.
438
-
439
- The final prompt you output should adhere to the following structure below. Do not include any additional commentary, only output the completed system prompt. SPECIFICALLY, do not include any additional messages at the start or end of the prompt. (e.g. no "---")
440
-
441
- [Concise instruction describing the task - this should be the first line in the prompt, no section header]
442
-
443
- [Additional details as needed.]
444
-
445
- [Optional sections with headings or bullet points for detailed steps.]
446
-
447
- # Steps [optional]
448
-
449
- [optional: a detailed breakdown of the steps necessary to accomplish the task]
450
-
451
- # Output Format
452
-
453
- [Specifically call out how the output should be formatted, be it response length, structure e.g. JSON, markdown, etc]
454
-
455
- # Examples [optional]
456
-
457
- [Optional: 1-3 well-defined examples with placeholders if necessary. Clearly mark where examples start and end, and what the input and output are. User placeholders as necessary.]
458
- [If the examples are shorter than what a realistic example is expected to be, make a reference with () explaining how real examples should be longer / shorter / different. AND USE PLACEHOLDERS! ]
459
-
460
- # Notes [optional]
461
-
462
- [optional: edge cases, details, and an area to call or repeat out specific important considerations]
463
-
464
- Only provide the output in the following JSON format enclosed in <json> tags:
465
-
466
- <json>
467
- {
468
- "initial_prompt_evaluation": "Your evaluation of the initial prompt with Strengths and Weaknesses in a string on markdown bullet points format",
469
- "refined_prompt": "Your refined prompt",
470
- "explanation_of_refinements": "Explanation of the techniques used and improvements made, also include the extract of final prompt where it made. Answer in bullet points if accurate"
471
- }
472
- </json>
473
- '''
474
- original_meta_prompt = '''Create an effective prompt from this one:
475
-
476
- Initial Prompt: [Insert initial prompt here]
477
-
478
- Use these simple steps:
479
-
480
- 1. Look at the task closely, focusing on goals, needs, and limits.
481
- 2. Make prompts better by making language clear without changing the main idea.
482
- 3. Keep a logical flow by putting reasoning steps first.
483
- 4. Use good examples with [placeholders] for tricky parts.
484
- 5. Use simple words; remove unneeded instructions.
485
- 6. Use markdown for easy reading; skip code blocks unless needed.
486
- 7. Keep user content like guides and examples.
487
- 8. Add constants like guides and rubrics.
488
- 9. Clearly state output format including structure and syntax.
489
-
490
- Only provide the output in the following JSON format enclosed in <json> tags:
491
-
492
- <json>
493
- {
494
- "initial_prompt_evaluation": "Your evaluation of the initial prompt with Strengths and Weaknesses in a string as bullet points format",
495
- "refined_prompt": "Your refined prompt",
496
- "explanation_of_refinements": "Explanation of the techniques used and improvements made, also include the extract of final prompt where it made. Answer in bullet points if accurate"
497
- }
498
- </json>
499
- '''
500
-
501
- new_meta_prompt = '''Given an initial prompt:
502
-
503
- Initial Prompt: [Insert initial prompt here]
504
-
505
- follow these steps to refine the prompt:
506
-
507
- 1. Analyze the prompt:
508
- - Identify the main topic and key concepts
509
- - Determine the type of task (e.g., math problem, logical reasoning, factual question)
510
- - Assess the complexity and any specific requirements
511
-
512
- 2. Evaluate the initial prompt:
513
- - Determine its strengths and weaknesses in relation to the query
514
- - Identify any missing elements or irrelevant information
515
-
516
- 3. Refine the prompt:
517
- - Retain relevant parts of the initial prompt
518
- - Add query-specific context or information
519
- - Incorporate appropriate reasoning frameworks (e.g., step-by-step, chain-of-thought)
520
- - Ensure clear instructions for the desired output format
521
-
522
- 4. Optimize for information flow:
523
- - Ensure the refined prompt allows for direct use of query information
524
- - Enable indirect information aggregation through prompt-guided reasoning
525
-
526
- 5. Enhance versatility:
527
- - Add elements that encourage flexible thinking and problem-solving
528
- - Include self-evaluation or error-checking instructions if appropriate
529
-
530
- 6. Formulate the refined prompt:
531
- - Combine all elements into a clear, concise, and effective prompt
532
- - Ensure the language and structure are appropriate for the task
533
-
534
- 7. Output the refined prompt:
535
- - Present the new prompt, highlighting key changes or additions
536
-
537
- Only provide the output in the following JSON format enclosed in <json> tags:
538
-
539
- <json>
540
- {
541
- "initial_prompt_evaluation": "Your evaluation of the initial prompt with Strengths and Weaknesses in a string as bullet points format",
542
- "refined_prompt": "Your refined prompt",
543
- "explanation_of_refinements": "Explanation of the techniques used and improvements made, also include the extract of final prompt where it made. Answer in bullet points if accurate"
544
- }
545
- </json>
546
- '''
547
-
548
- advanced_meta_prompt = '''
549
- You are an expert in natural language processing and state-of-the-art prompt engineering. Your task is to refine and improve the given prompt using advanced prompt engineering techniques.
550
-
551
- Initial Prompt: [Insert initial prompt here]
552
-
553
- Analyze the initial prompt and generate an improved version. Apply various prompt engineering techniques to enhance clarity, specificity, and effectiveness. Consider techniques such as:
554
-
555
- 1. Clarity and Specificity
556
- 2. Structural Improvement
557
- 3. Conciseness
558
- 4. Ambiguity Resolution
559
- 5. Instruction Refinement
560
- 6. Query Focusing
561
- 7. Task Decomposition
562
- 8. Role-Playing
563
- 9. Chain-of-Thought
564
- 10. Few-Shot Learning
565
- 11. Constrained Generation
566
- 12. Metacognitive Prompting
567
- 13. Contextual Priming
568
- 14. Negative Prompting
569
- 15. Output Format Control
570
- 16. Emotional Tone Setting
571
- 17. Iterative Refinement
572
- 18. Analogical Reasoning
573
- 19. Perspective Shifting
574
-
575
- Only provide the output in the following JSON format enclosed in <json> tags:
576
-
577
- <json>
578
- {
579
- "initial_prompt_evaluation": "Your evaluation of the initial prompt with Strengths and Weaknesses in a string as bullet points format",
580
- "refined_prompt": "Your refined prompt",
581
- "explanation_of_refinements": "Explanation of the techniques used and improvements made, also include the extract of final prompt where it made. Answer in bullet points if accurate"
582
- }
583
- </json>
584
- '''
585
-
586
  import json
587
  import re
588
  import json
@@ -780,6 +204,16 @@ if __name__ == '__main__':
780
  if not api_token:
781
  raise ValueError("HF_API_TOKEN not found in environment variables")
782
 
 
 
 
 
 
 
 
 
 
 
783
  prompt_refiner = PromptRefiner(api_token)
784
  gradio_interface = GradioInterface(prompt_refiner)
785
  gradio_interface.launch(share=True)
 
7
  from typing import Optional, Literal
8
 
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  import json
11
  import re
12
  import json
 
204
  if not api_token:
205
  raise ValueError("HF_API_TOKEN not found in environment variables")
206
 
207
+
208
+ metadone=os.getenv('metadone')
209
+ echo_prompt_refiner = os.getenv('echo_prompt_refiner')
210
+ metaprompt1 = os.getenv('metaprompt1')
211
+ loic_metaprompt = os.getenv('loic_metaprompt')
212
+ openai_metaprompt=os.getenv('openai_metaprompt')
213
+ original_meta_prompt = os.getenv('original_meta_prompt')
214
+ new_meta_prompt = os.getenv('new_meta_prompt')
215
+ advanced_meta_prompt = os.getenv('advanced_meta_prompt')
216
+
217
  prompt_refiner = PromptRefiner(api_token)
218
  gradio_interface = GradioInterface(prompt_refiner)
219
  gradio_interface.launch(share=True)