mirror of
https://github.com/open-webui/pipelines
synced 2025-06-26 18:15:58 +00:00
feat: cli
This commit is contained in:
70
cli.py
Normal file
70
cli.py
Normal file
@@ -0,0 +1,70 @@
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
import typer
|
||||
|
||||
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
|
||||
def start_process(app: str, host: str, port: int, reload: bool = False):
|
||||
# Start the FastAPI application
|
||||
command = [
|
||||
"uvicorn",
|
||||
app,
|
||||
"--host",
|
||||
host,
|
||||
"--port",
|
||||
str(port),
|
||||
"--forwarded-allow-ips",
|
||||
"*",
|
||||
]
|
||||
|
||||
if reload:
|
||||
command.append("--reload")
|
||||
|
||||
process = subprocess.Popen(command)
|
||||
return process
|
||||
|
||||
|
||||
main = typer.Typer()
|
||||
|
||||
|
||||
@main.command()
|
||||
def serve(
|
||||
host: str = "0.0.0.0",
|
||||
port: int = 9099,
|
||||
):
|
||||
while True:
|
||||
process = start_process("main:app", host, port, reload=False)
|
||||
process.wait()
|
||||
|
||||
if process.returncode == 42:
|
||||
print("Restarting due to restart request")
|
||||
time.sleep(2) # optional delay to prevent tight restart loops
|
||||
else:
|
||||
print("Normal exit, stopping the manager")
|
||||
break
|
||||
|
||||
|
||||
@main.command()
|
||||
def dev(
|
||||
host: str = "0.0.0.0",
|
||||
port: int = 9099,
|
||||
):
|
||||
while True:
|
||||
process = start_process("main:app", host, port, reload=True)
|
||||
process.wait()
|
||||
|
||||
if process.returncode == 42:
|
||||
print("Restarting due to restart request")
|
||||
time.sleep(2) # optional delay to prevent tight restart loops
|
||||
else:
|
||||
print("Normal exit, stopping the manager")
|
||||
break
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user