|
25 | 25 | parser = argparse.ArgumentParser(description="Top-level command")
|
26 | 26 | subparsers = parser.add_subparsers(
|
27 | 27 | dest="subcommand",
|
28 |
| - help="Use `generate`, `eval` or `export` followed by subcommand specific options.", |
| 28 | + help="Use `generate`, `eval`, `export` or `browser` followed by subcommand specific options.", |
29 | 29 | )
|
30 | 30 |
|
31 | 31 | parser_generate = subparsers.add_parser("generate")
|
|
63 | 63 | elif args.subcommand == "browser":
|
64 | 64 | # TODO: add check_args()
|
65 | 65 |
|
| 66 | + # Look for port from cmd args. Default to 5000 if not found. |
| 67 | + # The port args will be passed directly to the Flask app. |
| 68 | + port = 5000 |
| 69 | + i = 2 |
| 70 | + while i < len(sys.argv): |
| 71 | + # Check if the current argument is '--port' |
| 72 | + if sys.argv[i] == '--port': |
| 73 | + # Check if there's a value immediately following '--port' |
| 74 | + if i + 1 < len(sys.argv): |
| 75 | + # Extract the value and remove '--port' and the value from sys.argv |
| 76 | + port = sys.argv[i + 1] |
| 77 | + del sys.argv[i:i+2] # Delete '--port' and the value |
| 78 | + break # Exit loop since port is found |
| 79 | + else: |
| 80 | + i += 1 |
| 81 | + |
66 | 82 | # Assume the user wants "chat" when entering "browser". TODO: add support for "generate" as well
|
67 | 83 | args_plus_chat = ['"{}"'.format(s) for s in sys.argv[2:]] + ['"--chat"'] + ['"--num-samples"'] + ['"1000000"']
|
68 | 84 | formatted_args = ", ".join(args_plus_chat)
|
69 |
| - command = ["flask", "--app", "chat_in_browser:create_app(" + formatted_args + ")", "run"] |
| 85 | + command = ["flask", "--app", "chat_in_browser:create_app(" + formatted_args + ")", "run", "--port", f"{port}"] |
70 | 86 | subprocess.run(command)
|
71 | 87 | else:
|
72 | 88 | raise RuntimeError("Must specify valid subcommands: generate, export, eval")
|
0 commit comments