Add /v1/internal/model/unload endpoint

This commit is contained in:
oobabooga 2023-11-15 15:48:33 -08:00
parent 564d0cde82
commit be125e2708

View File

@ -20,6 +20,7 @@ from fastapi.requests import Request
from fastapi.responses import JSONResponse from fastapi.responses import JSONResponse
from modules import shared from modules import shared
from modules.logging_colors import logger from modules.logging_colors import logger
from modules.models import unload_model
from modules.text_generation import stop_everything_event from modules.text_generation import stop_everything_event
from pydub import AudioSegment from pydub import AudioSegment
from sse_starlette import EventSourceResponse from sse_starlette import EventSourceResponse
@ -285,6 +286,12 @@ async def handle_load_model(request_data: LoadModelRequest):
return HTTPException(status_code=400, detail="Failed to load the model.") return HTTPException(status_code=400, detail="Failed to load the model.")
@app.post("/v1/internal/model/unload")
async def handle_load_model():
unload_model()
return JSONResponse(content="OK")
def run_server(): def run_server():
server_addr = '0.0.0.0' if shared.args.listen else '127.0.0.1' server_addr = '0.0.0.0' if shared.args.listen else '127.0.0.1'
port = int(os.environ.get('OPENEDAI_PORT', shared.args.api_port)) port = int(os.environ.get('OPENEDAI_PORT', shared.args.api_port))