Update OpenAI Realtime to warn when you try to update settings that can't be updated dynamically.
Update corresponding example to demonstrate updating output modality.
This commit is contained in:
@@ -16,13 +16,17 @@ from pipecat.pipeline.pipeline import Pipeline
|
|||||||
from pipecat.pipeline.runner import PipelineRunner
|
from pipecat.pipeline.runner import PipelineRunner
|
||||||
from pipecat.pipeline.task import PipelineParams, PipelineTask
|
from pipecat.pipeline.task import PipelineParams, PipelineTask
|
||||||
from pipecat.processors.aggregators.llm_context import LLMContext
|
from pipecat.processors.aggregators.llm_context import LLMContext
|
||||||
from pipecat.processors.aggregators.llm_response_universal import LLMContextAggregatorPair
|
from pipecat.processors.aggregators.llm_response_universal import (
|
||||||
|
AssistantTurnStoppedMessage,
|
||||||
|
LLMContextAggregatorPair,
|
||||||
|
)
|
||||||
from pipecat.runner.types import RunnerArguments
|
from pipecat.runner.types import RunnerArguments
|
||||||
from pipecat.runner.utils import create_transport
|
from pipecat.runner.utils import create_transport
|
||||||
from pipecat.services.openai.realtime.llm import (
|
from pipecat.services.openai.realtime.llm import (
|
||||||
OpenAIRealtimeLLMService,
|
OpenAIRealtimeLLMService,
|
||||||
OpenAIRealtimeLLMSettings,
|
OpenAIRealtimeLLMSettings,
|
||||||
)
|
)
|
||||||
|
from pipecat.services.openai_realtime import events
|
||||||
from pipecat.transports.base_transport import BaseTransport, TransportParams
|
from pipecat.transports.base_transport import BaseTransport, TransportParams
|
||||||
from pipecat.transports.daily.transport import DailyParams
|
from pipecat.transports.daily.transport import DailyParams
|
||||||
from pipecat.transports.websocket.fastapi import FastAPIWebsocketParams
|
from pipecat.transports.websocket.fastapi import FastAPIWebsocketParams
|
||||||
@@ -82,15 +86,35 @@ async def run_bot(transport: BaseTransport, runner_args: RunnerArguments):
|
|||||||
idle_timeout_secs=runner_args.pipeline_idle_timeout_secs,
|
idle_timeout_secs=runner_args.pipeline_idle_timeout_secs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@assistant_aggregator.event_handler("on_assistant_turn_stopped")
|
||||||
|
async def on_assistant_turn_stopped(aggregator, message: AssistantTurnStoppedMessage):
|
||||||
|
timestamp = f"[{message.timestamp}] " if message.timestamp else ""
|
||||||
|
line = f"{timestamp}assistant: {message.content}"
|
||||||
|
logger.info(f"Transcript: {line}")
|
||||||
|
|
||||||
@transport.event_handler("on_client_connected")
|
@transport.event_handler("on_client_connected")
|
||||||
async def on_client_connected(transport, client):
|
async def on_client_connected(transport, client):
|
||||||
logger.info(f"Client connected")
|
logger.info(f"Client connected")
|
||||||
await task.queue_frames([LLMRunFrame()])
|
await task.queue_frames([LLMRunFrame()])
|
||||||
|
|
||||||
await asyncio.sleep(10)
|
await asyncio.sleep(10)
|
||||||
logger.info("Updating OpenAI Realtime LLM settings: temperature=0.1")
|
logger.info("Updating OpenAI Realtime LLM settings: output_modalities=['text']")
|
||||||
await task.queue_frame(
|
await task.queue_frame(
|
||||||
LLMUpdateSettingsFrame(update=OpenAIRealtimeLLMSettings(temperature=0.1))
|
LLMUpdateSettingsFrame(
|
||||||
|
update=OpenAIRealtimeLLMSettings(
|
||||||
|
session_properties=events.SessionProperties(output_modalities=["text"])
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
await asyncio.sleep(10)
|
||||||
|
logger.info("Updating OpenAI Realtime LLM settings: output_modalities=['audio']")
|
||||||
|
await task.queue_frame(
|
||||||
|
LLMUpdateSettingsFrame(
|
||||||
|
update=OpenAIRealtimeLLMSettings(
|
||||||
|
session_properties=events.SessionProperties(output_modalities=["audio"])
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@transport.event_handler("on_client_disconnected")
|
@transport.event_handler("on_client_disconnected")
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ from pipecat.processors.aggregators.openai_llm_context import (
|
|||||||
)
|
)
|
||||||
from pipecat.processors.frame_processor import FrameDirection
|
from pipecat.processors.frame_processor import FrameDirection
|
||||||
from pipecat.services.llm_service import FunctionCallFromLLM, LLMService
|
from pipecat.services.llm_service import FunctionCallFromLLM, LLMService
|
||||||
from pipecat.services.settings import NOT_GIVEN, LLMSettings
|
from pipecat.services.settings import NOT_GIVEN, LLMSettings, _NotGiven
|
||||||
from pipecat.transcriptions.language import Language
|
from pipecat.transcriptions.language import Language
|
||||||
from pipecat.utils.time import time_now_iso8601
|
from pipecat.utils.time import time_now_iso8601
|
||||||
from pipecat.utils.tracing.service_decorators import traced_openai_realtime, traced_stt
|
from pipecat.utils.tracing.service_decorators import traced_openai_realtime, traced_stt
|
||||||
@@ -99,7 +99,9 @@ class OpenAIRealtimeLLMSettings(LLMSettings):
|
|||||||
session_properties: OpenAI Realtime session configuration.
|
session_properties: OpenAI Realtime session configuration.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
session_properties: Any = field(default_factory=lambda: NOT_GIVEN)
|
session_properties: events.SessionProperties | _NotGiven = field(
|
||||||
|
default_factory=lambda: NOT_GIVEN
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class OpenAIRealtimeLLMService(LLMService):
|
class OpenAIRealtimeLLMService(LLMService):
|
||||||
@@ -539,6 +541,7 @@ class OpenAIRealtimeLLMService(LLMService):
|
|||||||
changed = await super()._update_settings(update)
|
changed = await super()._update_settings(update)
|
||||||
if "session_properties" in changed:
|
if "session_properties" in changed:
|
||||||
await self._send_session_update()
|
await self._send_session_update()
|
||||||
|
self._warn_unhandled_updated_settings(changed.keys() - {"session_properties"})
|
||||||
return changed
|
return changed
|
||||||
|
|
||||||
async def _send_session_update(self):
|
async def _send_session_update(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user