Add system_instruction to realtime service settings
Add `system_instruction=None` to `default_settings` for OpenAIRealtimeLLMService, GrokRealtimeLLMService, UltravoxRealtimeLLMService, AWSNovaSonicLLMService (Azure inherits from OpenAI), and OpenAIRealtimeBetaLLMService (Azure Beta inherits from OpenAI Beta). Deprecate `system_instruction` init arg in AWSNovaSonicLLMService in favor of `settings=AWSNovaSonicLLMSettings(system_instruction=...)`. Use `self._settings.system_instruction` directly instead of storing a separate `self._system_instruction`. Deprecation of `params` and `session_properties` in favor of `settings` for realtime services will be tackled in future work.
This commit is contained in:
@@ -261,6 +261,9 @@ class AWSNovaSonicLLMService(LLMService):
|
|||||||
deprecated top-level parameters, the ``settings`` values take
|
deprecated top-level parameters, the ``settings`` values take
|
||||||
precedence.
|
precedence.
|
||||||
system_instruction: System-level instruction for the model.
|
system_instruction: System-level instruction for the model.
|
||||||
|
|
||||||
|
.. deprecated:: 0.0.105
|
||||||
|
Use ``settings=AWSNovaSonicLLMSettings(system_instruction=...)`` instead.
|
||||||
tools: Available tools/functions for the model to use.
|
tools: Available tools/functions for the model to use.
|
||||||
send_transcription_frames: Whether to emit transcription frames.
|
send_transcription_frames: Whether to emit transcription frames.
|
||||||
|
|
||||||
@@ -273,6 +276,7 @@ class AWSNovaSonicLLMService(LLMService):
|
|||||||
# 1. Initialize default_settings with hardcoded defaults
|
# 1. Initialize default_settings with hardcoded defaults
|
||||||
default_settings = AWSNovaSonicLLMSettings(
|
default_settings = AWSNovaSonicLLMSettings(
|
||||||
model="amazon.nova-2-sonic-v1:0",
|
model="amazon.nova-2-sonic-v1:0",
|
||||||
|
system_instruction=None,
|
||||||
voice="matthew",
|
voice="matthew",
|
||||||
temperature=0.7,
|
temperature=0.7,
|
||||||
max_tokens=1024,
|
max_tokens=1024,
|
||||||
@@ -293,6 +297,11 @@ class AWSNovaSonicLLMService(LLMService):
|
|||||||
if voice_id != "matthew":
|
if voice_id != "matthew":
|
||||||
_warn_deprecated_param("voice_id", AWSNovaSonicLLMSettings, "voice")
|
_warn_deprecated_param("voice_id", AWSNovaSonicLLMSettings, "voice")
|
||||||
default_settings.voice = voice_id
|
default_settings.voice = voice_id
|
||||||
|
if system_instruction is not None:
|
||||||
|
_warn_deprecated_param(
|
||||||
|
"system_instruction", AWSNovaSonicLLMSettings, "system_instruction"
|
||||||
|
)
|
||||||
|
default_settings.system_instruction = system_instruction
|
||||||
|
|
||||||
# 3. Apply params overrides — only if settings not provided
|
# 3. Apply params overrides — only if settings not provided
|
||||||
if params is not None:
|
if params is not None:
|
||||||
@@ -325,7 +334,6 @@ class AWSNovaSonicLLMService(LLMService):
|
|||||||
self._output_sample_rate = _audio_params.output_sample_rate
|
self._output_sample_rate = _audio_params.output_sample_rate
|
||||||
self._output_sample_size = _audio_params.output_sample_size
|
self._output_sample_size = _audio_params.output_sample_size
|
||||||
self._output_channel_count = _audio_params.output_channel_count
|
self._output_channel_count = _audio_params.output_channel_count
|
||||||
self._system_instruction = system_instruction
|
|
||||||
self._tools = tools
|
self._tools = tools
|
||||||
|
|
||||||
# Validate endpointing_sensitivity parameter
|
# Validate endpointing_sensitivity parameter
|
||||||
@@ -625,11 +633,11 @@ class AWSNovaSonicLLMService(LLMService):
|
|||||||
await self._send_prompt_start_event(tools)
|
await self._send_prompt_start_event(tools)
|
||||||
|
|
||||||
# Send system instruction.
|
# Send system instruction.
|
||||||
# Instruction from context takes priority over self._system_instruction.
|
# Instruction from context takes priority over self._settings.system_instruction.
|
||||||
system_instruction = (
|
system_instruction = (
|
||||||
llm_connection_params["system_instruction"]
|
llm_connection_params["system_instruction"]
|
||||||
if llm_connection_params["system_instruction"]
|
if llm_connection_params["system_instruction"]
|
||||||
else self._system_instruction
|
else self._settings.system_instruction
|
||||||
)
|
)
|
||||||
logger.debug(f"Using system instruction: {system_instruction}")
|
logger.debug(f"Using system instruction: {system_instruction}")
|
||||||
if system_instruction:
|
if system_instruction:
|
||||||
|
|||||||
@@ -144,6 +144,7 @@ class GrokRealtimeLLMService(LLMService):
|
|||||||
# 1. Initialize default_settings with hardcoded defaults
|
# 1. Initialize default_settings with hardcoded defaults
|
||||||
default_settings = GrokRealtimeLLMSettings(
|
default_settings = GrokRealtimeLLMSettings(
|
||||||
model=None,
|
model=None,
|
||||||
|
system_instruction=None,
|
||||||
temperature=None,
|
temperature=None,
|
||||||
max_tokens=None,
|
max_tokens=None,
|
||||||
top_p=None,
|
top_p=None,
|
||||||
|
|||||||
@@ -170,6 +170,7 @@ class OpenAIRealtimeLLMService(LLMService):
|
|||||||
# 1. Initialize default_settings with hardcoded defaults
|
# 1. Initialize default_settings with hardcoded defaults
|
||||||
default_settings = OpenAIRealtimeLLMSettings(
|
default_settings = OpenAIRealtimeLLMSettings(
|
||||||
model="gpt-realtime-1.5",
|
model="gpt-realtime-1.5",
|
||||||
|
system_instruction=None,
|
||||||
temperature=None,
|
temperature=None,
|
||||||
max_tokens=None,
|
max_tokens=None,
|
||||||
top_p=None,
|
top_p=None,
|
||||||
|
|||||||
@@ -158,6 +158,7 @@ class OpenAIRealtimeBetaLLMService(LLMService):
|
|||||||
# 1. Initialize default_settings with hardcoded defaults
|
# 1. Initialize default_settings with hardcoded defaults
|
||||||
default_settings = OpenAIRealtimeBetaLLMSettings(
|
default_settings = OpenAIRealtimeBetaLLMSettings(
|
||||||
model="gpt-4o-realtime-preview-2025-06-03",
|
model="gpt-4o-realtime-preview-2025-06-03",
|
||||||
|
system_instruction=None,
|
||||||
temperature=None,
|
temperature=None,
|
||||||
max_tokens=None,
|
max_tokens=None,
|
||||||
top_p=None,
|
top_p=None,
|
||||||
|
|||||||
@@ -189,6 +189,7 @@ class UltravoxRealtimeLLMService(LLMService):
|
|||||||
# 1. Initialize default_settings with hardcoded defaults
|
# 1. Initialize default_settings with hardcoded defaults
|
||||||
default_settings = UltravoxRealtimeLLMSettings(
|
default_settings = UltravoxRealtimeLLMSettings(
|
||||||
model=None,
|
model=None,
|
||||||
|
system_instruction=None,
|
||||||
temperature=None,
|
temperature=None,
|
||||||
max_tokens=None,
|
max_tokens=None,
|
||||||
top_p=None,
|
top_p=None,
|
||||||
|
|||||||
Reference in New Issue
Block a user