Merge pull request #102 from Yidadaa/patch-1

feat: add cors support for openai_api.py
This commit is contained in:
Zhengxiao Du 2023-06-28 23:15:15 +08:00 committed by GitHub
commit 53f0106817
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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