-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
35 lines (28 loc) · 1.17 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from pydantic import BaseModel
from typing import Optional
from sqlalchemy import create_engine, Column, Integer, String, Text, DateTime, ForeignKey
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, relationship
from datetime import datetime
Base = declarative_base()
engine = create_engine('sqlite:///chat_history.db')
SessionLocal = sessionmaker(bind=engine)
class Conversation(Base):
__tablename__ = 'conversations'
id = Column(Integer, primary_key=True)
pdf_name = Column(String(255))
created_at = Column(DateTime, default=datetime.utcnow)
messages = relationship("Message", back_populates="conversation")
class Message(Base):
__tablename__ = 'messages'
id = Column(Integer, primary_key=True)
conversation_id = Column(Integer, ForeignKey('conversations.id'))
role = Column(String(50)) # 'user' or 'assistant'
content = Column(Text)
created_at = Column(DateTime, default=datetime.utcnow)
conversation = relationship("Conversation", back_populates="messages")
# Create tables
Base.metadata.create_all(engine)
class UserRequest(BaseModel):
instruction: str
pdf_file: bytes