全面更换orjson
This commit is contained in:
@@ -4,6 +4,7 @@ import math
|
||||
import random
|
||||
import time
|
||||
import re
|
||||
import orjson
|
||||
import jieba
|
||||
import networkx as nx
|
||||
import numpy as np
|
||||
@@ -999,7 +1000,7 @@ class EntorhinalCortex:
|
||||
# 将memory_items转换为JSON字符串
|
||||
try:
|
||||
memory_items = [str(item) for item in memory_items]
|
||||
memory_items_json = json.dumps(memory_items, ensure_ascii=False)
|
||||
memory_items_json = orjson.dumps(memory_items).decode("utf-8")
|
||||
if not memory_items_json:
|
||||
continue
|
||||
except Exception:
|
||||
@@ -1170,7 +1171,7 @@ class EntorhinalCortex:
|
||||
|
||||
try:
|
||||
memory_items = [str(item) for item in memory_items]
|
||||
if memory_items_json := json.dumps(memory_items, ensure_ascii=False):
|
||||
if memory_items_json := orjson.dumps(memory_items).decode("utf-8"):
|
||||
nodes_data.append(
|
||||
{
|
||||
"concept": concept,
|
||||
@@ -1249,7 +1250,7 @@ class EntorhinalCortex:
|
||||
for node in nodes:
|
||||
concept = node.concept
|
||||
try:
|
||||
memory_items = json.loads(node.memory_items)
|
||||
memory_items = orjson.loads(node.memory_items)
|
||||
if not isinstance(memory_items, list):
|
||||
memory_items = [memory_items] if memory_items else []
|
||||
|
||||
|
||||
@@ -356,10 +356,12 @@ def main():
|
||||
result = diagnostics.run_full_diagnosis()
|
||||
|
||||
# 保存诊断结果
|
||||
import json
|
||||
import orjson
|
||||
with open("action_diagnosis_results.json", "w", encoding="utf-8") as f:
|
||||
json.dump(result, f, indent=2, ensure_ascii=False, default=str)
|
||||
|
||||
f.write(orjson.dumps(
|
||||
result, option=orjson.OPT_INDENT_2).decode('utf-8')
|
||||
)
|
||||
|
||||
logger.info("📄 诊断结果已保存到: action_diagnosis_results.json")
|
||||
|
||||
# 根据诊断结果返回适当的退出代码
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import time
|
||||
import re
|
||||
import json
|
||||
import orjson
|
||||
import ast
|
||||
import traceback
|
||||
|
||||
@@ -69,7 +69,7 @@ class InstantMemory:
|
||||
return None
|
||||
try:
|
||||
repaired = repair_json(response)
|
||||
result = json.loads(repaired)
|
||||
result = orjson.loads(repaired)
|
||||
memory_text = result.get("memory_text", "")
|
||||
keywords = result.get("keywords", "")
|
||||
if isinstance(keywords, str):
|
||||
@@ -142,7 +142,7 @@ class InstantMemory:
|
||||
return None
|
||||
try:
|
||||
repaired = repair_json(response)
|
||||
result = json.loads(repaired)
|
||||
result = orjson.loads(repaired)
|
||||
# 解析keywords
|
||||
keywords = result.get("keywords", "")
|
||||
if isinstance(keywords, str):
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import json
|
||||
import difflib
|
||||
import orjson
|
||||
|
||||
from json_repair import repair_json
|
||||
from typing import List, Dict
|
||||
@@ -30,7 +31,7 @@ def get_keywords_from_json(json_str) -> List:
|
||||
fixed_json = repair_json(json_str)
|
||||
|
||||
# 如果repair_json返回的是字符串,需要解析为Python对象
|
||||
result = json.loads(fixed_json) if isinstance(fixed_json, str) else fixed_json
|
||||
result = orjson.loads(fixed_json) if isinstance(fixed_json, str) else fixed_json
|
||||
return result.get("keywords", [])
|
||||
except Exception as e:
|
||||
logger.error(f"解析关键词JSON失败: {e}")
|
||||
|
||||
Reference in New Issue
Block a user