-
Notifications
You must be signed in to change notification settings - Fork 431
/
app.py
57 lines (44 loc) · 1.73 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import warnings
import uvicorn
from fastapi import FastAPI, HTTPException
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
from fastapi.middleware.cors import CORSMiddleware
from fastapi.templating import Jinja2Templates
from utils.configs import enable_gateway, api_prefix
warnings.filterwarnings("ignore")
log_config = uvicorn.config.LOGGING_CONFIG
default_format = "%(asctime)s | %(levelname)s | %(message)s"
access_format = r'%(asctime)s | %(levelname)s | %(client_addr)s: %(request_line)s %(status_code)s'
log_config["formatters"]["default"]["fmt"] = default_format
log_config["formatters"]["access"]["fmt"] = access_format
app = FastAPI(
docs_url=f"/{api_prefix}/docs", # 设置 Swagger UI 文档路径
redoc_url=f"/{api_prefix}/redoc", # 设置 Redoc 文档路径
openapi_url=f"/{api_prefix}/openapi.json" # 设置 OpenAPI JSON 路径
)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
templates = Jinja2Templates(directory="templates")
security_scheme = HTTPBearer()
from app import app
import api.chat2api
if enable_gateway:
import gateway.share
import gateway.login
import gateway.chatgpt
import gateway.gpts
import gateway.admin
import gateway.v1
import gateway.backend
else:
@app.api_route("/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD", "PATCH", "TRACE"])
async def reverse_proxy():
raise HTTPException(status_code=404, detail="Gateway is disabled")
if __name__ == "__main__":
uvicorn.run("app:app", host="0.0.0.0", port=5005)
# uvicorn.run("app:app", host="0.0.0.0", port=5005, ssl_keyfile="key.pem", ssl_certfile="cert.pem")