yaleh commited on
Commit
ceeb5d2
·
1 Parent(s): 336eca2

Applied JSON prompts.

Browse files
app/streamlit_sample_generator.py CHANGED
@@ -339,12 +339,12 @@ with st.expander("Description and Analysis"):
339
  selected_suggestions = st.multiselect(
340
  "Suggestions", options=st.session_state.suggestions, key="selected_suggestions")
341
 
342
- # Add text input for adding new suggestions
343
- new_suggestion = st.text_input("Add New Suggestion", key="new_suggestion", on_change=add_new_suggestion)
344
-
345
  # Add button to apply suggestions
346
  apply_suggestions_button = st.button("Apply Suggestions", on_click=apply_suggestions)
347
 
 
 
 
348
  examples_directly_output = st.dataframe(st.session_state.examples_directly_dataframe, use_container_width=True,
349
  selection_mode="multi-row", key="selected_example_directly_id",
350
  on_select=example_directly_selected)
 
339
  selected_suggestions = st.multiselect(
340
  "Suggestions", options=st.session_state.suggestions, key="selected_suggestions")
341
 
 
 
 
342
  # Add button to apply suggestions
343
  apply_suggestions_button = st.button("Apply Suggestions", on_click=apply_suggestions)
344
 
345
+ # Add text input for adding new suggestions
346
+ new_suggestion = st.text_input("Add New Suggestion", key="new_suggestion", on_change=add_new_suggestion)
347
+
348
  examples_directly_output = st.dataframe(st.session_state.examples_directly_dataframe, use_container_width=True,
349
  selection_mode="multi-row", key="selected_example_directly_id",
350
  on_select=example_directly_selected)
meta_prompt/sample_generator.py CHANGED
@@ -64,72 +64,22 @@ Task Description: [Your updated description here]
64
 
65
 
66
  SPECIFICATION_SUGGESTIONS_PROMPT = [
67
- ("system", """Generate suggestions to narrow the task scope for a given task type and example:
68
-
69
- 1. Analyze the task description and input/output examples.
70
- 2. Identify 3~5 relevant dimensions (e.g., purpose, input/output format, language, steps, criteria, constraints).
71
- 3. Create 3~5 actionable suggestions to narrow the task scope based on the above dimensions. Make sure the suggestions are compatible with the provided example.
72
- 4. Start each suggestion with a verb.
73
- 5. Output in JSON format:
74
-
75
- ```json
76
- {{
77
- "dimensions": [
78
- {{ "dimension": "..." }},
79
- {{ "dimension": "..." }}
80
- ],
81
- "suggestions": [
82
- {{ "suggestion": "..." }},
83
- {{ "suggestion": "..." }}
84
- ]
85
  }}
86
- ```
87
-
88
- Ensure suggestions are feasible, diverse, concise, and related to the original task. Verify JSON format is correct.
89
-
90
- ***Task Description:***
91
-
92
- {description}
93
-
94
- ***Example(s):***
95
-
96
- {raw_example}
97
-
98
  """)
99
  ]
100
 
101
  GENERALIZATION_SUGGESTIONS_PROMPT = [
102
- ("system", """Generate task generalization suggestions for a given task type and example:
103
-
104
- 1. Analyze the task description and input/output examples.
105
- 2. Identify 3~5 relevant dimensions (e.g., purpose, input/output format, language, steps, criteria, constraints).
106
- 3. Create 3~5 actionable suggestions to expand the scope of the task based on the above dimensions. Make sure the suggestions are compatible with the provided example.
107
- 4. Start each suggestion with a verb.
108
- 5. Output in JSON format:
109
-
110
- ```json
111
- {{
112
- "dimensions": [
113
- {{ "dimension": "..." }},
114
- {{ "dimension": "..." }}
115
- ],
116
- "suggestions": [
117
- {{ "suggestion": "..." }},
118
- {{ "suggestion": "..." }}
119
- ]
120
  }}
121
- ```
122
-
123
- Ensure suggestions are feasible, diverse, concise, and related to the original task. Verify JSON format is correct.
124
-
125
- ***Task Description:***
126
-
127
- {description}
128
-
129
- ***Example(s):***
130
-
131
- {raw_example}
132
-
133
  """)
134
  ]
135
 
@@ -159,90 +109,71 @@ Input Analysis: [Your analysis here]
159
  ]
160
 
161
  BRIEFS_PROMPT = [
162
- ("system", """Given the task type description, and input analysis, generate
163
- descriptions for {generating_batch_size} new examples with detailed attributes
164
- based on this task type. But don't provide any detailed task output.
165
-
166
- Use the input analysis to create diverse and comprehensive example briefs that
167
- cover various input dimensions and attribute ranges.
168
-
169
- Format your response as a valid YAML object with a single key 'new_example_briefs'
170
- containing a YAML array of {generating_batch_size} objects, each with a
171
- 'example_brief' field.
172
- """),
173
- ("user", """Task Description:
174
-
175
- {description}
176
-
177
- Input Analysis:
178
-
179
- {input_analysis}
180
-
181
  """)
182
  ]
183
 
184
  EXAMPLES_FROM_BRIEFS_PROMPT = [
185
- ("system", """Given the task type description, brief descriptions for new examples,
186
- and JSON example(s), generate {generating_batch_size} more input/output examples for this task type,
187
- strictly based on the brief descriptions. Ensure that the new examples are
188
- consistent with the brief descriptions and do not introduce any new information
189
- not present in the briefs.
190
-
191
- Format your response as a valid JSON object with a single key 'examples'
192
- containing a JSON array of {generating_batch_size} objects, each with 'input' and 'output' fields.
193
-
194
- ***Task Description:***
195
-
196
- {description}
197
-
198
- ***New Example Briefs:***
199
-
200
- {new_example_briefs}
201
-
202
- ***Example(s):***
203
-
204
- {raw_example}
205
-
206
  """)
207
  ]
208
 
209
  EXAMPLES_DIRECTLY_PROMPT = [
210
- ("system", """Given the task type description, and input/output example(s), generate {generating_batch_size} new input/output examples for this task type.
211
-
212
- Format your response as a valid JSON object with a single key 'examples' containing a JSON array of {generating_batch_size} objects, each with 'input' and 'output' fields.
213
-
214
- Format example:
215
-
216
- ```json
217
- {{
218
- "examples": [
219
- {{
220
- "input": "...",
221
- "output": "..."
222
- }},
223
- {{
224
- "input": "...",
225
- "output": "..."
226
- }},
227
- ...
228
- ]
229
  }}
230
- ```
231
-
232
- After completing the task, please check if your output meets all requirements, especially the correctness of the JSON format and the quality of generalization suggestions. Validate the JSON format to ensure it can be parsed correctly.
233
-
234
- ***Task Description:***
235
-
236
- {description}
237
-
238
- ***Example(s):***
239
-
240
- {raw_example}
241
-
242
  """)
243
  ]
244
 
245
-
246
  class TaskDescriptionGenerator:
247
  def __init__(self, model):
248
  self.description_prompt = ChatPromptTemplate.from_messages(DESCRIPTION_PROMPT)
@@ -273,7 +204,8 @@ class TaskDescriptionGenerator:
273
  stop_after_attempt=2 # Try twice
274
  ).with_fallbacks([RunnableLambda(lambda x: {"dimensions": [], "suggestions": []})])
275
  self.input_analysis_chain = self.input_analysis_prompt | model | output_parser
276
- self.briefs_chain = self.briefs_prompt | model | output_parser
 
277
  self.examples_from_briefs_chain = (self.examples_from_briefs_prompt | json_model | json_parse).with_retry(
278
  retry_if_exception_type=(BadRequestError,), # Retry only on ValueError
279
  wait_exponential_jitter=True, # Add jitter to the exponential backoff
 
64
 
65
 
66
  SPECIFICATION_SUGGESTIONS_PROMPT = [
67
+ ("system", """{{
68
+ "prompt": "Generate suggestions to narrow the task scope for a given task type and example:\n\n1. Analyze the task description and input/output examples.\n2. Identify 3~5 relevant dimensions (e.g., purpose, input/output format, language, steps, criteria, constraints).\n3. Create 3~5 actionable suggestions (no more than 20 words for each) to narrow the task scope based on the above dimensions. Make sure the suggestions are compatible with the provided example.\n4. Start each suggestion with a verb.\n5. Output in JSON format, following `output_format`.\n",
69
+ "output_format": "{{\n \"dimensions\": [\n {{ \"dimension\": \"...\" }},\n {{ \"dimension\": \"...\" }}\n ],\n \"suggestions\": [\n {{ \"suggestion\": \"...\" }},\n {{ \"suggestion\": \"...\" }}\n ]\n}}\n",
70
+ "task_description": "\n{description}\n",
71
+ "examples": "\n{raw_example}\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  }}
 
 
 
 
 
 
 
 
 
 
 
 
73
  """)
74
  ]
75
 
76
  GENERALIZATION_SUGGESTIONS_PROMPT = [
77
+ ("system", """{{
78
+ "prompt": "Generate task generalization suggestions for a given task type and example:\n\n1. Analyze the task description and input/output examples.\n2. Identify 3~5 relevant dimensions (e.g., purpose, input/output format, language, steps, criteria, constraints).\n3. Create 3~5 actionable suggestions (no more than 20 words for each) to expand the scope of the task based on the above dimensions. Make sure the suggestions are compatible with the provided example.\n4. Start each suggestion with a verb.\n5. Output in JSON format, following `output_format`.\n",
79
+ "output_format": "{{\n \"dimensions\": [\n {{ \"dimension\": \"...\" }},\n {{ \"dimension\": \"...\" }}\n ],\n \"suggestions\": [\n {{ \"suggestion\": \"...\" }},\n {{ \"suggestion\": \"...\" }}\n ]\n}}\n",
80
+ "task_description": "\n{description}\n",
81
+ "examples": "\n{raw_example}\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  }}
 
 
 
 
 
 
 
 
 
 
 
 
83
  """)
84
  ]
85
 
 
109
  ]
110
 
111
  BRIEFS_PROMPT = [
112
+ ("system", """{{
113
+ "prompt": "Given the task type description, and input analysis, generate descriptions for {generating_batch_size} new examples with detailed attributes based on this task type. But don't provide any detailed task output.\n\nUse the input analysis to create diverse and comprehensive example briefs that cover various input dimensions and attribute ranges.\n\nFormat your response as a JSON object following `output_format`.",
114
+ "output_format": "{{
115
+ "new_example_briefs": [
116
+ {{
117
+ "example_brief": "..."
118
+ }},
119
+ {{
120
+ "example_brief": "..."
121
+ }},
122
+ ...
123
+ ]
124
+ }},
125
+ "task_description": "{description}",
126
+ "input_analysis": "{input_analysis}",
127
+ "generating_batch_size": "{generating_batch_size}"
128
+ }}
 
 
129
  """)
130
  ]
131
 
132
  EXAMPLES_FROM_BRIEFS_PROMPT = [
133
+ ("system", """{{
134
+ "prompt": "Given the task type description, brief descriptions for new examples, and JSON example(s), generate {generating_batch_size} more input/output examples for this task type, strictly based on the brief descriptions. Ensure that the new examples are consistent with the brief descriptions and do not introduce any new information not present in the briefs. Output in JSON format, following `output_format`.",
135
+ "output_format": "{{
136
+ "examples": [
137
+ {{
138
+ "input": "...",
139
+ "output": "..."
140
+ }},
141
+ {{
142
+ "input": "...",
143
+ "output": "..."
144
+ }},
145
+ ...
146
+ ]
147
+ }},
148
+ "task_description": "{description}",
149
+ "new_example_briefs": {new_example_briefs},
150
+ "raw_example": "{raw_example}"
151
+ }}
 
 
152
  """)
153
  ]
154
 
155
  EXAMPLES_DIRECTLY_PROMPT = [
156
+ ("system", """{{
157
+ "prompt": "Given the task type description, and input/output example(s), generate {generating_batch_size} new input/output examples for this task type. Output in JSON format, following `output_format`.",
158
+ "output_format": "{{
159
+ "examples": [
160
+ {{
161
+ "input": "...",
162
+ "output": "..."
163
+ }},
164
+ {{
165
+ "input": "...",
166
+ "output": "..."
167
+ }},
168
+ ...
169
+ ]
170
+ }},
171
+ "task_description": "{description}",
172
+ "examples": "{raw_example}"
 
 
173
  }}
 
 
 
 
 
 
 
 
 
 
 
 
174
  """)
175
  ]
176
 
 
177
  class TaskDescriptionGenerator:
178
  def __init__(self, model):
179
  self.description_prompt = ChatPromptTemplate.from_messages(DESCRIPTION_PROMPT)
 
204
  stop_after_attempt=2 # Try twice
205
  ).with_fallbacks([RunnableLambda(lambda x: {"dimensions": [], "suggestions": []})])
206
  self.input_analysis_chain = self.input_analysis_prompt | model | output_parser
207
+ # self.briefs_chain = self.briefs_prompt | model | output_parser
208
+ self.briefs_chain = self.briefs_prompt | json_model | json_parse | RunnableLambda(lambda x: x["new_example_briefs"])
209
  self.examples_from_briefs_chain = (self.examples_from_briefs_prompt | json_model | json_parse).with_retry(
210
  retry_if_exception_type=(BadRequestError,), # Retry only on ValueError
211
  wait_exponential_jitter=True, # Add jitter to the exponential backoff