rag-lex / app /server.py
RJuro's picture
-
3026887
raw
history blame contribute delete
994 Bytes
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)