(prompt: str, config, llm_client)
| 9 | |
| 10 | |
| 11 | def rawdog(prompt: str, config, llm_client): |
| 12 | verbose = config.get("dry_run") |
| 13 | retries = int(config.get("retries")) |
| 14 | _continue = True |
| 15 | _first = True |
| 16 | while _continue is True: |
| 17 | error, script, output = "", "", "" |
| 18 | try: |
| 19 | if _first: |
| 20 | message, script = llm_client.get_script(prompt, stream=verbose) |
| 21 | _first = False |
| 22 | else: |
| 23 | message, script = llm_client.get_script(stream=verbose) |
| 24 | if script: |
| 25 | if verbose: |
| 26 | print(f"\n{80 * '-'}") |
| 27 | if ( |
| 28 | input("Execute script in markdown block? (Y/n): ") |
| 29 | .strip() |
| 30 | .lower() |
| 31 | == "n" |
| 32 | ): |
| 33 | llm_client.add_message("user", "User chose not to run script") |
| 34 | break |
| 35 | output, error = execute_script(script, llm_client) |
| 36 | elif message: |
| 37 | print(message) |
| 38 | except KeyboardInterrupt: |
| 39 | break |
| 40 | |
| 41 | _continue = ( |
| 42 | output and output.strip().endswith("CONTINUE") or error and retries > 0 |
| 43 | ) |
| 44 | if error: |
| 45 | retries -= 1 |
| 46 | llm_client.add_message("user", f"Error: {error}") |
| 47 | print(f"Error: {error}") |
| 48 | if script and not verbose: |
| 49 | print(f"{80 * '-'}\n{script}\n{80 * '-'}") |
| 50 | if output: |
| 51 | llm_client.add_message("user", f"LAST SCRIPT OUTPUT:\n{output}") |
| 52 | if verbose or not _continue: |
| 53 | print(output) |
| 54 | |
| 55 | |
| 56 | def banner(): |
no test coverage detected