mirror of
https://github.com/MODSetter/SurfSense.git
synced 2025-09-09 22:04:47 +00:00
SurfSense v3 - Highlight: Local LLM Support
This commit is contained in:
parent
04df919cf9
commit
7f38091d3d
13 changed files with 692 additions and 1345 deletions
27
backend/Utils/stringify.py
Normal file
27
backend/Utils/stringify.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
from collections import OrderedDict
|
||||
|
||||
try:
|
||||
from collections.abc import Mapping, Sequence
|
||||
except ImportError:
|
||||
from collections import Mapping, Sequence
|
||||
|
||||
import json
|
||||
|
||||
COMPACT_SEPARATORS = (',', ':')
|
||||
|
||||
def order_by_key(kv):
|
||||
key, val = kv
|
||||
return key
|
||||
|
||||
def recursive_order(node):
|
||||
if isinstance(node, Mapping):
|
||||
ordered_mapping = OrderedDict(sorted(node.items(), key=order_by_key))
|
||||
for key, value in ordered_mapping.items():
|
||||
ordered_mapping[key] = recursive_order(value)
|
||||
return ordered_mapping
|
||||
elif isinstance(node, Sequence) and not isinstance(node, (str, bytes)):
|
||||
return [recursive_order(item) for item in node]
|
||||
return node
|
||||
|
||||
def stringify(node):
|
||||
return json.dumps(recursive_order(node), separators=COMPACT_SEPARATORS)
|
Loading…
Add table
Add a link
Reference in a new issue