Add support for image attachments in chat messages and update model capabilities endpoint

This commit is contained in:
2026-04-16 21:27:43 +02:00
parent d8784463b5
commit e88ac88840
5 changed files with 179 additions and 25 deletions

View File

@@ -4,16 +4,15 @@ from sqlalchemy.orm import sessionmaker, DeclarativeBase
from sqlalchemy import text
"""
Database utilities and configuration. This module defines the SQLAlchemy
engine, session factory and base class for models. It also contains a
lightweight migration helper used to evolve the schema over time. The
`ensure_sources_column` helper adds a new `sources_json` column to the
`chat_messages` table if it does not already exist. This is required
for persisting citation sources alongside assistant messages.
Database utilities and configuration. This module defines the SQLAlchemy
engine, session factory and base class for models. It also contains a
lightweight migration helper used to evolve the schema over time. The
`ensure_sources_column` helper adds the JSON-backed columns used by chat
messages when they do not already exist.
The migration uses SQLite's `ALTER TABLE` syntax and therefore should
only run once on startup. It is safe to call repeatedly: when the
column already exists, the function will simply noop.
only run once on startup. It is safe to call repeatedly: when a column
already exists, the function will simply no-op.
"""
DATABASE_URL = "sqlite:///./backend/app.db"
@@ -34,5 +33,7 @@ def ensure_sources_column(engine):
cols = [row[1] for row in conn.execute(text("PRAGMA table_info(chat_messages)"))]
if "sources_json" not in cols:
conn.execute(text("ALTER TABLE chat_messages ADD COLUMN sources_json TEXT DEFAULT '[]'"))
if "attachments_json" not in cols:
conn.execute(text("ALTER TABLE chat_messages ADD COLUMN attachments_json TEXT DEFAULT '[]'"))
except Exception as e:
print("[db] ensure_sources_column error:", e)