A helper function to construct the prompt. Read the code and the related information (e.g. stack_trace) from the a list of commits. Then feed into the prompt constructor. The operation_type is either "mutation" or "crossover". The prompt_constructor is a function with the following s
(config, commits, chunk_size, operation_type)
| 284 | |
| 285 | |
| 286 | def _construct_prompt(config, commits, chunk_size, operation_type) -> str: |
| 287 | """A helper function to construct the prompt. |
| 288 | Read the code and the related information (e.g. stack_trace) from the a list of commits. |
| 289 | Then feed into the prompt constructor. |
| 290 | The operation_type is either "mutation" or "crossover". |
| 291 | The prompt_constructor is a function with the following signature: |
| 292 | def prompt_constructor(operation_type: str, code_infos: List[CodeInfo]) -> str |
| 293 | """ |
| 294 | code_infos = [] |
| 295 | for commit in commits: |
| 296 | code = git.read_file(config, commit) |
| 297 | note = git.read_note(config, commit) |
| 298 | if note is not None: |
| 299 | note = json.loads(note) |
| 300 | if note["timeout"]: |
| 301 | timeout = True |
| 302 | stack_trace = None |
| 303 | else: |
| 304 | timeout = False |
| 305 | try: |
| 306 | stack_trace = json.loads(note["stdout"])["stack_trace"] |
| 307 | except json.JSONDecodeError: |
| 308 | logger.warning( |
| 309 | f"Failed to parse the stack trace of {commit} with note: {note}" |
| 310 | ) |
| 311 | stack_trace = None |
| 312 | import traceback |
| 313 | |
| 314 | traceback.print_exc() |
| 315 | |
| 316 | code_infos.append(CodeInfo(code, stack_trace, timeout)) |
| 317 | |
| 318 | prompts = [] |
| 319 | chunk = [] |
| 320 | for code_info in code_infos: |
| 321 | chunk.append(code_info) |
| 322 | if len(chunk) == chunk_size: |
| 323 | prompts.append(config.prompt_constructor(operation_type, chunk)) |
| 324 | chunk = [] |
| 325 | |
| 326 | return prompts |
| 327 | |
| 328 | |
| 329 | def llm_mutation(config, llm_backend, seeds, commits) -> list[str]: |
no outgoing calls
no test coverage detected