Spaces:
Runtime error
Runtime error
Download app/db/models/rag_source.py from junaidte14/aiverse: direct link, hf CLI and curl.
- Browser
- Download file 2.57 kB
-
https://huggingface.co/spaces/junaidte14/aiverse/resolve/main/app/db/models/rag_source.py
- Command line
-
hf download hf://spaces/junaidte14/aiverse/app/db/models/rag_source.py
-
curl -L -o rag_source.py https://huggingface.co/spaces/junaidte14/aiverse/resolve/main/app/db/models/rag_source.py
2.57 kB
| """ | |
| RAG Source tracking model | |
| Tracks external sources (GitHub repos, Google Drive folders) | |
| """ | |
| from datetime import datetime, timezone | |
| from sqlalchemy import ( | |
| Column, | |
| Integer, | |
| String, | |
| DateTime, | |
| Boolean, | |
| ForeignKey, | |
| Enum as SQLEnum, | |
| text, | |
| ) | |
| # FIX: Import JSONB for better performance and Pydantic compatibility | |
| from sqlalchemy.dialects.postgresql import JSONB | |
| from sqlalchemy.orm import relationship | |
| import enum | |
| from app.db.base import Base | |
| class SourceType(str, enum.Enum): | |
| """Source type enumeration""" | |
| MANUAL = "manual" | |
| GITHUB = "github" | |
| class SyncStatus(str, enum.Enum): | |
| """Sync status enumeration""" | |
| PENDING = "pending" | |
| IN_PROGRESS = "in_progress" | |
| COMPLETED = "completed" | |
| FAILED = "failed" | |
| class RAGSource(Base): | |
| """ | |
| External source for RAG collections | |
| """ | |
| __tablename__ = "rag_sources" | |
| id = Column(Integer, primary_key=True, index=True) | |
| # Ownership | |
| user_id = Column(Integer, ForeignKey("users.id"), nullable=False) | |
| collection_name = Column(String(255), nullable=False, index=True) | |
| # Source info | |
| source_type = Column(SQLEnum(SourceType), nullable=False) | |
| source_identifier = Column(String(500), nullable=False) | |
| display_name = Column(String(255), nullable=False) | |
| # Sync configuration | |
| auto_sync = Column(Boolean, default=False) | |
| sync_interval_hours = Column(Integer, default=24) | |
| # FIX: Use timezone=True to align with Pydantic's datetime expectations | |
| last_sync_at = Column(DateTime(timezone=True), nullable=True) | |
| last_sync_status = Column(SQLEnum(SyncStatus), default=SyncStatus.PENDING) | |
| last_sync_error = Column(String(1000), nullable=True) | |
| # Statistics | |
| total_files = Column(Integer, default=0) | |
| total_chunks = Column(Integer, default=0) | |
| last_commit_sha = Column(String(255), nullable=True) | |
| # FIX: Change JSON to JSONB and add a default empty dict | |
| # This prevents 'NoneType' errors during dictionary updates in your service[cite: 18] | |
| config = Column(JSONB, nullable=True, server_default=text("'{}'::jsonb")) | |
| # Metadata | |
| # FIX: Use timezone-aware defaults | |
| created_at = Column( | |
| DateTime(timezone=True), | |
| default=lambda: datetime.now(timezone.utc), | |
| nullable=False, | |
| ) | |
| updated_at = Column( | |
| DateTime(timezone=True), | |
| default=lambda: datetime.now(timezone.utc), | |
| onupdate=lambda: datetime.now(timezone.utc), | |
| nullable=False, | |
| ) | |
| # Relationships | |
| user = relationship("User", back_populates="rag_sources") | |