-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
30 lines (22 loc) · 818 Bytes
/
main.py
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
from fastapi import FastAPI
from contextlib import asynccontextmanager
from pydantic import BaseModel
from connectors.db import GraphDBBackend
from connectors.llm import LlmEngine
state = {}
class RequestBody(BaseModel):
question: str
@asynccontextmanager
async def lifespan(app: FastAPI):
# Set up the local LLM And graph database
state["db"] = GraphDBBackend("./location_data")
state["llm"] = LlmEngine("./models/mixtral-8x7b-instruct-v0.1.Q4_K_M.gguf")
yield
app = FastAPI(lifespan=lifespan)
@app.post("/")
async def query_llm(body: RequestBody):
if body.question == "":
return { "error": "Please specify a question" }
query = state["llm"].generate_cypher_statement(state["db"].schema, body.question)
results = state["db"].execute_query(query)
return results