Skip to content

Commit 30045ed

Browse files
Olivia-liumalfet
authored andcommitted
Fix the --port arg for browser mode (#447)
* fix port for browser command * fix port
1 parent de9c414 commit 30045ed

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ Run a chatbot in your browser that’s supported by the model you specify in the
146146
**Examples**
147147

148148
```
149-
python3 torchchat.py browser stories15M --temperature 0 --num-samples 10
149+
python3 torchchat.py browser stories15M --temperature 0 --num-samples 100
150150
```
151151

152-
*Running on http://127.0.0.1:5000* should be printed out on the terminal. Click the link or go to [http://127.0.0.1:5000](http://127.0.0.1:5000) on your browser to start interacting with it.
152+
*Running on http://127.0.0.1:5000* should be printed out on the terminal. Click the link or go to [http://127.0.0.1:5000](http://127.0.0.1:5000) on your browser to start interacting with it. If port 5000 has already been taken, run the command again with `--port`, e.g. `--port 5001`.
153153

154154
Enter some text in the input box, then hit the enter key or click the “SEND” button. After a second or two, the text you entered together with the generated text will be displayed. Repeat to have a conversation.
155155

cli.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ def add_arguments_for_chat(parser):
3636
def add_arguments_for_browser(parser):
3737
# Only browser specific options should be here
3838
_add_arguments_common(parser)
39-
parser.add_argument(
40-
"--port", type=int, default=5000, help="Port for the web server in browser mode"
41-
)
42-
_add_arguments_common(parser)
4339

4440

4541
def add_arguments_for_download(parser):
@@ -294,6 +290,12 @@ def add_arguments(parser):
294290
default=".model-artifacts",
295291
help="The directory to store downloaded model artifacts",
296292
)
293+
parser.add_argument(
294+
"--port",
295+
type=int,
296+
default=5000,
297+
help="Port for the web server in browser mode",
298+
)
297299

298300

299301
def arg_init(args):

torchchat.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,15 @@
125125
check_args(args, "browser")
126126

127127
# Look for port from cmd args. Default to 5000 if not found.
128-
# The port args will be passed directly to the Flask app.
129128
port = 5000
130129
i = 2
131130
while i < len(sys.argv):
132-
# Check if the current argument is '--port'
133131
if sys.argv[i] == "--port":
134-
# Check if there's a value immediately following '--port'
135132
if i + 1 < len(sys.argv):
136133
# Extract the value and remove '--port' and the value from sys.argv
137134
port = sys.argv[i + 1]
138-
del sys.argv[i : i + 2] # Delete '--port' and the value
139-
break # Exit loop since port is found
135+
del sys.argv[i : i + 2]
136+
break
140137
else:
141138
i += 1
142139

0 commit comments

Comments
 (0)