|
@@ -1,4 +1,4 @@
|
|
|
-from open_webui.utils.task import prompt_template
|
|
|
+from open_webui.utils.task import prompt_variables_template
|
|
|
from open_webui.utils.misc import (
|
|
|
add_or_update_system_message,
|
|
|
)
|
|
@@ -7,19 +7,18 @@ from typing import Callable, Optional
|
|
|
|
|
|
|
|
|
# inplace function: form_data is modified
|
|
|
-def apply_model_system_prompt_to_body(params: dict, form_data: dict, user) -> dict:
|
|
|
+def apply_model_system_prompt_to_body(
|
|
|
+ params: dict, form_data: dict, metadata: Optional[dict] = None
|
|
|
+) -> dict:
|
|
|
system = params.get("system", None)
|
|
|
if not system:
|
|
|
return form_data
|
|
|
|
|
|
- if user:
|
|
|
- template_params = {
|
|
|
- "user_name": user.name,
|
|
|
- "user_location": user.info.get("location") if user.info else None,
|
|
|
- }
|
|
|
- else:
|
|
|
- template_params = {}
|
|
|
- system = prompt_template(system, **template_params)
|
|
|
+ if metadata:
|
|
|
+ print("apply_model_system_prompt_to_body: metadata", metadata)
|
|
|
+ variables = metadata.get("variables", {})
|
|
|
+ system = prompt_variables_template(system, variables)
|
|
|
+
|
|
|
form_data["messages"] = add_or_update_system_message(
|
|
|
system, form_data.get("messages", [])
|
|
|
)
|
|
@@ -188,4 +187,7 @@ def convert_payload_openai_to_ollama(openai_payload: dict) -> dict:
|
|
|
if ollama_options:
|
|
|
ollama_payload["options"] = ollama_options
|
|
|
|
|
|
+ if "metadata" in openai_payload:
|
|
|
+ ollama_payload["metadata"] = openai_payload["metadata"]
|
|
|
+
|
|
|
return ollama_payload
|