mirror of
https://github.com/getzep/graphiti.git
synced 2025-06-27 02:00:02 +00:00
feat: add FastAPI lifespan and healthcheck endpoint (#144)
* chore: Add healthcheck endpoint + build indexes and constraints on svc startup * chore: Bring back driver close call
This commit is contained in:
parent
5d2121e1a3
commit
2fc1b00602
@ -158,8 +158,8 @@ class Graphiti:
|
||||
# Use graphiti...
|
||||
finally:
|
||||
graphiti.close()
|
||||
self.driver.close()
|
||||
"""
|
||||
self.driver.close()
|
||||
|
||||
async def build_indices_and_constraints(self):
|
||||
"""
|
||||
|
@ -1,14 +1,29 @@
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from graph_service.config import get_settings
|
||||
from graph_service.routers import ingest, retrieve
|
||||
from graph_service.zep_graphiti import initialize_graphiti
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(_: FastAPI):
|
||||
settings = get_settings()
|
||||
await initialize_graphiti(settings)
|
||||
yield
|
||||
# Shutdown
|
||||
# No need to close Graphiti here, as it's handled per-request
|
||||
|
||||
|
||||
app = FastAPI(lifespan=lifespan)
|
||||
|
||||
|
||||
app.include_router(retrieve.router)
|
||||
app.include_router(ingest.router)
|
||||
|
||||
|
||||
@app.get('/')
|
||||
def read_root():
|
||||
return {'Hello': 'World'}
|
||||
@app.get('/healthcheck')
|
||||
async def healthcheck():
|
||||
return JSONResponse(content={'status': 'healthy'}, status_code=200)
|
||||
|
@ -82,6 +82,15 @@ async def get_graphiti(settings: ZepEnvDep):
|
||||
client.close()
|
||||
|
||||
|
||||
async def initialize_graphiti(settings: ZepEnvDep):
|
||||
client = ZepGraphiti(
|
||||
uri=settings.neo4j_uri,
|
||||
user=settings.neo4j_user,
|
||||
password=settings.neo4j_password,
|
||||
)
|
||||
await client.build_indices_and_constraints()
|
||||
|
||||
|
||||
def get_fact_result_from_edge(edge: EntityEdge):
|
||||
return FactResult(
|
||||
uuid=edge.uuid,
|
||||
|
Loading…
x
Reference in New Issue
Block a user