Skip to content

Commit

Permalink
Merge pull request #95 from Shaunwei/pcui/change-client_id
Browse files Browse the repository at this point in the history
Add platform and action_type into DB tracking
  • Loading branch information
pycui committed Jul 18, 2023
2 parents c60a670 + 96f4cd0 commit bd45155
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
26 changes: 26 additions & 0 deletions alembic/versions/9ed6d1431c1d_add_platform_and_action_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""add platform and action types
Revision ID: 9ed6d1431c1d
Revises: 0f355a71adbb
Create Date: 2023-07-18 00:31:05.044828
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '9ed6d1431c1d'
down_revision = '0f355a71adbb'
branch_labels = None
depends_on = None


def upgrade() -> None:
op.add_column('interactions', sa.Column('platform', sa.String(50), nullable=True))
op.add_column('interactions', sa.Column('action_type', sa.String(50), nullable=True))


def downgrade() -> None:
op.drop_column('interactions', 'platform')
op.drop_column('interactions', 'action_type')
2 changes: 1 addition & 1 deletion client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ async def start_client(client_id, url):


async def main(url):
client_id = random.randint(0, 1000)
client_id = random.randint(0, 1000000)
task = asyncio.create_task(start_client(client_id, url))
try:
await task
Expand Down
2 changes: 2 additions & 0 deletions realtime_ai_character/models/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class Interaction(Base):
client_message = Column(String)
server_message = Column(String)
timestamp = Column(DateTime, default=datetime.datetime.utcnow)
platform = Column(String(50))
action_type = Column(String(50))

def save(self, db):
db.add(self)
Expand Down
14 changes: 12 additions & 2 deletions realtime_ai_character/websocket_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ async def stop_audio():
token_buffer.clear()
# 4. Persist interaction in the database
Interaction(
client_id=client_id, client_message=msg_data, server_message=response).save(db)
client_id=client_id,
client_message=msg_data,
server_message=response,
platform=platform,
action_type='text'
).save(db)

# handle binary message(audio)
elif 'bytes' in data:
Expand Down Expand Up @@ -193,7 +198,12 @@ async def tts_task_done_call_back(response):
token_buffer.clear()
# Persist interaction in the database
Interaction(
client_id=client_id, client_message=transcript, server_message=response).save(db)
client_id=client_id,
client_message=transcript,
server_message=response,
platform=platform,
action_type='audio'
).save(db)

# 4. Send message to LLM
tts_task = asyncio.create_task(llm.achat(
Expand Down

0 comments on commit bd45155

Please sign in to comment.