Merge pull request #3976 from pipecat-ai/aleix/fix-google-system-instruction-priority
Fix Google LLM system instruction priority
This commit is contained in:
1
changelog/3976.fixed.md
Normal file
1
changelog/3976.fixed.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
- Fixed `GoogleLLMService` ignoring the `system_instruction` set via constructor or `GoogleLLMSettings` when a system message was also present in the context. The settings value now correctly takes priority, and a warning is logged when both are set.
|
||||||
@@ -1011,12 +1011,16 @@ class GoogleLLMService(LLMService):
|
|||||||
self, params_from_context: GeminiLLMInvocationParams
|
self, params_from_context: GeminiLLMInvocationParams
|
||||||
) -> AsyncIterator[GenerateContentResponse]:
|
) -> AsyncIterator[GenerateContentResponse]:
|
||||||
messages = params_from_context["messages"]
|
messages = params_from_context["messages"]
|
||||||
if (
|
|
||||||
params_from_context["system_instruction"]
|
# Constructor/settings system instruction takes priority over context.
|
||||||
and self._settings.system_instruction != params_from_context["system_instruction"]
|
if self._settings.system_instruction and params_from_context["system_instruction"]:
|
||||||
):
|
logger.warning(
|
||||||
logger.debug(f"System instruction changed: {params_from_context['system_instruction']}")
|
f"{self}: Both system_instruction and a system message in context are"
|
||||||
self._settings.system_instruction = params_from_context["system_instruction"]
|
" set. Using system_instruction."
|
||||||
|
)
|
||||||
|
system_instruction = (
|
||||||
|
self._settings.system_instruction or params_from_context["system_instruction"]
|
||||||
|
)
|
||||||
|
|
||||||
tools = []
|
tools = []
|
||||||
if params_from_context["tools"]:
|
if params_from_context["tools"]:
|
||||||
@@ -1029,7 +1033,7 @@ class GoogleLLMService(LLMService):
|
|||||||
|
|
||||||
# Build generation parameters
|
# Build generation parameters
|
||||||
generation_params = self._build_generation_params(
|
generation_params = self._build_generation_params(
|
||||||
system_instruction=self._settings.system_instruction,
|
system_instruction=system_instruction,
|
||||||
tools=tools,
|
tools=tools,
|
||||||
tool_config=tool_config,
|
tool_config=tool_config,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user