baconnier commited on
Commit
b952eb2
1 Parent(s): 0ae518b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -29
app.py CHANGED
@@ -6,16 +6,6 @@ import gradio as gr
6
  from pydantic import BaseModel, Field
7
  from typing import Optional, Literal
8
 
9
- metaprompt_explanations = {
10
- "star": "The ECHO (Enhanced Chain of Harmonized Optimization) method, which provides a comprehensive and structured approach to prompt refinement, including multiple stages of analysis, expansion, and synthesis.",
11
- "done": "A detailed, multi-step approach that emphasizes role-playing, structured output, and various advanced prompting techniques like Chain-of-Thought and Tree of Thoughts.",
12
- "physics": "A prompt enhancement method that focuses on role-playing, structured output, and incorporating multiple advanced prompting techniques such as Chain-of-Thought and Tree of Thoughts.",
13
- "morphosis": "A simplified approach that focuses on clear language, logical flow, and essential elements of prompt engineering without complex techniques.",
14
- "verse": "A structured method that emphasizes analyzing the initial prompt, evaluating its strengths and weaknesses, and refining it with a focus on information flow and versatility.",
15
- "phor": "An advanced prompt engineering approach that combines multiple techniques, including clarity enhancement, structural improvement, and various specialized prompting methods like Chain-of-Thought and Few-Shot Learning.",
16
- "bolism": "A prompt refinement method that emphasizes leveraging the autoregressive nature of language models, encouraging reasoning before conclusions, and providing detailed instructions for output formatting."
17
- }
18
-
19
  class PromptInput(BaseModel):
20
  text: str = Field(..., description="The initial prompt text")
21
  meta_prompt_choice: Literal["star","done","physics","morphosis", "verse", "phor","bolism"] = Field(..., description="Choice of meta prompt strategy")
@@ -26,7 +16,6 @@ class RefinementOutput(BaseModel):
26
  refined_prompt: Optional[str] = None
27
  explanation_of_refinements: Optional[str] = None
28
  raw_content: Optional[str] = None
29
- metaprompt_explanation: Optional[str] = None # New field
30
 
31
  class PromptRefiner:
32
  def __init__(self, api_token: str):
@@ -53,10 +42,10 @@ class PromptRefiner:
53
  {"role": "user", "content": selected_meta_prompt.replace("[Insert initial prompt here]", prompt_input.text)}
54
  ]
55
  response = self.client.chat_completion(
56
- model="meta-llama/Meta-Llama-3-70B-Instruct",
57
  messages=messages,
58
- max_tokens=4000,
59
- temperature=0.3
60
  )
61
  response_content = response.choices[0].message.content.strip()
62
  try:
@@ -71,10 +60,6 @@ class PromptRefiner:
71
  for key, value in json_output.items():
72
  if isinstance(value, str):
73
  json_output[key] = value.replace('\\"', '"')
74
-
75
- # Add the metaprompt explanation to the output
76
- json_output['metaprompt_explanation'] = metaprompt_explanations.get(prompt_input.meta_prompt_choice, "")
77
-
78
  return RefinementOutput(**json_output, raw_content=response_content)
79
  else:
80
  raise ValueError("No JSON found in the response")
@@ -89,10 +74,6 @@ class PromptRefiner:
89
  output[key] = match.group(1).replace('\\n', '\n').replace('\\"', '"')
90
  else:
91
  output[key] = ""
92
-
93
- # Add the metaprompt explanation to the output
94
- output['metaprompt_explanation'] = metaprompt_explanations.get(prompt_input.meta_prompt_choice, "")
95
-
96
  return RefinementOutput(**output, raw_content=response_content)
97
 
98
  def apply_prompt(self, prompt: str, model: str) -> str:
@@ -138,17 +119,14 @@ class GradioInterface:
138
  gr.Markdown("### Explanation of Refinements")
139
  explanation_of_refinements = gr.Markdown(label="Explanation of Refinements")
140
 
141
- with gr.Row():
142
- gr.Markdown("### Metaprompt Explanation")
143
- metaprompt_explanation = gr.Markdown(label="Metaprompt Explanation")
144
-
145
  with gr.Accordion("Full Response JSON", open=False,visible=False):
146
  full_response_json = gr.JSON()
147
 
 
148
  refine_button.click(
149
  fn=self.refine_prompt,
150
  inputs=[prompt_text, meta_prompt_choice],
151
- outputs=[analysis_evaluation, refined_prompt, explanation_of_refinements, full_response_json, metaprompt_explanation]
152
  )
153
  with gr.Row():
154
  apply_model = gr.Dropdown(
@@ -203,8 +181,7 @@ class GradioInterface:
203
  analysis_evaluation,
204
  result.refined_prompt,
205
  result.explanation_of_refinements,
206
- result.dict(),
207
- result.metaprompt_explanation
208
  )
209
 
210
  def apply_prompts(self, original_prompt: str, refined_prompt: str, model: str):
 
6
  from pydantic import BaseModel, Field
7
  from typing import Optional, Literal
8
 
 
 
 
 
 
 
 
 
 
 
9
  class PromptInput(BaseModel):
10
  text: str = Field(..., description="The initial prompt text")
11
  meta_prompt_choice: Literal["star","done","physics","morphosis", "verse", "phor","bolism"] = Field(..., description="Choice of meta prompt strategy")
 
16
  refined_prompt: Optional[str] = None
17
  explanation_of_refinements: Optional[str] = None
18
  raw_content: Optional[str] = None
 
19
 
20
  class PromptRefiner:
21
  def __init__(self, api_token: str):
 
42
  {"role": "user", "content": selected_meta_prompt.replace("[Insert initial prompt here]", prompt_input.text)}
43
  ]
44
  response = self.client.chat_completion(
45
+ model=prompt_refiner_model,
46
  messages=messages,
47
+ max_tokens=2000,
48
+ temperature=0.8
49
  )
50
  response_content = response.choices[0].message.content.strip()
51
  try:
 
60
  for key, value in json_output.items():
61
  if isinstance(value, str):
62
  json_output[key] = value.replace('\\"', '"')
 
 
 
 
63
  return RefinementOutput(**json_output, raw_content=response_content)
64
  else:
65
  raise ValueError("No JSON found in the response")
 
74
  output[key] = match.group(1).replace('\\n', '\n').replace('\\"', '"')
75
  else:
76
  output[key] = ""
 
 
 
 
77
  return RefinementOutput(**output, raw_content=response_content)
78
 
79
  def apply_prompt(self, prompt: str, model: str) -> str:
 
119
  gr.Markdown("### Explanation of Refinements")
120
  explanation_of_refinements = gr.Markdown(label="Explanation of Refinements")
121
 
 
 
 
 
122
  with gr.Accordion("Full Response JSON", open=False,visible=False):
123
  full_response_json = gr.JSON()
124
 
125
+
126
  refine_button.click(
127
  fn=self.refine_prompt,
128
  inputs=[prompt_text, meta_prompt_choice],
129
+ outputs=[analysis_evaluation, refined_prompt, explanation_of_refinements, full_response_json]
130
  )
131
  with gr.Row():
132
  apply_model = gr.Dropdown(
 
181
  analysis_evaluation,
182
  result.refined_prompt,
183
  result.explanation_of_refinements,
184
+ result.dict()
 
185
  )
186
 
187
  def apply_prompts(self, original_prompt: str, refined_prompt: str, model: str):