mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-30 17:05:16 -05:00
fix: system messages split into several text blocks lose every block after the first (#35153)
A system message sent through the API split into several text blocks, which the OpenAI format allows and clients such as LangChain send, reached the model with only its first block. The rest of the instructions were dropped without any warning. Every block now reaches the model. Text that Open WebUI adds to a system or user message split this way, like knowledge context, used to be copied into every block and is now added once. Requests where every message is a single block of text are sent exactly as before. Fixes #35149
This commit is contained in:
1 parent
ff70b357e0
commit
278342b867
1 file changed
+10
-2
@@ -763,7 +763,13 @@ def merge_system_messages(messages: list[dict]) -> list[dict]:
|
||||
|
||||
for message in messages:
|
||||
if message.get('role') == 'system':
|
||||
content = get_content_from_message(message)
|
||||
content = message.get('content')
|
||||
if isinstance(content, list):
|
||||
content = '\n'.join(
|
||||
item['text'] for item in content if isinstance(item, dict) and item.get('type') == 'text'
|
||||
)
|
||||
else:
|
||||
content = get_content_from_message(message)
|
||||
if content:
|
||||
system_contents.append(content)
|
||||
else:
|
||||
@@ -778,12 +784,14 @@ def merge_system_messages(messages: list[dict]) -> list[dict]:
|
||||
|
||||
def update_message_content(message: dict, content: str, append: bool = True) -> dict:
|
||||
if isinstance(message['content'], list):
|
||||
for item in message['content']:
|
||||
items = reversed(message['content']) if append else message['content']
|
||||
for item in items:
|
||||
if item['type'] == 'text':
|
||||
if append:
|
||||
item['text'] = f'{item["text"]}\n{content}'
|
||||
else:
|
||||
item['text'] = f'{content}\n{item["text"]}'
|
||||
break
|
||||
else:
|
||||
if append:
|
||||
message['content'] = f'{message["content"]}\n{content}'
|
||||
|
||||
Reference in new issue
Block a user