|
import os
|
|
from fastapi import FastAPI
|
|
from fastapi.responses import RedirectResponse
|
|
from langchain.globals import set_verbose
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from routers import ask
|
|
import warnings
|
|
|
|
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
|
|
|
set_verbose(True)
|
|
|
|
app = FastAPI()
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
app.include_router(ask.router, prefix="/api")
|
|
|
|
|
|
@app.get("/")
|
|
def redirect_docs():
|
|
return RedirectResponse(url="/docs")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
os.system("uvicorn app:app --port 7860 --host 0.0.0.0")
|
|
except KeyboardInterrupt:
|
|
print("\nBye!\n")
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
|
|
|