(agent, prompt, num_retries, name_to_hierarchy, visual_identifier='', existing_code='')
| 503 | return fill_content(agent, prompt, num_retries, existing_code) |
| 504 | |
| 505 | def gen_layout(agent, prompt, num_retries, name_to_hierarchy, visual_identifier='', existing_code=''): |
| 506 | if existing_code == '': |
| 507 | existing_code = utils_functions |
| 508 | agent.reset() |
| 509 | log = [] |
| 510 | cumulative_input_token, cumulative_output_token = 0, 0 |
| 511 | for attempt in range(num_retries + 1): |
| 512 | response = agent.step(prompt) |
| 513 | input_token, output_token = account_token(response) |
| 514 | cumulative_input_token += input_token |
| 515 | cumulative_output_token += output_token |
| 516 | new_code = match_response(response) |
| 517 | all_code = existing_code + '\n' + new_code |
| 518 | |
| 519 | # Save visualizations |
| 520 | all_code += f''' |
| 521 | name_to_hierarchy = {name_to_hierarchy} |
| 522 | identifier = "{visual_identifier}" |
| 523 | get_visual_cues(name_to_hierarchy, identifier) |
| 524 | ''' |
| 525 | |
| 526 | output, error = run_code(all_code) |
| 527 | log.append({ |
| 528 | "code": new_code, |
| 529 | "output": output, |
| 530 | "error": error, |
| 531 | "concatenated_code": all_code, |
| 532 | 'num_tokens': (input_token, output_token), |
| 533 | 'cumulative_tokens': (cumulative_input_token, cumulative_output_token) |
| 534 | }) |
| 535 | |
| 536 | if error is None: |
| 537 | return log |
| 538 | |
| 539 | if attempt < num_retries: |
| 540 | print(f"Retrying... Attempt {attempt + 1} of {num_retries}") |
| 541 | prompt = error |
| 542 | return log |
| 543 | |
| 544 | def gen_layout_parallel(agent, prompt, num_retries, existing_code='', slide_width=0, slide_height=0, tmp_name='tmp'): |
| 545 | if existing_code == '': |
no test coverage detected