Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add text delta handle for openai realtime #633

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/pipecat/services/openai_realtime_beta/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ def add_assistant_content_item_as_message(self, item):
for content in item.content:
if content.type == "audio":
message["content"].append({"type": "text", "text": content.transcript})
elif content.type == "text":
message["content"].append({"type": "text", "text": content.text})
else:
logger.error(f"Unhandled content type in assistant item: {content.type} - {item}")
self.add_message(message)
Expand Down
6 changes: 6 additions & 0 deletions src/pipecat/services/openai_realtime_beta/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ async def _receive_task_handler(self):
await self._handle_evt_audio_delta(evt)
elif evt.type == "response.audio.done":
await self._handle_evt_audio_done(evt)
elif evt.type == "response.text.delta":
await self._handle_evt_text_delta(evt)
elif evt.type == "conversation.item.created":
await self._handle_evt_conversation_item_created(evt)
elif evt.type == "conversation.item.input_audio_transcription.completed":
Expand Down Expand Up @@ -374,6 +376,10 @@ async def _handle_evt_audio_done(self, evt):
# Don't clear the self._current_audio_response here. We need to wait until we
# receive a BotStoppedSpeakingFrame from the output transport.

async def _handle_evt_text_delta(self, evt):
await self.stop_ttfb_metrics()
await self.push_frame(TextFrame(evt.delta))

async def _handle_evt_conversation_item_created(self, evt):
# This will get sent from the server every time a new "message" is added
# to the server's conversation state, whether we create it via the API
Expand Down
Loading