I am a bit confused by the new FastAPI HTTP Deployment and I am having trouble getting it running with my existing application.
I am currently running my application with uvicorn on port 8080
. I am able to launch serve with http_options=dict(location='NoServer")
I tried using APIRouter and the app instance, but I keep on getting an error
ray.serve.exceptions.RayServeException:
serve.get_replica_context() may only be called from within a Ray Serve backend.
serve is started as follows:
ray.init(address="auto", ignore_reinit_error=True, namespace="serve")
serve.start(
http_options=dict(location="NoServer"), detached=True,
)
FastAPI is started as follows:
ray.init(address="auto", ignore_reinit_error=True, namespace="serve")
uvicorn.run(
"app:app", port=project_config.app.port, log_level=project_config.app.log_level
)
My code is taken from the example:
from fastapi import FastAPI
from ray import serve
app = FastAPI()
@serve.deployment(name="deployment", route_prefix="/api")
@serve.ingress(app)
class MyFastAPIDeployment:
@app.get("/")
def root_handler(self):
return "hello from /api"
@app.get("/{subpath}")
def subpath_handler(self, subpath: str):
return f"hello from /{subpath}"
MyFastAPIDeployment.deploy()