|
from fastapi import FastAPI, HTTPException
|
|
from pydantic import BaseModel
|
|
from typing import Optional
|
|
|
|
from rag_retriever import initialize_llm, initialize_pinecone, create_query_engine, get_response
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
|
|
initialize_llm()
|
|
|
|
|
|
|
|
|
|
index = initialize_pinecone()
|
|
|
|
|
|
query_engine = create_query_engine(index)
|
|
|
|
class QueryRequest(BaseModel):
|
|
query: str
|
|
|
|
@app.post("/query")
|
|
async def query(query_request: QueryRequest):
|
|
try:
|
|
response = get_response(query_engine, query_request.query)
|
|
return {"response": response}
|
|
except Exception as e:
|
|
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
@app.get("/healthcheck")
|
|
async def healthcheck():
|
|
return {"status": "ok"}
|
|
|
|
|