File size: 593 Bytes
6d1fe81
 
a4fda78
62b1a00
6d1fe81
 
 
 
 
62b1a00
 
ec3714b
62b1a00
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# uvicorn app:app --host 0.0.0.0 --port 7860 --reload

from fastapi import FastAPI, HTTPException
from starlette.requests import Request

app = FastAPI()

@app.get("/")
def greet_json():
    return {"Hello": "World!"}

@app.post("/airs/v1/chat/completions")
async def chat_completions(request:Request):
    auth_header = request.headers['authorization']
    api_key = auth_header.split()[1]  # 分割字符串并取第二个元素
    if api_key != "iam-tanbushi":
        raise HTTPException(status_code=401, detail="Invalid API Key")
    data = await request.json()
    return {"data": data}