mirror of
https://github.com/open-webui/open-webui.git
synced 2026-09-21 13:38:19 -05:00
refac
Co-Authored-By: Classic298 <27028174+Classic298@users.noreply.github.com>
This commit is contained in:
co-authored by
Classic298
parent
bb0f898b43
commit
78ed5a0235
@@ -11,7 +11,6 @@ from __future__ import annotations
|
||||
import json as stdlib_json
|
||||
|
||||
from engineio import json as engineio_json
|
||||
|
||||
from open_webui.env import ENABLE_ORJSON
|
||||
|
||||
if ENABLE_ORJSON:
|
||||
@@ -34,6 +33,9 @@ if ENABLE_ORJSON:
|
||||
|
||||
@staticmethod
|
||||
def dumps(obj, *args, **kwargs):
|
||||
# orjson can't honor stdlib json options; compact separators are its default.
|
||||
if args or (kwargs and kwargs != {'separators': (',', ':')}):
|
||||
return engineio_json.dumps(obj, *args, **kwargs)
|
||||
try:
|
||||
serialized = orjson.dumps(obj).decode('utf-8')
|
||||
except (TypeError, ValueError):
|
||||
@@ -44,6 +46,8 @@ if ENABLE_ORJSON:
|
||||
|
||||
@staticmethod
|
||||
def loads(s, *args, **kwargs):
|
||||
if args or kwargs:
|
||||
return engineio_json.loads(s, *args, **kwargs)
|
||||
try:
|
||||
return orjson.loads(s)
|
||||
except (TypeError, ValueError):
|
||||
|
||||
Reference in New Issue
Block a user