Spaces:
Running
Running
Applied JSON prompt to description chains.
Browse files- 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", """
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
description
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
]
|
24 |
|
25 |
DESCRIPTION_UPDATING_PROMPT = [
|
26 |
-
("system", """
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
6. Quantity Requirement:
|
52 |
-
- Provide at least 5 specification suggestions across different dimensions.
|
53 |
"""),
|
54 |
-
("user", """
|
55 |
-
|
56 |
-
{
|
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 |
|
195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|