Download fastapi-backend/app/models/bot.py from APIMoral/README: direct link, hf CLI and curl.
- Browser
- Download file 3.73 kB
-
https://huggingface.co/spaces/APIMoral/README/resolve/main/fastapi-backend/app/models/bot.py
- Command line
-
hf download hf://spaces/APIMoral/README/fastapi-backend/app/models/bot.py
-
curl -L -o bot.py https://huggingface.co/spaces/APIMoral/README/resolve/main/fastapi-backend/app/models/bot.py
3.73 kB
| from sqlalchemy import Column, String, Text, Boolean, DateTime, ForeignKey, JSON | |
| from sqlalchemy.sql import func | |
| from sqlalchemy.orm import relationship | |
| from app.database import Base | |
| import uuid | |
| class Bot(Base): | |
| __tablename__ = "bots" | |
| id = Column(String(36), primary_key=True, default=lambda: str(uuid.uuid4())) | |
| owner_id = Column(String(36), ForeignKey("users.id"), nullable=False) | |
| name = Column(String(255), nullable=False) | |
| description = Column(Text, nullable=True) | |
| # System Prompt settings | |
| role = Column(Text, nullable=True) # "Ты - заботливый администратор..." | |
| tabo = Column(Text, nullable=True) # Список ограничений | |
| script = Column(Text, nullable=True) # Скрипт сбора лида | |
| # Widget customization | |
| widget_color = Column(String(7), default="#007bff") # Hex color | |
| widget_logo = Column(String(500), nullable=True) # URL лого | |
| welcome_message = Column(String(500), default="Привет! Чем могу помочь?") | |
| # Notifications | |
| telegram_bot_token = Column(String(255), nullable=True) # Telegram bot token | |
| telegram_chat_id = Column(String(255), nullable=True) # Chat ID for notifications | |
| webhook_url = Column(String(500), nullable=True) # Webhook URL for CRM | |
| # Settings | |
| is_active = Column(Boolean, default=True) | |
| notify_on_lead = Column(Boolean, default=True) | |
| notify_on_operator_request = Column(Boolean, default=True) | |
| created_at = Column(DateTime(timezone=True), server_default=func.now()) | |
| updated_at = Column(DateTime(timezone=True), onupdate=func.now()) | |
| # Relationships | |
| owner = relationship("User", backref="bots") | |
| documents = relationship("Document", backref="bot", cascade="all, delete-orphan") | |
| conversations = relationship("Conversation", backref="bot", cascade="all, delete-orphan") | |
| class Document(Base): | |
| __tablename__ = "documents" | |
| id = Column(String(36), primary_key=True, default=lambda: str(uuid.uuid4())) | |
| bot_id = Column(String(36), ForeignKey("bots.id"), nullable=False) | |
| name = Column(String(255), nullable=False) | |
| content = Column(Text, nullable=False) #Parsed text content | |
| file_type = Column(String(50), nullable=True) # txt, pdf, url | |
| file_path = Column(String(500), nullable=True) # Original file path | |
| # Chunking info | |
| chunks = Column(JSON, nullable=True) # List of chunk texts | |
| created_at = Column(DateTime(timezone=True), server_default=func.now()) | |
| class Conversation(Base): | |
| __tablename__ = "conversations" | |
| id = Column(String(36), primary_key=True, default=lambda: str(uuid.uuid4())) | |
| bot_id = Column(String(36), ForeignKey("bots.id"), nullable=False) | |
| session_id = Column(String(36), index=True) # Unique session per user | |
| created_at = Column(DateTime(timezone=True), server_default=func.now()) | |
| updated_at = Column(DateTime(timezone=True), onupdate=func.now()) | |
| # Lead info | |
| lead_name = Column(String(255), nullable=True) | |
| lead_phone = Column(String(50), nullable=True) | |
| lead_email = Column(String(255), nullable=True) | |
| lead_status = Column(String(50), default="new") # new, warm, hot, converted | |
| messages = relationship("Message", backref="conversation", cascade="all, delete-orphan") | |
| class Message(Base): | |
| __tablename__ = "messages" | |
| id = Column(String(36), primary_key=True, default=lambda: str(uuid.uuid4())) | |
| conversation_id = Column(String(36), ForeignKey("conversations.id"), nullable=False) | |
| role = Column(String(20), nullable=False) # user, assistant, system | |
| content = Column(Text, nullable=False) | |
| created_at = Column(DateTime(timezone=True), server_default=func.now()) | |