全面更换orjson
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import time
|
||||
import json
|
||||
import orjson
|
||||
import hashlib
|
||||
from pathlib import Path
|
||||
import numpy as np
|
||||
@@ -106,7 +106,7 @@ class CacheManager:
|
||||
logger.warning(f"无法获取文件信息: {tool_file_path},错误: {e}")
|
||||
|
||||
try:
|
||||
sorted_args = json.dumps(function_args, sort_keys=True)
|
||||
sorted_args = orjson.dumps(function_args, option=orjson.OPT_SORT_KEYS).decode('utf-8')
|
||||
except TypeError:
|
||||
sorted_args = repr(sorted(function_args.items()))
|
||||
return f"{tool_name}::{sorted_args}::{file_hash}"
|
||||
@@ -163,7 +163,7 @@ class CacheManager:
|
||||
expires_at = cache_results["expires_at"]
|
||||
if time.time() < expires_at:
|
||||
logger.info(f"命中L2键值缓存: {key}")
|
||||
data = json.loads(cache_results["cache_value"])
|
||||
data = orjson.loads(cache_results["cache_value"])
|
||||
|
||||
# 更新访问统计
|
||||
await db_query(
|
||||
@@ -209,7 +209,7 @@ class CacheManager:
|
||||
if semantic_cache_results:
|
||||
expires_at = semantic_cache_results["expires_at"]
|
||||
if time.time() < expires_at:
|
||||
data = json.loads(semantic_cache_results["cache_value"])
|
||||
data = orjson.loads(semantic_cache_results["cache_value"])
|
||||
logger.debug(f"L2语义缓存返回的数据: {data}")
|
||||
|
||||
# 回填 L1
|
||||
@@ -245,7 +245,7 @@ class CacheManager:
|
||||
# 写入 L2 (数据库)
|
||||
cache_data = {
|
||||
"cache_key": key,
|
||||
"cache_value": json.dumps(data, ensure_ascii=False),
|
||||
"cache_value": orjson.dumps(data).decode('utf-8'),
|
||||
"expires_at": expires_at,
|
||||
"tool_name": tool_name,
|
||||
"created_at": time.time(),
|
||||
|
||||
@@ -340,14 +340,14 @@ async def store_action_info(
|
||||
保存的记录数据或None
|
||||
"""
|
||||
try:
|
||||
import json
|
||||
import orjson
|
||||
|
||||
# 构建动作记录数据
|
||||
record_data = {
|
||||
"action_id": thinking_id or str(int(time.time() * 1000000)),
|
||||
"time": time.time(),
|
||||
"action_name": action_name,
|
||||
"action_data": json.dumps(action_data or {}, ensure_ascii=False),
|
||||
"action_data": orjson.dumps(action_data or {}).decode('utf-8'),
|
||||
"action_done": action_done,
|
||||
"action_build_into_prompt": action_build_into_prompt,
|
||||
"action_prompt_display": action_prompt_display,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# 使用基于时间戳的文件处理器,简单的轮转份数限制
|
||||
|
||||
import logging
|
||||
import json
|
||||
import orjson
|
||||
import threading
|
||||
import time
|
||||
import structlog
|
||||
@@ -696,7 +696,7 @@ class ModuleColoredConsoleRenderer:
|
||||
elif isinstance(event, dict):
|
||||
# 如果是字典,格式化为可读字符串
|
||||
try:
|
||||
event_content = json.dumps(event, ensure_ascii=False, indent=None)
|
||||
event_content = orjson.dumps(event).decode("utf-8")
|
||||
except (TypeError, ValueError):
|
||||
event_content = str(event)
|
||||
else:
|
||||
@@ -716,7 +716,7 @@ class ModuleColoredConsoleRenderer:
|
||||
# 确保值也转换为字符串
|
||||
if isinstance(value, (dict, list)):
|
||||
try:
|
||||
value_str = json.dumps(value, ensure_ascii=False, indent=None)
|
||||
value_str = orjson.dumps(value).decode("utf-8")
|
||||
except (TypeError, ValueError):
|
||||
value_str = str(value)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user