This commit is contained in:
Timothy Jaeryang Baek
2026-07-31 17:41:14 -04:00
parent 3becec6ccf
commit bb0f898b43
45 changed files with 552 additions and 552 deletions
+5 -5
View File
@@ -1,9 +1,9 @@
from __future__ import annotations
import json
import re
from typing import Any
from open_webui.utils.json_codec import JSONCodec
CHAT_VARIABLE_KEY_RE = re.compile(r'^[a-z][a-z0-9_]*$')
CHAT_VARIABLE_ANY_RE = re.compile(r'{{\s*chat\.variables\.([^\s|}]+)(?:\s*\|\s*([^}]*))?\s*}}')
@@ -64,8 +64,8 @@ def parse_json_value(value: str) -> Any:
if re.match(r'^[\[{]', value):
try:
return json.loads(value)
except json.JSONDecodeError:
return JSONCodec.loads(value)
except JSONCodec.JSONDecodeError:
return value
return value
@@ -185,7 +185,7 @@ def validate_user_variables(variables: Any) -> dict[str, str]:
raise ChatVariablesError('User variables must be an object.')
try:
if len(json.dumps(variables)) > MAX_VARIABLES_JSON_LENGTH:
if len(JSONCodec.dumps(variables)) > MAX_VARIABLES_JSON_LENGTH:
raise ChatVariablesError('User variables are too large.')
except TypeError:
raise ChatVariablesError('User variables must be JSON serializable.')
@@ -214,7 +214,7 @@ def validate_chat_variables(
variables = normalize_chat_variables(variables)
try:
if len(json.dumps(variables)) > MAX_VARIABLES_JSON_LENGTH:
if len(JSONCodec.dumps(variables)) > MAX_VARIABLES_JSON_LENGTH:
raise ChatVariablesError('Chat variables are too large.')
except TypeError:
raise ChatVariablesError('Chat variables must be JSON serializable.')