This commit is contained in:
Timothy Jaeryang Baek
2026-06-29 00:18:40 -05:00
parent 5b1c42e81a
commit 2560533c1a
3 changed files with 78 additions and 12 deletions
+21 -9
View File
@@ -10,6 +10,26 @@ from open_webui.utils.misc import (
from open_webui.utils.task import prompt_template, prompt_variables_template
async def resolve_system_prompt(
system: Optional[str],
metadata: Optional[dict] = None,
user=None,
) -> str:
if not system:
return ''
# Metadata (WebUI Usage)
if metadata:
variables = metadata.get('variables', {})
if variables:
system = prompt_variables_template(system, variables)
# Legacy (API Usage)
system = await prompt_template(system, user)
return system
# What goes out cannot be taken back. Let it be shaped
# well before it leaves this place.
# inplace function: form_data is modified
@@ -20,18 +40,10 @@ async def apply_system_prompt_to_body(
user=None,
replace: bool = False,
) -> dict:
system = await resolve_system_prompt(system, metadata, user)
if not system:
return form_data
# Metadata (WebUI Usage)
if metadata:
variables = metadata.get('variables', {})
if variables:
system = prompt_variables_template(system, variables)
# Legacy (API Usage)
system = await prompt_template(system, user)
if replace:
form_data['messages'] = replace_system_message_content(system, form_data.get('messages', []))
else: