This content originally appeared on DEV Community and was authored by praveenr
In previous blogs we have seen how to install neo4j, load data into it and query it using natural language. This will be the final blog in this series, we are going to create a simple fastAPI app to expose the setup as an API.
You can find the code here - https://github.com/praveenr2998/Creating-Lightweight-RAG-Systems-With-Graphs/blob/main/fastapi_app/app.py
from fastapi import FastAPI
from pydantic import BaseModel
from query_engine import GraphQueryEngine
# Pydantic model
class QueryRequest(BaseModel):
query: str
app = FastAPI()
@app.post("/process-query/")
async def process_query(request: QueryRequest):
query_engine = GraphQueryEngine()
cypher_queries = query_engine.get_response(request.query)
cypher_queries = query_engine.populate_embedding_in_query(request.query, cypher_queries)
fetched_data = query_engine.fetch_data(cypher_queries)
response = query_engine.get_final_response(request.query, fetched_data)
return {"response": response}
- To run this file use the command
uvicorn app:app --reload
In the terminal you'll be able to see the endpoint in my case it is http://127.0.0.1:8000/ add docs to it to open swagger - http://127.0.0.1:8000/docs
click on the Try it out option to get response for your question, enter you question key of your input json
CURL COMMAND
curl -X 'POST' \
'http://127.0.0.1:8000/process-query/' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"query": "do you have headphones within the price of 25000"
}'
Hope this helps... !!!
LinkedIn - https://www.linkedin.com/in/praveenr2998/
This content originally appeared on DEV Community and was authored by praveenr
praveenr | Sciencx (2024-08-21T14:21:44+00:00) Expose API Using FastAPI. Retrieved from https://www.scien.cx/2024/08/21/expose-api-using-fastapi/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.