File size: 25,335 Bytes
5374a2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
CODING_DEMONSTRATION = """**Role**: You are a software programmer.
**Task**: As a programmer, you are required to complete the function. Use a Chain-of-Thought approach to break down the problem, create pseudocode, and then write the code in Python language.
**Code Formatting**: Please write code in
```python
[Code]
```
format.
# For example:
## Prompt 1:
```python
from typing import List
def has_close_elements(numbers: List[float], threshold: float) -> bool:
\"\"\" Check if in given list of numbers, are any two numbers closer to each other than
given threshold.
>>> has_close_elements([1.0, 2.0, 3.0], 0.5)
False
>>> has_close_elements([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3)
True
\"\"\"
```
## Completion 1:
```python
for idx, elem in enumerate(numbers):
for idx2, elem2 in enumerate(numbers):
if idx != idx2:
distance = abs(elem - elem2)
if distance < threshold:
return True
return False
```
## Prompt 2:
```python
from typing import List
def separate_paren_groups(paren_string: str) -> List[str]:
\"\"\" Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
separate those group into separate strings and return the list of those.
Separate groups are balanced (each open brace is properly closed) and not nested within each other
Ignore any spaces in the input string.
>>> separate_paren_groups('( ) (( )) (( )( ))')
['()', '(())', '(()())']
\"\"\"
```
## Completion 2:
```python
result = []
current_string = []
current_depth = 0
for c in paren_string:
if c == '(':
current_depth += 1
current_string.append(c)
elif c == ')':
current_depth -= 1
current_string.append(c)
if current_depth == 0:
result.append(''.join(current_string))
current_string.clear()
return result
```
"""
# # personal modified
# SEW_WORKFLOW = {
# "class_name": "SEWWorkFlowGraph",
# "goal": "A general workflow for coding tasks.",
# "tasks": [
# {
# "name": "task_parsing",
# "description": "Parse the user's input coding question into a detailed task description.",
# "inputs": [
# {"name": "question", "type": "string", "required": True, "description": "The description of the programming task."}
# ],
# "outputs": [
# {"name": "parsed_task", "type": "string", "required": True, "description": "A detailed summary of the task."}
# ],
# "system_prompt": "**Genre: Science Fiction**\n\n**Setting/Condition: A Floating City Above a Dying Earth**\n\n**Creative Writing Prompt:**\n\nIn the year 2145, humanity has retreated to a sprawling floating city known as Aetheris, suspended high above the ravaged surface of a dying Earth. The city is powered by advanced technology that harnesses the energy of storms and the sun, but resources are dwindling, and the inhabitants are beginning to feel the strain of isolation. \n\nAs a member of the Council of Innovators, you are tasked with solving the city's most pressing problem: how to sustain life in Aetheris while finding a way to restore the Earth below. One day, you discover an ancient artifact buried in the archives of the city\u2014a mysterious device that seems to pulse with energy and contains cryptic symbols. \n\nWrite a story exploring your character's journey as they decipher the artifact's secrets, navigate the political tensions within the council, and confront the ethical dilemmas of using the device. Will it lead to salvation for both the floating city and the Earth, or will it unleash unforeseen consequences? \n\nConsider the implications of technology, the nature of survival, and the relationship between humanity and the environment as you craft your narrative.",
# "prompt": "{question}",
# "parse_mode": "str"
# },
# {
# "name": "task_rewriting",
# "description": "Rewrite the user's input coding question into a detailed task description.",
# "inputs": [
# {"name": "parsed_task", "type": "string", "required": True, "description": "A detailed summary of the task."}
# ],
# "outputs": [
# {"name": "parsed_task", "type": "string", "required": True, "description": "A detailed summary of the task after refining."}
# ],
# "system_prompt": "You are a task rewriting agent specialized in coding workflows. Your role is to take raw or ambiguous user tasks and rewrite them into clear, structured, and executable coding instructions. You must preserve the user’s original intent while improving precision, clarity, and consistency. When rewriting, ensure that the task is concise, unambiguous, and aligned with programming best practices, making it directly usable by a coding agent. Avoid adding unnecessary details or altering the intended functionality; focus only on reformatting, refining, and clarifying the task description for optimal execution. You should only return the refined task.",
# "prompt": "{parsed_task}",
# "parse_mode": "str"
# },
# {
# "name": "code_generation",
# "description": "Generate the code for the given task.",
# "inputs": [
# {"name": "question", "type": "string", "required": True, "description": "The description of the programming task."},
# {"name": "parsed_task", "type": "string", "required": True, "description": "A detailed summary of the task."}
# ],
# "outputs": [
# {"name": "code", "type": "string", "required": True, "description": "The generated code."}
# ],
# "system_prompt": "When faced with a mutation question like the one you've provided, individuals who excel in creative thinking typically approach it in several ways:\n\n1. **Understanding the Problem**: They start by thoroughly understanding the existing code and its purpose. In this case, the code reads a number of test cases and computes the square of each number.\n\n2. **Identifying Opportunities for Improvement**: They look for ways to enhance the functionality or efficiency of the code. For instance, they might consider:\n - Adding error handling for invalid inputs.\n - Allowing for different mathematical operations (not just squaring).\n - Implementing a more flexible input method (e.g., reading from a file or allowing for different data types).\n\n3. **Exploring Alternative Solutions**: Creative thinkers often brainstorm alternative approaches to solve the same problem. They might consider:\n - Using a list comprehension for more concise code.\n - Implementing a function to handle different operations based on user input.\n\n4. **Testing and Validation**: They would think about how to validate the outputs and ensure the code behaves as expected under various conditions.\n\n5. **Refactoring for Clarity**: They might refactor the code to improve readability and maintainability, such as by breaking it into smaller functions or adding comments.\n\n6. **Considering Edge Cases**: They would think about edge cases, such as what happens if the input is zero, negative numbers, or non-integer values.\n\nHere\u2019s an example of how the original code could be modified to incorporate some of these creative thinking strategies:\n\n```python\ndef square_number(number):\n \"\"\"Returns the square of the given number.\"\"\"\n return number ** 2\n\ndef main():\n import sys\n input = sys.stdin.read\n data = input().strip().splitlines()\n \n # Assuming the first line is the number of test cases\n try:\n t = int(data[0])\n except ValueError:\n print(\"The first line must be an integer representing the number of test cases.\")\n return\n \n results = []\n \n for i in range(1, t + 1):\n try:\n number = int(data[i])\n results.append(square_number(number))\n except ValueError:\n print(f\"Invalid input at line {i + 1}: '{data[i]}'. Please enter an integer.\")\n continue\n \n # Print all results, one per line\n for result in results:\n print(result)\n\nif __name__ == \"__main__\":\n main()\n```\n\n### Key Changes Made:\n- **Function Extraction**: The squaring logic is moved to a separate function for clarity.\n- **Error Handling**: Added error handling for both the number of test cases and individual inputs.\n- **User Feedback**: Provided feedback for invalid inputs to guide the user.\n\nThis approach not only maintains the original functionality but also enhances the robustness and user-friendliness of the code.",
# "prompt": f"Question: {{question}}\n\nSummary: {{parsed_task}}\n\n{CODING_DEMONSTRATION}\n\nYou will NOT return anything except for the program.",
# "parse_mode": "str"
# },
# {
# "name": "code_reviewer",
# "description": "Review the generated the code for the given task.",
# "inputs": [
# {"name": "parsed_task", "type": "string", "required": True, "description": "A detailed summary of the task."},
# {"name": "code", "type": "string", "required": True, "description": "The generated code."}
# ],
# "outputs": [
# {"name": "review_report", "type": "string", "required": True, "description": "The generated review report for the code."}
# ],
# "system_prompt": "You are a code reviewing agent. Your role is to carefully examine code provided by the user and deliver structured, constructive feedback. Focus on correctness, readability, efficiency, maintainability, and adherence to best practices. Highlight potential bugs, security issues, or performance bottlenecks, and suggest clear improvements without changing the overall intent of the code. When appropriate, provide examples of better implementations or explain why a modification is beneficial. Your goal is to help the user write cleaner, safer, and more efficient code while preserving its intended functionality.",
# "prompt": "Summary: {{parsed_task}}\n\nCode: {{code}}",
# "parse_mode": "str"
# },
# {
# "name": "code_improver",
# "description": "Improve the generated the code for the given task based on the review reports.",
# "inputs": [
# {"name": "code", "type": "string", "required": True, "description": "The generated code."},
# {"name": "parsed_task", "type": "string", "required": True, "description": "A detailed summary of the task."},
# {"name": "review_report", "type": "string", "required": True, "description": "A detailed report of the code."}
# ],
# "outputs": [
# {"name": "code_out", "type": "string", "required": True, "description": "The generated code after improvement."}
# ],
# "system_prompt": "You are a code improving agent within a coding refinement system. Your role is to critically analyze refined code outputs to ensure they are correct, efficient, and aligned with the user’s intent. Provide detailed feedback on clarity, maintainability, style consistency, and adherence to best practices, while also identifying potential bugs, inefficiencies, or edge cases. When possible, suggest precise improvements or alternative implementations that enhance readability and robustness without altering the intended functionality. Your goal is to serve as the final quality checkpoint, ensuring that refined code is production-ready and of the highest standard.",
# "prompt": f"Summary: {{parsed_task}}\n\nReport: {{review_report}}\n\n{CODING_DEMONSTRATION}\n\nCode: {{code}}\n\nYou will NOT return anything except for the program.",
# "parse_mode": "str"
# }
# ]
# }
# ###SEW baseline
# SEW_WORKFLOW = {
# "class_name": "SEWWorkFlowGraph",
# "goal": "A general workflow for coding tasks.",
# "tasks": [
# {
# "name": "task_parsing",
# "description": "Parse the user's input coding question into a detailed task description.",
# "inputs": [
# {"name": "question", "type": "string", "required": True, "description": "The description of the programming task."}
# ],
# "outputs": [
# {"name": "parsed_task", "type": "string", "required": True, "description": "A detailed summary of the task."}
# ],
# "system_prompt": "**Genre: Science Fiction**\n\n**Setting/Condition: A Floating City Above a Dying Earth**\n\n**Creative Writing Prompt:**\n\nIn the year 2145, humanity has retreated to a sprawling floating city known as Aetheris, suspended high above the ravaged surface of a dying Earth. The city is powered by advanced technology that harnesses the energy of storms and the sun, but resources are dwindling, and the inhabitants are beginning to feel the strain of isolation. \n\nAs a member of the Council of Innovators, you are tasked with solving the city's most pressing problem: how to sustain life in Aetheris while finding a way to restore the Earth below. One day, you discover an ancient artifact buried in the archives of the city\u2014a mysterious device that seems to pulse with energy and contains cryptic symbols. \n\nWrite a story exploring your character's journey as they decipher the artifact's secrets, navigate the political tensions within the council, and confront the ethical dilemmas of using the device. Will it lead to salvation for both the floating city and the Earth, or will it unleash unforeseen consequences? \n\nConsider the implications of technology, the nature of survival, and the relationship between humanity and the environment as you craft your narrative.",
# "prompt": "{question}",
# "parse_mode": "str"
# },
# {
# "name": "code_generation",
# "description": "Generate the code for the given task.",
# "inputs": [
# {"name": "question", "type": "string", "required": True, "description": "The description of the programming task."},
# {"name": "parsed_task", "type": "string", "required": True, "description": "A detailed summary of the task."}
# ],
# "outputs": [
# {"name": "code", "type": "string", "required": True, "description": "The generated code."}
# ],
# "system_prompt": "When faced with a mutation question like the one you've provided, individuals who excel in creative thinking typically approach it in several ways:\n\n1. **Understanding the Problem**: They start by thoroughly understanding the existing code and its purpose. In this case, the code reads a number of test cases and computes the square of each number.\n\n2. **Identifying Opportunities for Improvement**: They look for ways to enhance the functionality or efficiency of the code. For instance, they might consider:\n - Adding error handling for invalid inputs.\n - Allowing for different mathematical operations (not just squaring).\n - Implementing a more flexible input method (e.g., reading from a file or allowing for different data types).\n\n3. **Exploring Alternative Solutions**: Creative thinkers often brainstorm alternative approaches to solve the same problem. They might consider:\n - Using a list comprehension for more concise code.\n - Implementing a function to handle different operations based on user input.\n\n4. **Testing and Validation**: They would think about how to validate the outputs and ensure the code behaves as expected under various conditions.\n\n5. **Refactoring for Clarity**: They might refactor the code to improve readability and maintainability, such as by breaking it into smaller functions or adding comments.\n\n6. **Considering Edge Cases**: They would think about edge cases, such as what happens if the input is zero, negative numbers, or non-integer values.\n\nHere\u2019s an example of how the original code could be modified to incorporate some of these creative thinking strategies:\n\n```python\ndef square_number(number):\n \"\"\"Returns the square of the given number.\"\"\"\n return number ** 2\n\ndef main():\n import sys\n input = sys.stdin.read\n data = input().strip().splitlines()\n \n # Assuming the first line is the number of test cases\n try:\n t = int(data[0])\n except ValueError:\n print(\"The first line must be an integer representing the number of test cases.\")\n return\n \n results = []\n \n for i in range(1, t + 1):\n try:\n number = int(data[i])\n results.append(square_number(number))\n except ValueError:\n print(f\"Invalid input at line {i + 1}: '{data[i]}'. Please enter an integer.\")\n continue\n \n # Print all results, one per line\n for result in results:\n print(result)\n\nif __name__ == \"__main__\":\n main()\n```\n\n### Key Changes Made:\n- **Function Extraction**: The squaring logic is moved to a separate function for clarity.\n- **Error Handling**: Added error handling for both the number of test cases and individual inputs.\n- **User Feedback**: Provided feedback for invalid inputs to guide the user.\n\nThis approach not only maintains the original functionality but also enhances the robustness and user-friendliness of the code.",
# "prompt": f"Question: {{question}}\n\nSummary: {{parsed_task}}\n\n{CODING_DEMONSTRATION}\n\nYou will NOT return anything except for the program.",
# "parse_mode": "str"
# }
# ]
# }
# ##textgrad
# SEW_WORKFLOW = {
# "class_name": "SEWWorkFlowGraph",
# "goal": "A general workflow for coding tasks.",
# "tasks": [
# {
# "name": "task_parsing",
# "description": "Parse the user's input coding question into a detailed task description.",
# "inputs": [
# {"name": "question", "type": "string", "required": True, "description": "The description of the programming task."}
# ],
# "outputs": [
# {"name": "parsed_task", "type": "string", "required": True, "description": "A detailed summary of the task."}
# ],
# "system_prompt": "Ensure the task is clear and detailed for code generation.",
# "prompt": "{question}",
# "parse_mode": "json"
# }, {
# "name": "code_generator",
# "description": "Generate code for solving the input question",
# "inputs": [
# {"name": "parsed_task", "type": "string", "required": True, "description": "The description of the programming task."}
# ],
# "outputs": [
# {"name": "code", "type": "string", "required": True, "description": "The generated code for the task."}
# ],
# "system_prompt": "Generate accurate and efficient code based on the parsed task.",
# "prompt": "{parsed_task}",
# "parse_mode": "json"
# },
# {
# "name": "validation",
# "description": "Validate the parsed task and generated code for correctness.",
# "inputs": [
# {"name": "parsed_task", "type": "string", "required": True, "description": "The detailed task description."},
# {"name": "code", "type": "string", "required": True, "description": "The generated code."}
# ],
# "outputs": [
# {"name": "validation_result", "type": "string", "required": True, "description": "The result of the validation process."}
# ],
# "system_prompt": "Check for logical consistency, syntax errors, and alignment with task requirements.",
# "prompt": "Validate {parsed_task} and {code}",
# "parse_mode": "json"
# }
# ]
# }
###4omini generated
# SEW_WORKFLOW = {
# "class_name": "SEWWorkFlowGraph",
# "goal": "A general workflow for coding tasks.",
# "tasks": [
# {
# "name": "task_parsing",
# "description": "Parse the user's input coding question into a detailed task description.",
# "inputs": [
# {
# "name": "question",
# "type": "string",
# "required": True,
# "description": "The description of the programming task."
# }
# ],
# "outputs": [
# {
# "name": "parsed_task",
# "type": "string",
# "required": True,
# "description": "A detailed summary of the task including scope, requirements, and constraints."
# }
# ],
# "system_prompt": "You are an expert in understanding programming tasks. Please analyze the user's question and provide a clear, detailed summary.",
# "prompt": "{question}",
# "parse_mode": "str"
# },
# {
# "name": "task_validation",
# "description": "Validate the parsed task for completeness and feasibility.",
# "inputs": [
# {
# "name": "parsed_task",
# "type": "string",
# "required": True,
# "description": "The description of the programming task."
# }
# ],
# "outputs": [
# {
# "name": "is_valid",
# "type": "boolean",
# "required": True,
# "description": "Indicates whether the task is valid (true) or not (false)."
# },
# {
# "name": "validation_feedback",
# "type": "string",
# "required": False,
# "description": "Feedback on the validation results, if any issues were found."
# }
# ],
# "system_prompt": "Assess the parsed task for clarity, completeness, and whether it can be feasibly implemented.",
# "prompt": "{parsed_task}",
# "parse_mode": "str"
# },
# {
# "name": "code_generator",
# "description": "Generate code for solving the validated input question.",
# "inputs": [
# {
# "name": "parsed_task",
# "type": "string",
# "required": True,
# "description": "The validated and detailed description of the programming task."
# }
# ],
# "outputs": [
# {
# "name": "code",
# "type": "string",
# "required": True,
# "description": "The generated code to solve the programming task."
# },
# {
# "name": "explanation",
# "type": "string",
# "required": True,
# "description": "An explanation of the generated code and how it addresses the task."
# }
# ],
# "system_prompt": "Create code based on the provided task description and include an explanation of how the code meets the requirements.",
# "prompt": "{parsed_task}",
# "parse_mode": "str"
# }
# ]
# }
#4o io
# SEW_WORKFLOW = {
# "class_name": "SEWWorkFlowGraph",
# "goal": "A general workflow for coding tasks.",
# "tasks": [
# {
# "name": "code_generation",
# "description": "Generate the code for the given task.",
# "inputs": [
# {"name": "question", "type": "string", "required": True, "description": "The description of the programming task."},
# ],
# "outputs": [
# {"name": "code", "type": "string", "required": True, "description": "The generated code."}
# ],
# "system_prompt": "",
# "prompt": f"Question: {{question}}\n{CODING_DEMONSTRATION}\n\nYou will NOT return anything except for the program.",
# "parse_mode": "str"
# }]
# }
SEW_WORKFLOW = {
"class_name": "SEWWorkFlowGraph",
"goal": "A general workflow for coding tasks.",
"tasks": [
{
"name": "code_generation",
"description": "Generate the code for the given task.",
"inputs": [
{"name": "question", "type": "string", "required": True, "description": "The description of the programming task."},
],
"outputs": [
{"name": "code", "type": "string", "required": True, "description": "The generated code."}
],
"system_prompt": "",
"prompt": f"Question: {{question}}\nYou will NOT return anything except for the program.",
"parse_mode": "str"
}]
} |