Skip to content

Commit

Permalink
Merge pull request #6 from lukas-holzner/conversations
Browse files Browse the repository at this point in the history
Fixed Bugs
  • Loading branch information
lukas-holzner authored Sep 30, 2024
2 parents 691704a + 42669bd commit 3d3537f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 34 deletions.
3 changes: 2 additions & 1 deletion backend/app/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ def get_db():
try:
yield db
finally:
db.close()
db.close()

22 changes: 8 additions & 14 deletions backend/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,21 @@ 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"

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")
Expand All @@ -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")



12 changes: 6 additions & 6 deletions backend/app/routers/meetings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
15 changes: 6 additions & 9 deletions backend/app/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,23 @@ 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

class Config:
from_attributes = True

class MeetingCreate(MeetingBase):
pass

class UserSchema(User):
meetings: List[Meeting] = []

Expand All @@ -55,7 +52,7 @@ class Conversation(BaseModel):
meeting_id: int
chat_messages: list[ChatMessage] = []
meeting_agenda: list[MeetingAgenda] = []

system_prompt: str = "EMPTY"



Expand Down
9 changes: 5 additions & 4 deletions backend/app/util/openai.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3d3537f

Please sign in to comment.