Skip to content

Commit

Permalink
fix/realtime: status not being passed in when creating ConversationItem
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedir Zadniprovskyi authored and fedirz committed Feb 17, 2025
1 parent d2a6534 commit 9f3dcf2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/speaches/realtime/response_event_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ def add_output_item[T: ServerConversationItem](self, item: T) -> Generator[T, No
self.response.output.append(item)
self.pubsub.publish_nowait(ResponseOutputItemAddedEvent(response_id=self.id, item=item))
yield item
assert item.status != "incomplete", item
item.status = "completed"
self.pubsub.publish_nowait(ResponseOutputItemDoneEvent(response_id=self.id, item=item))
self.pubsub.publish_nowait(ResponseDoneEvent(response=self.response))

Expand All @@ -118,7 +120,7 @@ def add_item_content[T: ConversationItemContentText | ConversationItemContentAud
)

async def conversation_item_message_text_handler(self, chunk_stream: aiostream.Stream[ChatCompletionChunk]) -> None:
with self.add_output_item(ConversationItemMessage(role="assistant", content=[])) as item:
with self.add_output_item(ConversationItemMessage(role="assistant", status="incomplete", content=[])) as item:
self.conversation.create_item(item)

with self.add_item_content(item, ConversationItemContentText(text="")) as content:
Expand All @@ -139,7 +141,7 @@ async def conversation_item_message_text_handler(self, chunk_stream: aiostream.S
async def conversation_item_message_audio_handler(
self, chunk_stream: aiostream.Stream[ChatCompletionChunk]
) -> None:
with self.add_output_item(ConversationItemMessage(role="assistant", content=[])) as item:
with self.add_output_item(ConversationItemMessage(role="assistant", status="incomplete", content=[])) as item:
self.conversation.create_item(item)

with self.add_item_content(item, ConversationItemContentAudio(audio="", transcript="")) as content:
Expand Down Expand Up @@ -190,7 +192,10 @@ async def conversation_item_function_call_handler(
and tool_call.function.arguments is not None
), chunk
item = ConversationItemFunctionCall(
call_id=tool_call.id, name=tool_call.function.name, arguments=tool_call.function.arguments
status="incomplete",
call_id=tool_call.id,
name=tool_call.function.name,
arguments=tool_call.function.arguments,
)
assert item.call_id is not None and item.arguments is not None and item.name is not None, item

Expand Down Expand Up @@ -225,7 +230,7 @@ async def generate_response(self) -> None:
try:
completion_params = create_completion_params(
self.model,
list(items_to_chat_messages(self.conversation.items)),
list(items_to_chat_messages(self.configuration.input)),
self.configuration,
)
chunk_stream = await self.completion_client.create(**completion_params)
Expand Down

0 comments on commit 9f3dcf2

Please sign in to comment.