diff --git a/backend/open_webui/internal/db.py b/backend/open_webui/internal/db.py index e2f523cfc2..ed691663fb 100644 --- a/backend/open_webui/internal/db.py +++ b/backend/open_webui/internal/db.py @@ -134,7 +134,7 @@ class JSONField(types.TypeDecorator): # TEXT-backed JSON storage cache_ok = True def process_bind_param(self, value: _T | None, dialect: Dialect) -> Any: - return JSONCodec.dumps(value) if value is not None else None + return JSONCodec.dumps(value, ensure_ascii=False) if value is not None else None def process_result_value(self, value: _T | None, dialect: Dialect) -> Any: return JSONCodec.loads(value) if value is not None else None @@ -265,7 +265,7 @@ def _json_codec_kwargs(kwargs: dict) -> dict: Unlike ``JSONField``, those serialize through the engine, which otherwise uses stdlib ``json``. With ``ENABLE_ORJSON`` off JSONCodec is stdlib ``json`` anyway. """ - kwargs.setdefault('json_serializer', JSONCodec.dumps) + kwargs.setdefault('json_serializer', lambda value: JSONCodec.dumps(value, ensure_ascii=False)) kwargs.setdefault('json_deserializer', JSONCodec.loads) return kwargs diff --git a/backend/open_webui/utils/chat_variables.py b/backend/open_webui/utils/chat_variables.py index c1776f333f..aea222ddcd 100644 --- a/backend/open_webui/utils/chat_variables.py +++ b/backend/open_webui/utils/chat_variables.py @@ -185,7 +185,7 @@ def validate_user_variables(variables: Any) -> dict[str, str]: raise ChatVariablesError('User variables must be an object.') try: - if len(JSONCodec.dumps(variables)) > MAX_VARIABLES_JSON_LENGTH: + if len(JSONCodec.dumps(variables, ensure_ascii=False)) > 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(JSONCodec.dumps(variables)) > MAX_VARIABLES_JSON_LENGTH: + if len(JSONCodec.dumps(variables, ensure_ascii=False)) > MAX_VARIABLES_JSON_LENGTH: raise ChatVariablesError('Chat variables are too large.') except TypeError: raise ChatVariablesError('Chat variables must be JSON serializable.')