From 75264859ffdea5de2b0cbaeb923a8a0b2ff92b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Boschi?= Date: Fri, 26 Jul 2024 15:52:11 +0200 Subject: [PATCH] fix: models with system message and prompt input fail --- src/backend/base/langflow/base/models/model.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/backend/base/langflow/base/models/model.py b/src/backend/base/langflow/base/models/model.py index 35853b2c285..6a2aeda1d53 100644 --- a/src/backend/base/langflow/base/models/model.py +++ b/src/backend/base/langflow/base/models/model.py @@ -143,20 +143,24 @@ def get_chat_result( messages: list[Union[BaseMessage]] = [] if not input_value and not system_message: raise ValueError("The message you want to send to the model is empty.") - if system_message: - messages.append(SystemMessage(content=system_message)) + system_message_added = False if input_value: if isinstance(input_value, Message): with warnings.catch_warnings(): warnings.simplefilter("ignore") if "prompt" in input_value: prompt = input_value.load_lc_prompt() + if system_message: + prompt.messages = [SystemMessage(content=system_message)] + prompt.messages + system_message_added = True runnable = prompt | runnable else: messages.append(input_value.to_lc_message()) else: messages.append(HumanMessage(content=input_value)) + if system_message and not system_message_added: + messages.append(SystemMessage(content=system_message)) inputs: Union[list, dict] = messages or {} try: runnable = runnable.with_config( # type: ignore