refactor: update chat session management to use singleton pattern and enhance validation in chat agent

This commit is contained in:
grillazz
2026-07-14 11:41:15 +02:00
parent 16a2e4e325
commit 251aef0ec4
4 changed files with 121 additions and 14 deletions
+4 -4
View File
@@ -33,11 +33,11 @@ async def lifespan(app: FastAPI):
app.logger = get_logger()
app.redis = await get_redis()
postgres_dsn = global_settings.postgres_url.unicode_string()
# Chat service: initialize the pluggable model-client adapter and the
# in-memory session manager. See app/services/chat_agent.py to swap the
# local stub for a real model client (OpenAI, Ollama, etc.).
# Chat service: initialize the pluggable model-client adapter. The session
# manager is now a singleton and will be auto-instantiated on first access.
# See app/services/chat_agent.py to swap the local stub for a real model
# client (OpenAI, Ollama, etc.).
app.chat_agent = build_chat_agent(global_settings.chat)
app.chat_sessions = ChatSessionManager()
try:
# app.postgres_pool = await asyncpg.create_pool(
# dsn=postgres_dsn,