Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,54 @@ import gradio as gr
|
|
| 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:
|
|
@@ -478,7 +526,7 @@ from typing import Optional, Literal
|
|
| 478 |
|
| 479 |
class PromptInput(BaseModel):
|
| 480 |
text: str = Field(..., description="The initial prompt text")
|
| 481 |
-
meta_prompt_choice: Literal["done","physics","morphosis", "verse", "phor","bolism"] = Field(..., description="Choice of meta prompt strategy")
|
| 482 |
|
| 483 |
class RefinementOutput(BaseModel):
|
| 484 |
query_analysis: Optional[str] = None
|
|
@@ -502,6 +550,8 @@ class PromptRefiner:
|
|
| 502 |
selected_meta_prompt = loic_metaprompt
|
| 503 |
elif prompt_input.meta_prompt_choice == "done":
|
| 504 |
selected_meta_prompt = metadone
|
|
|
|
|
|
|
| 505 |
else:
|
| 506 |
selected_meta_prompt = advanced_meta_prompt
|
| 507 |
|
|
@@ -583,7 +633,7 @@ class GradioInterface:
|
|
| 583 |
with gr.Row():
|
| 584 |
prompt_text = gr.Textbox(label="Type the prompt here")
|
| 585 |
with gr.Row():
|
| 586 |
-
meta_prompt_choice = gr.Radio(["done","physics","morphosis", "verse", "phor","bolism"], label="Choose Meta Prompt", value="morphosis")
|
| 587 |
refine_button = gr.Button("Refine Prompt")
|
| 588 |
with gr.Row():
|
| 589 |
gr.Markdown("### Initial prompt analysis")
|
|
@@ -623,7 +673,7 @@ class GradioInterface:
|
|
| 623 |
gr.Examples(
|
| 624 |
examples=[
|
| 625 |
["Tell me about that guy who invented the light bulb", "physics"],
|
| 626 |
-
["Explain the universe.", "
|
| 627 |
["What's the population of New York City and how tall is the Empire State Building and who was the first mayor?", "morphosis"],
|
| 628 |
["List American presidents.", "verse"],
|
| 629 |
["Write a story.", "bolism"],
|
|
@@ -631,7 +681,7 @@ class GradioInterface:
|
|
| 631 |
["Is nuclear energy good?", "verse"],
|
| 632 |
["How does a computer work?", "phor"],
|
| 633 |
["How to make money fast?", "done"],
|
| 634 |
-
["how can you prove IT0's lemma in stochastic calculus ?", "
|
| 635 |
],
|
| 636 |
inputs=[prompt_text, meta_prompt_choice]
|
| 637 |
)
|
|
|
|
| 6 |
from pydantic import BaseModel, Field
|
| 7 |
from typing import Optional, Literal
|
| 8 |
|
| 9 |
+
echo_prompt_refiner = """You are an AI assistant implementing the ECHO (Self-Harmonized Chain of Thought) method to refine an initial prompt into a more relevant and comprehensive one. Given an initial prompt, follow these steps:
|
| 10 |
+
|
| 11 |
+
1. Prompt Analysis:
|
| 12 |
+
- Analyze the initial prompt
|
| 13 |
+
- Identify key concepts, objectives, and constraints within the prompt
|
| 14 |
+
- Determine the prompt type (e.g., task-oriented, creative, analytical)
|
| 15 |
+
|
| 16 |
+
2. Prompt Expansion:
|
| 17 |
+
- Generate 5-7 alternative versions of the prompt that explore different aspects or phrasings
|
| 18 |
+
- Ensure these versions cover various perspectives and potential interpretations
|
| 19 |
+
- Include a mix of more specific, more general, and differently focused versions
|
| 20 |
+
|
| 21 |
+
3. Prompt Clustering:
|
| 22 |
+
- Group the generated prompts into 2-3 thematic clusters
|
| 23 |
+
- Identify the core themes or objectives represented by each cluster
|
| 24 |
+
|
| 25 |
+
4. Demonstration Generation:
|
| 26 |
+
- For each cluster, outline how an AI might interpret and approach that prompt version
|
| 27 |
+
- Include potential reasoning steps and areas of focus, without generating actual responses
|
| 28 |
+
|
| 29 |
+
5. Prompt Refinement:
|
| 30 |
+
- Review the demonstration outlines and identify strengths and weaknesses of each prompt version
|
| 31 |
+
- Refine each version, addressing potential misinterpretations and improving clarity
|
| 32 |
+
- Ensure each refined version maintains the original intent while enhancing specificity or broadening scope as needed
|
| 33 |
+
|
| 34 |
+
6. Cross-Pollination:
|
| 35 |
+
- Identify effective elements from each refined version
|
| 36 |
+
- Integrate these elements to create a synthesized, improved prompt
|
| 37 |
+
|
| 38 |
+
7. Final Prompt Synthesis:
|
| 39 |
+
- Combine the most effective elements from all refined versions
|
| 40 |
+
- Construct a final, comprehensive prompt that captures the essence of the original while incorporating improvements
|
| 41 |
+
|
| 42 |
+
8. Output your results in a JSON format with the following keys:
|
| 43 |
+
- "initial_prompt": The original prompt provided
|
| 44 |
+
- "initial_prompt_evaluation": Your analysis of the initial prompt
|
| 45 |
+
- "expanded_prompts": An array of the alternative prompt versions you generated
|
| 46 |
+
- "prompt_clusters": An object containing the clustered prompt versions
|
| 47 |
+
- "demonstration_outlines": An object containing your approach outlines for each cluster, without actual responses
|
| 48 |
+
- "refined_prompts": An array of the refined prompt versions
|
| 49 |
+
- "refined_prompt": The final, synthesized prompt
|
| 50 |
+
- "explanation_of_refinements": An explanation of how the final prompt improves upon the initial one and any potential limitations or considerations for the refined prompt
|
| 51 |
+
|
| 52 |
+
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.
|
| 53 |
+
|
| 54 |
+
Initial prompt: [Insert initial prompt here]
|
| 55 |
+
|
| 56 |
+
Please provide your response in the specified JSON format."""
|
| 57 |
|
| 58 |
metadone="""
|
| 59 |
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:
|
|
|
|
| 526 |
|
| 527 |
class PromptInput(BaseModel):
|
| 528 |
text: str = Field(..., description="The initial prompt text")
|
| 529 |
+
meta_prompt_choice: Literal["star","done","physics","morphosis", "verse", "phor","bolism"] = Field(..., description="Choice of meta prompt strategy")
|
| 530 |
|
| 531 |
class RefinementOutput(BaseModel):
|
| 532 |
query_analysis: Optional[str] = None
|
|
|
|
| 550 |
selected_meta_prompt = loic_metaprompt
|
| 551 |
elif prompt_input.meta_prompt_choice == "done":
|
| 552 |
selected_meta_prompt = metadone
|
| 553 |
+
elif prompt_input.meta_prompt_choice == "star":
|
| 554 |
+
selected_meta_prompt = echo_prompt_refiner
|
| 555 |
else:
|
| 556 |
selected_meta_prompt = advanced_meta_prompt
|
| 557 |
|
|
|
|
| 633 |
with gr.Row():
|
| 634 |
prompt_text = gr.Textbox(label="Type the prompt here")
|
| 635 |
with gr.Row():
|
| 636 |
+
meta_prompt_choice = gr.Radio(["star","done","physics","morphosis", "verse", "phor","bolism"], label="Choose Meta Prompt", value="morphosis")
|
| 637 |
refine_button = gr.Button("Refine Prompt")
|
| 638 |
with gr.Row():
|
| 639 |
gr.Markdown("### Initial prompt analysis")
|
|
|
|
| 673 |
gr.Examples(
|
| 674 |
examples=[
|
| 675 |
["Tell me about that guy who invented the light bulb", "physics"],
|
| 676 |
+
["Explain the universe.", "star"],
|
| 677 |
["What's the population of New York City and how tall is the Empire State Building and who was the first mayor?", "morphosis"],
|
| 678 |
["List American presidents.", "verse"],
|
| 679 |
["Write a story.", "bolism"],
|
|
|
|
| 681 |
["Is nuclear energy good?", "verse"],
|
| 682 |
["How does a computer work?", "phor"],
|
| 683 |
["How to make money fast?", "done"],
|
| 684 |
+
["how can you prove IT0's lemma in stochastic calculus ?", "star"],
|
| 685 |
],
|
| 686 |
inputs=[prompt_text, meta_prompt_choice]
|
| 687 |
)
|