feat: support pass args before init web app

as title

Former-commit-id: b2874a72e48bb7eb50567a2dd7a2ee352f60a226
This commit is contained in:
Ehco 2023-07-20 21:49:26 +08:00 committed by GitHub
parent 6552b74005
commit 14db5c4cfe

View File

@ -30,9 +30,7 @@ async def lifespan(app: FastAPI): # collects GPU memory
torch_gc() torch_gc()
def create_app(): def create_app(chat_model: ChatModel):
chat_model = ChatModel(*get_infer_args())
app = FastAPI(lifespan=lifespan) app = FastAPI(lifespan=lifespan)
app.add_middleware( app.add_middleware(
@ -124,5 +122,6 @@ def create_app():
if __name__ == "__main__": if __name__ == "__main__":
app = create_app() chat_model = ChatModel(*get_infer_args())
app = create_app(chat_model)
uvicorn.run(app, host="0.0.0.0", port=8000, workers=1) uvicorn.run(app, host="0.0.0.0", port=8000, workers=1)