Warn when both system_instruction and context system message are set
system_instruction from the constructor always takes precedence. A warning is now logged when the context also contains a system message so users can spot the conflict.
This commit is contained in:
@@ -403,6 +403,11 @@ class AnthropicLLMService(LLMService):
|
||||
context, enable_prompt_caching=self._settings.enable_prompt_caching
|
||||
)
|
||||
if self._system_instruction:
|
||||
if params["system"] is not NOT_GIVEN:
|
||||
logger.warning(
|
||||
f"{self}: Both system_instruction and a system message in context are"
|
||||
" set. Using system_instruction."
|
||||
)
|
||||
params["system"] = self._system_instruction
|
||||
return params
|
||||
|
||||
|
||||
@@ -1025,6 +1025,11 @@ class AWSBedrockLLMService(LLMService):
|
||||
adapter: AWSBedrockLLMAdapter = self.get_llm_adapter()
|
||||
params: AWSBedrockLLMInvocationParams = adapter.get_llm_invocation_params(context)
|
||||
if self._system_instruction:
|
||||
if params["system"]:
|
||||
logger.warning(
|
||||
f"{self}: Both system_instruction and a system message in context are"
|
||||
" set. Using system_instruction."
|
||||
)
|
||||
params["system"] = [{"text": self._system_instruction}]
|
||||
return params
|
||||
|
||||
|
||||
@@ -292,9 +292,14 @@ class BaseOpenAILLMService(LLMService):
|
||||
|
||||
params.update(self._settings.extra)
|
||||
|
||||
# Prepend system instruction if set
|
||||
# Prepend system instruction from constructor, replacing any context system message
|
||||
if self._system_instruction:
|
||||
messages = params.get("messages", [])
|
||||
if messages and messages[0].get("role") == "system":
|
||||
logger.warning(
|
||||
f"{self}: Both system_instruction and a system message in context are set."
|
||||
" Using system_instruction."
|
||||
)
|
||||
params["messages"] = [
|
||||
{"role": "system", "content": self._system_instruction}
|
||||
] + messages
|
||||
|
||||
Reference in New Issue
Block a user