Browse Source

feat: add cors support for openai_api.py

pull/102/head
Yifei Zhang 1 year ago committed by GitHub
parent
commit
6fa53c645e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      openai_api.py

8
openai_api.py

@ -9,6 +9,7 @@ import torch
import uvicorn import uvicorn
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
from fastapi import FastAPI, HTTPException from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
from starlette.responses import StreamingResponse from starlette.responses import StreamingResponse
from typing import Any, Dict, List, Literal, Optional, Union from typing import Any, Dict, List, Literal, Optional, Union
@ -25,6 +26,13 @@ async def lifespan(app: FastAPI): # collects GPU memory
app = FastAPI(lifespan=lifespan) app = FastAPI(lifespan=lifespan)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
class ModelCard(BaseModel): class ModelCard(BaseModel):
id: str id: str

Loading…
Cancel
Save