feat: Implemented memory persistent
This commit is contained in:
@@ -1,11 +1,43 @@
|
||||
from fastapi import FastAPI
|
||||
from naliiabotapi.api.v1.endpoints.chat import router as chat_router
|
||||
from naliiabotapi.api.v1.webhooks.chat_hook import router as chat_hook_router
|
||||
import naliiabotapi.api.dependencies as deps
|
||||
from contextlib import asynccontextmanager
|
||||
from langgraph.checkpoint.postgres.aio import AsyncPostgresSaver
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
deps.db_pool = deps.get_async_connection_pool()
|
||||
await deps.db_pool.open()
|
||||
|
||||
async with deps.db_pool.connection() as conn:
|
||||
checkpointer = AsyncPostgresSaver(conn)
|
||||
await checkpointer.setup()
|
||||
|
||||
model_name = "anthropic"
|
||||
naliia_prompt = deps.get_prompt_template("NALIIA_PROMPT")
|
||||
naliia_tools = deps.NaliiaTools().get_tools()
|
||||
config = deps.AgentConfig(system_prompt=naliia_prompt)
|
||||
model = deps.LLMFactory(model_name).get_model()
|
||||
|
||||
deps.agent_instance = deps.Agent(
|
||||
model=model,
|
||||
config=config,
|
||||
checkpointer=checkpointer,
|
||||
tools=naliia_tools
|
||||
)
|
||||
|
||||
yield
|
||||
|
||||
await deps.db_pool.close()
|
||||
|
||||
|
||||
app = FastAPI(
|
||||
title="NaliiaBot API",
|
||||
description="API for NaliiaBot, a chatbot that provides customer service and related topics.",
|
||||
version="1.0.0"
|
||||
version="1.0.0",
|
||||
lifespan=lifespan
|
||||
)
|
||||
|
||||
app.include_router(chat_router)
|
||||
|
||||
Reference in New Issue
Block a user