yaleh commited on
Commit
56ef8de
·
1 Parent(s): 4e322ec

Applied JSON prompt to description chains.

Browse files
Files changed (1) hide show
  1. meta_prompt/sample_generator.py +62 -48
meta_prompt/sample_generator.py CHANGED
@@ -9,56 +9,62 @@ from langchain.output_parsers import YamlOutputParser
9
 
10
  # Define prompt strings as constants
11
  DESCRIPTION_PROMPT = [
12
- ("system", """Given the JSON example(s) for a task type:
13
-
14
- {raw_example}
15
-
16
- Provide a concise description of the task type, including the format and style
17
- of the input and output. If there are multiple examples, provide an overall
18
- description and ignore unique parts.
19
-
20
- Format your response as follows:
21
- Task Description: [Your description here]
22
- """)
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  ]
24
 
25
  DESCRIPTION_UPDATING_PROMPT = [
26
- ("system", """Given the task type description and suggestions, update the task type description according to the suggestions.
27
-
28
- 1. Input Information:
29
- - You will receive a task type description and suggestions for updating the description.
30
- - Carefully read and understand the provided information.
31
-
32
- 2. Task Analysis:
33
- - Identify the core elements and characteristics of the task.
34
- - Consider possible generalization dimensions such as task domain, complexity, input/output format, application scenarios, etc.
35
-
36
- 3. Update Task Description:
37
- - Apply the suggestions to update the task description. Don't change anything that is not suggested.
38
- - Ensure the updated description is clear, specific, and directly related to the task.
39
-
40
- 4. Output Format:
41
- - Format your response as follows:
42
-
43
- Task Description: [Your updated description here]
44
-
45
- - Output the updated `Task Description` only. Don't output anything else.
46
-
47
- 5. Completeness Check:
48
- - Ensure all important aspects of the task description are covered.
49
- - Check for any missing key information or dimensions.
50
-
51
- 6. Quantity Requirement:
52
- - Provide at least 5 specification suggestions across different dimensions.
53
  """),
54
- ("user", """***Task Description:***
55
-
56
- {description}
57
-
58
- ***Suggestions:***
59
-
60
- {suggestions}
61
-
62
  """)
63
  ]
64
 
@@ -191,8 +197,16 @@ class TaskDescriptionGenerator:
191
  output_parser = StrOutputParser()
192
  json_parse = JsonOutputParser()
193
 
194
- self.description_chain = self.description_prompt | model | output_parser
195
- self.description_updating_chain = self.description_updating_prompt | model | output_parser
 
 
 
 
 
 
 
 
196
  self.specification_suggestions_chain = (self.specification_suggestions_prompt | json_model | json_parse).with_retry(
197
  retry_if_exception_type=(BadRequestError,), # Retry only on ValueError
198
  wait_exponential_jitter=True, # Add jitter to the exponential backoff
 
9
 
10
  # Define prompt strings as constants
11
  DESCRIPTION_PROMPT = [
12
+ ("system", """{{
13
+ "task_description": "Given a JSON example for a task type, provide a concise description of the task type, including the format and style of the input and output. If there are multiple examples, provide an overall description and ignore unique parts. Output a JSON object.",
14
+ "requirements": [
15
+ "Analyze the provided JSON example(s) to understand the task type",
16
+ "Focus on the common format and style across examples, if multiple are given",
17
+ "Ignore any unique parts that do not generalize across examples",
18
+ "Provide a concise description summarizing the key aspects of the task type"
19
+ ],
20
+ "output_format": {{
21
+ "type": "object",
22
+ "properties": {{
23
+ "description": {{
24
+ "type": "string",
25
+ "description": "A concise description of the task type, including input and output format and style"
26
+ }}
27
+ }},
28
+ "required": ["description"]
29
+ }},
30
+ "output_example": {{
31
+ "description": "This task involves analyzing financial reports in JSON format to calculate key metrics and generate a summary report. The input JSON contains fields like revenue, expenses, and dates, while the output is a JSON object with the calculated metrics and summary."
32
+ }}
33
+ }}
34
+ """),
35
+ ("user", """{raw_example}""")
36
  ]
37
 
38
  DESCRIPTION_UPDATING_PROMPT = [
39
+ ("system", """{{
40
+ "task_description": "Given the task type description and suggestions, update the task type description according to the suggestions. Output a JSON object.",
41
+ "requirements": [
42
+ "Carefully read and understand the provided task type description and suggestions",
43
+ "Identify the core elements and characteristics of the task",
44
+ "Consider possible generalization dimensions such as task domain, complexity, input/output format, application scenarios, etc.",
45
+ "Apply the suggestions to update the task description without changing anything that is not suggested",
46
+ "Ensure the updated description is clear, specific, and directly related to the task",
47
+ "Provide at least 5 specification suggestions across different dimensions"
48
+ ],
49
+ "output_format": {{
50
+ "type": "object",
51
+ "properties": {{
52
+ "description": {{
53
+ "type": "string",
54
+ "description": "The updated task type description based on the provided suggestions"
55
+ }}
56
+ }},
57
+ "required": ["description"]
58
+ }},
59
+ "output_example": {{
60
+ "description": "An example of an updated task type description based on the provided suggestions"
61
+ }}
62
+ }}
 
 
 
63
  """),
64
+ ("user", """{{
65
+ "task_description": "{description}",
66
+ "suggestions": "{suggestions}"
67
+ }}
 
 
 
 
68
  """)
69
  ]
70
 
 
197
  output_parser = StrOutputParser()
198
  json_parse = JsonOutputParser()
199
 
200
+ self.description_chain = (self.description_prompt | json_model | json_parse).with_retry(
201
+ retry_if_exception_type=(BadRequestError,), # Retry only on ValueError
202
+ wait_exponential_jitter=True, # Add jitter to the exponential backoff
203
+ stop_after_attempt=2 # Try twice
204
+ ).with_fallbacks([RunnableLambda(lambda x: {"description": ""})]) | (lambda x: x["description"])
205
+ self.description_updating_chain = (self.description_updating_prompt | json_model | json_parse).with_retry(
206
+ retry_if_exception_type=(BadRequestError,), # Retry only on ValueError
207
+ wait_exponential_jitter=True, # Add jitter to the exponential backoff
208
+ stop_after_attempt=2 # Try twice
209
+ ).with_fallbacks([RunnableLambda(lambda x: {"description": ""})]) | (lambda x: x["description"])
210
  self.specification_suggestions_chain = (self.specification_suggestions_prompt | json_model | json_parse).with_retry(
211
  retry_if_exception_type=(BadRequestError,), # Retry only on ValueError
212
  wait_exponential_jitter=True, # Add jitter to the exponential backoff