File size: 843 Bytes
7e7a14c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()

# Load settings from.env file


# Initialize LLM
initialize_llm()



# Initialize Pinecone index
index = initialize_pinecone()

# Create query engine
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"}