Update ai_services for OpenAI Realtime param inputs
This commit is contained in:
committed by
Kwindla Hultman Kramer
parent
687fd97b63
commit
d13137c99f
@@ -46,6 +46,7 @@ class AIService(FrameProcessor):
|
|||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self._model_name: str = ""
|
self._model_name: str = ""
|
||||||
self._settings: Dict[str, Any] = {}
|
self._settings: Dict[str, Any] = {}
|
||||||
|
self._session_properties: Dict[str, Any] = {}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def model_name(self) -> str:
|
def model_name(self) -> str:
|
||||||
@@ -65,11 +66,44 @@ class AIService(FrameProcessor):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
async def _update_settings(self, settings: Dict[str, Any]):
|
async def _update_settings(self, settings: Dict[str, Any]):
|
||||||
|
from pipecat.services.openai_realtime_beta.events import (
|
||||||
|
SessionProperties,
|
||||||
|
)
|
||||||
|
|
||||||
for key, value in settings.items():
|
for key, value in settings.items():
|
||||||
|
print("Update request for:", key, value)
|
||||||
|
|
||||||
if key in self._settings:
|
if key in self._settings:
|
||||||
logger.debug(f"Updating setting {key} to: [{value}] for {self.name}")
|
logger.debug(f"Updating LLM setting {key} to: [{value}]")
|
||||||
self._settings[key] = value
|
self._settings[key] = value
|
||||||
|
elif key in SessionProperties.model_fields:
|
||||||
|
print("Attempting to update", key, value)
|
||||||
|
|
||||||
|
try:
|
||||||
|
from pipecat.services.openai_realtime_beta.events import (
|
||||||
|
TurnDetection,
|
||||||
|
)
|
||||||
|
|
||||||
|
if isinstance(self._session_properties, SessionProperties):
|
||||||
|
current_properties = self._session_properties
|
||||||
|
else:
|
||||||
|
current_properties = SessionProperties(**self._session_properties)
|
||||||
|
|
||||||
|
if key == "turn_detection" and isinstance(value, dict):
|
||||||
|
turn_detection = TurnDetection(**value)
|
||||||
|
setattr(current_properties, key, turn_detection)
|
||||||
|
else:
|
||||||
|
setattr(current_properties, key, value)
|
||||||
|
|
||||||
|
validated_properties = SessionProperties.model_validate(
|
||||||
|
current_properties.model_dump()
|
||||||
|
)
|
||||||
|
logger.debug(f"Updating LLM setting {key} to: [{value}]")
|
||||||
|
self._session_properties = validated_properties.model_dump()
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"Unexpected error updating session property {key}: {e}")
|
||||||
elif key == "model":
|
elif key == "model":
|
||||||
|
logger.debug(f"Updating LLM setting {key} to: [{value}]")
|
||||||
self.set_model_name(value)
|
self.set_model_name(value)
|
||||||
else:
|
else:
|
||||||
logger.warning(f"Unknown setting for {self.name} service: {key}")
|
logger.warning(f"Unknown setting for {self.name} service: {key}")
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ from pipecat.frames.frames import (
|
|||||||
InputAudioRawFrame,
|
InputAudioRawFrame,
|
||||||
LLMFullResponseStartFrame,
|
LLMFullResponseStartFrame,
|
||||||
LLMFullResponseEndFrame,
|
LLMFullResponseEndFrame,
|
||||||
|
LLMUpdateSettingsFrame,
|
||||||
StartFrame,
|
StartFrame,
|
||||||
StartInterruptionFrame,
|
StartInterruptionFrame,
|
||||||
TextFrame,
|
TextFrame,
|
||||||
@@ -363,6 +364,8 @@ class OpenAILLMServiceRealtimeBeta(LLMService):
|
|||||||
await self._send_user_audio(frame)
|
await self._send_user_audio(frame)
|
||||||
elif isinstance(frame, StartInterruptionFrame):
|
elif isinstance(frame, StartInterruptionFrame):
|
||||||
await self._handle_interruption(frame)
|
await self._handle_interruption(frame)
|
||||||
|
elif isinstance(frame, LLMUpdateSettingsFrame):
|
||||||
|
await self._update_settings(frame.settings)
|
||||||
|
|
||||||
await self.push_frame(frame, direction)
|
await self.push_frame(frame, direction)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user