File size: 994 Bytes
3026887
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi import FastAPI, Depends, HTTPException, status, Request #added security
from fastapi.responses import RedirectResponse
from langserve import add_routes
from rag_chroma import chain as rag_chroma_chain

from dotenv import load_dotenv
load_dotenv()
# load api key from .env file
import os


app = FastAPI()

API_KEY = os.getenv("BACK_API_KEY")

async def get_api_key(request: Request):
    api_key = request.headers.get('x-api-key')
    if api_key != API_KEY:
        raise HTTPException(
            status_code=status.HTTP_401_UNAUTHORIZED,
            detail="Invalid API Key"
        )

@app.get("/")
async def redirect_root_to_docs():
    return RedirectResponse("/docs")


# Edit this to add the chain you want to add
add_routes(app, rag_chroma_chain, 
           path="/rag-chroma", 
           #playground_type='chat',
           dependencies=[Depends(get_api_key)]
           )

if __name__ == "__main__":
    import uvicorn

    uvicorn.run(app, host="0.0.0.0", port=8000)