45 lines
2.1 KiB
Python
45 lines
2.1 KiB
Python
|
|
"""Conversation model."""
|
||
|
|
|
||
|
|
from datetime import datetime
|
||
|
|
from typing import Optional
|
||
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
||
|
|
from sqlalchemy import String, Integer, Text, Boolean, DateTime
|
||
|
|
|
||
|
|
from ..db.base import BaseModel
|
||
|
|
|
||
|
|
class Conversation(BaseModel):
|
||
|
|
"""Conversation model."""
|
||
|
|
|
||
|
|
__tablename__ = "conversations"
|
||
|
|
|
||
|
|
title: Mapped[str] = mapped_column(String(200), nullable=False)
|
||
|
|
user_id: Mapped[int] = mapped_column(Integer, nullable=False) # Removed ForeignKey("users.id")
|
||
|
|
knowledge_base_id: Mapped[Optional[int]] = mapped_column(Integer, nullable=True) # Removed ForeignKey("knowledge_bases.id")
|
||
|
|
system_prompt: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||
|
|
model_name: Mapped[str] = mapped_column(String(100), nullable=False, default="gpt-3.5-turbo")
|
||
|
|
temperature: Mapped[str] = mapped_column(String(10), nullable=False, default="0.7")
|
||
|
|
max_tokens: Mapped[int] = mapped_column(Integer, nullable=False, default=2048)
|
||
|
|
is_archived: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
||
|
|
message_count: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
||
|
|
last_message_at: Mapped[Optional[datetime]] = mapped_column(nullable=True)
|
||
|
|
|
||
|
|
# Relationships removed to eliminate foreign key constraints
|
||
|
|
|
||
|
|
def to_dict(self) -> dict:
|
||
|
|
"""Convert conversation to a dictionary."""
|
||
|
|
return {
|
||
|
|
"id": self.id,
|
||
|
|
"title": self.title,
|
||
|
|
"user_id": self.user_id,
|
||
|
|
"knowledge_base_id": self.knowledge_base_id,
|
||
|
|
"system_prompt": self.system_prompt,
|
||
|
|
"model_name": self.model_name,
|
||
|
|
"temperature": self.temperature,
|
||
|
|
"max_tokens": self.max_tokens,
|
||
|
|
"is_archived": self.is_archived,
|
||
|
|
"message_count": self.message_count,
|
||
|
|
"last_message_at": self.last_message_at,
|
||
|
|
}
|
||
|
|
def __repr__(self):
|
||
|
|
return f"<Conversation(id={self.id}, title='{self.title}', user_id={self.user_id}, system_prompt={self.system_prompt}, model_name='{self.model_name}', temperature='{self.temperature}', message_count={self.message_count})>"
|