From 42669bdebe8617728ad5eb9a4065bda388bbe3d3 Mon Sep 17 00:00:00 2001 From: Lukas Holzner Date: Mon, 30 Sep 2024 20:19:25 +0200 Subject: [PATCH] Fixed Bugs --- backend/app/database.py | 3 ++- backend/app/models.py | 22 ++++++++-------------- backend/app/routers/meetings.py | 12 ++++++------ backend/app/schemas.py | 15 ++++++--------- backend/app/util/openai.py | 9 +++++---- 5 files changed, 27 insertions(+), 34 deletions(-) diff --git a/backend/app/database.py b/backend/app/database.py index 6188d5b..cfd7dd0 100644 --- a/backend/app/database.py +++ b/backend/app/database.py @@ -18,4 +18,5 @@ def get_db(): try: yield db finally: - db.close() \ No newline at end of file + db.close() + diff --git a/backend/app/models.py b/backend/app/models.py index 2a15a70..c0bc302 100644 --- a/backend/app/models.py +++ b/backend/app/models.py @@ -26,21 +26,13 @@ class Meeting(Base): title = Column(String, index=True) description = Column(String) date = Column(DateTime) - meeting_type_id = Column(Integer, ForeignKey("meeting_types.id")) + meeting_type = Column(String) # Change this to a String column - # Update this relationship - users = relationship("User", secondary=user_meeting, back_populates="meetings") - meeting_type = relationship("MeetingType", back_populates="meetings") - conversations = relationship("Conversation", back_populates="meeting") -class MeetingType(Base): - __tablename__ = "meeting_types" - - id = Column(Integer, primary_key=True, index=True) - name = Column(String, unique=True, index=True) - system_prompt = Column(Text) - - meetings = relationship("Meeting", back_populates="meeting_type") + # Add this relationship + users = relationship("User", secondary="user_meeting", back_populates="meetings") + # Add this relationship + conversations = relationship("Conversation", back_populates="meeting") class Conversation(Base): __tablename__ = "conversations" @@ -48,6 +40,7 @@ class Conversation(Base): id = Column(Integer, primary_key=True, index=True) user_id = Column(Integer, ForeignKey("users.id")) meeting_id = Column(Integer, ForeignKey("meetings.id")) + system_prompt = Column(String, default="Test", nullable=True) user = relationship("User", back_populates="conversations") meeting = relationship("Meeting", back_populates="conversations") @@ -73,6 +66,7 @@ class MeetingAgenda(Base): completed = Column(Boolean, default=False) conversation_id = Column(Integer, ForeignKey("conversations.id")) - conversation = relationship("Conversation", back_populates="meeting_agenda") + conversation = relationship("Conversation", back_populates="meeting_agenda") + diff --git a/backend/app/routers/meetings.py b/backend/app/routers/meetings.py index 9c6fbab..3bffbe4 100644 --- a/backend/app/routers/meetings.py +++ b/backend/app/routers/meetings.py @@ -2,7 +2,7 @@ from sqlalchemy.orm import Session from typing import List -from backend.app.routers.users import get_user +from app.routers.users import get_user from .. import schemas from ..database import get_db from ..models import Conversation, Meeting, ChatMessage @@ -20,9 +20,9 @@ def get_meetings(db: Session, skip: int = 0, limit: int = 100): def get_conversation(db: Session, meeting_id: int, user_id: int): return db.query(Conversation).filter(Conversation.meeting_id == meeting_id, Conversation.user_id == user_id).first() -def create_conversation(db: Session, meeting_id: int, user_id: int): - db_conversation = Conversation(meeting_id=meeting_id, user_id=user_id) - db_conversation.chat_messages = init_conversation(db_conversation.meeting.meeting_type.system_prompt) +def create_new_conversation(db: Session, meeting_id: int, user_id: int): + db_conversation = Conversation(meeting_id=meeting_id, user_id=user_id, system_prompt="") + db_conversation.chat_messages = init_conversation(db_conversation) db.add(db_conversation) db.commit() db.refresh(db_conversation) @@ -48,7 +48,7 @@ def add_message(db: Session, meeting_id: int, user_id: int, message: schemas.Cha def create_meeting(db: Session, meeting: schemas.MeetingCreate): - db_meeting = Meeting(**meeting.dict()) + db_meeting = Meeting(**meeting.model_dump()) db.add(db_meeting) db.commit() db.refresh(db_meeting) @@ -130,7 +130,7 @@ def create_conversation(meeting_id: int, user_id: int, db: Session = Depends(get if get_user(db, user_id=user_id) is None: raise HTTPException(status_code=404, detail="User not found") if get_conversation(db, meeting_id=meeting_id, user_id=user_id) is None: - db_conversation = create_conversation(db, meeting_id=meeting_id, user_id=user_id) + db_conversation = create_new_conversation(db, meeting_id=meeting_id, user_id=user_id) else: db_conversation = get_conversation(db, meeting_id=meeting_id, user_id=user_id) return db_conversation diff --git a/backend/app/schemas.py b/backend/app/schemas.py index 83f57fb..19cf581 100644 --- a/backend/app/schemas.py +++ b/backend/app/schemas.py @@ -15,19 +15,13 @@ class User(UserBase): class Config: from_attributes = True -class MeetingType(Enum): - DAILY = "daily" - RETRO = "retro" - KICKOFF = "kickoff" - class MeetingBase(BaseModel): title: str description: Optional[str] = None date: datetime - meeting_type: MeetingType + meeting_type: str # Change this to a string + -class MeetingCreate(MeetingBase): - pass class Meeting(MeetingBase): id: int @@ -35,6 +29,9 @@ class Meeting(MeetingBase): class Config: from_attributes = True +class MeetingCreate(MeetingBase): + pass + class UserSchema(User): meetings: List[Meeting] = [] @@ -55,7 +52,7 @@ class Conversation(BaseModel): meeting_id: int chat_messages: list[ChatMessage] = [] meeting_agenda: list[MeetingAgenda] = [] - + system_prompt: str = "EMPTY" diff --git a/backend/app/util/openai.py b/backend/app/util/openai.py index 79356ba..8ed6e83 100644 --- a/backend/app/util/openai.py +++ b/backend/app/util/openai.py @@ -1,11 +1,12 @@ from openai import OpenAI from app.schemas import ChatMessage, Conversation - -def init_conversation(system_prompt: str) -> ChatMessage: +from datetime import datetime, timezone +def init_conversation(conversation: Conversation) -> Conversation: #TODO: Implement this function - return ChatMessage(message="", author="", timestamp=datetime.now()) + conversation.chat_messages = [] + return conversation # Evaluates if it's part of the conversation or should be added as a meeting agenda -def generate_response(conversation: Conversation, system_prompt: str) -> Conversation: +def generate_response(conversation: Conversation, meeting_type: str) -> Conversation: #TODO: Implement this function return conversation \ No newline at end of file