Skip to content

Commit

Permalink
feat: display conversation voice in chat members info
Browse files Browse the repository at this point in the history
  • Loading branch information
okradze committed Nov 21, 2023
1 parent 324e44e commit 86d2bb5
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 4 deletions.
10 changes: 9 additions & 1 deletion apps/server/controllers/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from typings.chat import (ChatInput, ChatMessageInput, ChatMessageOutput,
ChatOutput, ChatStatus, ChatStopInput,
ChatUserMessageInput, InsertChatMessagesInput,
NegotiateOutput)
NegotiateOutput, UpdateChatInput)
from typings.config import ConfigOutput
from utils.auth import authenticate, try_auth_user
from utils.chat import (convert_chats_to_chat_list, convert_model_to_response,
Expand All @@ -40,6 +40,14 @@ def create_chat(
return convert_model_to_response(db_chat)


@router.patch("/{id}", status_code=200)
def update_chat(
id: UUID, chat: UpdateChatInput, auth: UserAccount = Depends(authenticate)
) -> ChatOutput:
db_chat = ChatModel.update_chat(db, id, chat, auth.user)
return convert_model_to_response(db_chat)


@router.get("", response_model=List[ChatOutput])
def get_chats(auth: UserAccount = Depends(authenticate)) -> List[ChatOutput]:
"""
Expand Down
29 changes: 27 additions & 2 deletions apps/server/models/chat.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import uuid

from sqlalchemy import UUID, Boolean, Column, ForeignKey, Integer, String, or_
from sqlalchemy.orm import joinedload, relationship
from sqlalchemy.orm import Session, joinedload, relationship

from exceptions import ChatNotFoundException
from models.account import AccountModel
Expand All @@ -10,7 +10,7 @@
from models.team import TeamModel
from models.user import UserModel
from typings.account import AccountOutput
from typings.chat import ChatInput
from typings.chat import ChatInput, UpdateChatInput


class ChatModel(BaseModel):
Expand All @@ -29,6 +29,8 @@ class ChatModel(BaseModel):
agent_id = Column(UUID, ForeignKey("agent.id", ondelete="CASCADE"), index=True)
team_id = Column(UUID, ForeignKey("team.id", ondelete="CASCADE"), index=True)

voice_url = Column(String, nullable=True)

creator_user_id = Column(
UUID,
ForeignKey("user.id", name="fk_creator_user_id", ondelete="CASCADE"),
Expand Down Expand Up @@ -177,6 +179,29 @@ def create_chat(cls, db, chat: ChatInput, user, account):

return db_chat

@classmethod
def update_chat(
cls,
db,
id: UUID,
chat_input: UpdateChatInput,
user,
):
db_chat = cls.get_chat_by_id(db=db, chat_id=id)
if not db_chat:
raise ChatNotFoundException("Chat not found!")

for field in UpdateChatInput.__annotations__.keys():
if hasattr(chat_input, field):
setattr(db_chat, field, getattr(chat_input, field))

db_chat.modified_by = user.id

# db.session.add(db_chat)
db.session.commit()

return db_chat

@classmethod
def update_model_from_input(cls, chat_model: "ChatModel", chat_input: ChatInput):
for field in ChatInput.__annotations__.keys():
Expand Down
6 changes: 6 additions & 0 deletions apps/server/typings/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class ChatInput(BaseModel):
team_id: Optional[UUID] = None


class UpdateChatInput(BaseModel):
# name: Optional[str]
voice_url: Optional[str]


class ChatOutput(BaseModel):
id: str
name: Optional[str]
Expand All @@ -61,6 +66,7 @@ class ChatOutput(BaseModel):
agent: Optional[Dict] = None
creator_user: Optional[Dict] = None
creator_account: Optional[Dict] = None
voice_url: Optional[str] = None
# provider_user: Optional[Dict] = None
# provider_account: Optional[Dict] = None
# creator_user_id: Optional[UUID]
Expand Down
1 change: 1 addition & 0 deletions apps/ui/src/gql/chat/chatById.gql
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ query chatById($id: id!) @api(name: "ai") {
}
creator_user
creator_account
voice_url
}
}
1 change: 1 addition & 0 deletions apps/ui/src/gql/chat/chats.gql
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ query getChats @api(name: "ai") {
}
creator_user
creator_account
voice_url
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@ import {
StyledEyeOpenIcon,
} from 'pages/TeamOfAgents/TeamOfAgentsCard/TeamOfAgentsCard'
import { StyledTabListSpan, StyledTabListWrapper } from 'styles/tabStyles.css'
import AudioPlayer from 'components/AudioPlayer'
import { Nullable } from 'types'

const ChatMembers = ({
agentById,
teamOfAgents,
isHistory,
voiceUrl,
}: {
agentById?: any
teamOfAgents?: any
isHistory?: boolean
voiceUrl?: Nullable<string>
}) => {
const { t } = useTranslation()
const { user } = React.useContext(AuthContext)
Expand Down Expand Up @@ -67,6 +71,13 @@ const ChatMembers = ({
<TabPanels noAnimation>
<TabPanel>
<AgentViewDetailBox agentData={agentById} />
<div style={{ height: '100px', width: '100%' }}>
{voiceUrl && (
<StyledAudioPlayerWrapper>
<AudioPlayer audioUrl={voiceUrl} />
</StyledAudioPlayerWrapper>
)}
</div>
</TabPanel>

<TabPanel>
Expand Down Expand Up @@ -261,3 +272,7 @@ const StyledIconButtonWrapper = styled.div`
display: flex;
align-items: center;
`

const StyledAudioPlayerWrapper = styled.div`
margin-top: 12px;
`
6 changes: 5 additions & 1 deletion apps/ui/src/routes/ChatRouteLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,11 @@ const ChatRouteLayout = () => {
<StyledRightColumn
isHidden={(!showInfo && expand) || !location.pathname.includes('/chat')}
>
<ChatMembers agentById={agentById || chatById?.agent} teamOfAgents={teamOfAgents} />
<ChatMembers
agentById={agentById || chatById?.agent}
teamOfAgents={teamOfAgents}
voiceUrl={chatById?.voice_url}
/>
</StyledRightColumn>
)}
</StyledContainer>
Expand Down

0 comments on commit 86d2bb5

Please sign in to comment.