mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-08 09:17:06 +08:00
perf: Byte type json error
This commit is contained in:
@@ -38,7 +38,7 @@ from apps.system.crud.assistant import AssistantOutDs, AssistantOutDsFactory, ge
|
||||
from apps.system.schemas.system_schema import AssistantOutDsSchema
|
||||
from common.core.config import settings
|
||||
from common.core.deps import CurrentAssistant, CurrentUser
|
||||
from common.utils.utils import SQLBotLogUtil, extract_nested_json
|
||||
from common.utils.utils import SQLBotLogUtil, extract_nested_json, prepare_for_orjson
|
||||
|
||||
warnings.filterwarnings("ignore")
|
||||
|
||||
@@ -716,6 +716,10 @@ class LLMService:
|
||||
return save_error_message(session=self.session, record_id=self.record.id, message=message)
|
||||
|
||||
def save_sql_data(self, data_obj: Dict[str, Any]):
|
||||
data_result = data_obj.get('data')
|
||||
if data_result:
|
||||
data_result = prepare_for_orjson(data_result)
|
||||
data_obj['data'] = data_result
|
||||
return save_sql_exec_data(session=self.session, record_id=self.record.id,
|
||||
data=orjson.dumps(data_obj).decode())
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import base64
|
||||
import hashlib
|
||||
import inspect
|
||||
import logging
|
||||
@@ -215,6 +216,20 @@ class SQLBotLogUtil:
|
||||
logger = SQLBotLogUtil._get_logger()
|
||||
if logger.isEnabledFor(logging.CRITICAL):
|
||||
logger._log(logging.CRITICAL, msg, args, **kwargs)
|
||||
|
||||
def prepare_for_orjson(data):
|
||||
if not data:
|
||||
return data
|
||||
if isinstance(data, bytes):
|
||||
return base64.b64encode(data).decode('utf-8')
|
||||
elif isinstance(data, dict):
|
||||
return {k: prepare_for_orjson(v) for k, v in data.items()}
|
||||
elif isinstance(data, (list, tuple)):
|
||||
return [prepare_for_orjson(item) for item in data]
|
||||
else:
|
||||
return data
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user