(cmd)
| 5 | |
| 6 | |
| 7 | def run_in_subprocess(cmd): |
| 8 | try: |
| 9 | with subprocess.Popen( |
| 10 | cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE |
| 11 | ) as return_info: |
| 12 | while True: |
| 13 | next_line = return_info.stdout.readline() |
| 14 | return_line = next_line.decode("utf-8", "ignore").strip() |
| 15 | if return_line == "" and return_info.poll() != None: |
| 16 | break |
| 17 | if return_line != "": |
| 18 | logging.info(return_line) |
| 19 | |
| 20 | err_lines = "" |
| 21 | while True: |
| 22 | next_line = return_info.stderr.readline() |
| 23 | return_line = next_line.decode("utf-8", "ignore").strip() |
| 24 | if return_line == "" and return_info.poll() != None: |
| 25 | break |
| 26 | if return_line != "": |
| 27 | logging.info(return_line) |
| 28 | err_lines += return_line + "\n" |
| 29 | |
| 30 | return_code = return_info.wait() |
| 31 | if return_code: |
| 32 | raise RuntimeError(err_lines) |
| 33 | except Exception as e: |
| 34 | raise e |
| 35 | |
| 36 | |
| 37 | def simple_openai_api(model): |
no outgoing calls