As the title says, I created an API using Ray Serve and FastAPI. The api works fine when I call it using curl
or Postman
, but when I call it through a different web application, I don’t get any response back from the api. The request just goes on forever.
Code:
from fastapi import FastAPI
from ray import serve
import ray
from pydantic import BaseModel
import logging
from fastapi.middleware.cors import CORSMiddleware
from starlette.middleware import Middleware
from starlette.middleware.cors import CORSMiddleware as StarletteCORSMiddleware
logging.basicConfig(level=logging.DEBUG)
app = FastAPI()
origins = [
"*",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
url = '0.0.0.0'
ray.init(namespace="serve", address="auto")
serve.start(detached=True, http_options={"middlewares": [
Middleware(
StarletteCORSMiddleware, allow_origins=["*"], allow_methods=["*"])
]})
class Data(BaseModel):
text: str
action: dict
class Text(BaseModel):
text: str
@serve.deployment
@serve.ingress(app)
class RlClient:
def __init__(self):
self.client = "hello"
@app.get("/health")
def health(self):
return {
"message": "OK!",
}
RlClient.deploy()