CamelJSONEncoder

class CamelJSONEncoder(JSONEncoder):

A custom JSON encoder for serializing specifically enumerated types. Ensures enumerated types can be stored in and retrieved from JSON format.

default

def default(self, obj):

JsonStorage

class JsonStorage(BaseKeyValueStorage):

A concrete implementation of the :obj:BaseKeyValueStorage using JSON files. Allows for persistent storage of records in a human-readable format.

Parameters:

  • path (Path, optional): Path to the desired JSON file. If None, a default path ./chat_history.json will be used. (default: :obj:None)

init

def __init__(self, path: Optional[Path] = None):

_json_object_hook

def _json_object_hook(self, d):

save

def save(self, records: List[Dict[str, Any]]):

Saves a batch of records to the key-value storage system.

Parameters:

  • records (List[Dict[str, Any]]): A list of dictionaries, where each dictionary represents a unique record to be stored.

load

def load(self):

Returns:

List[Dict[str, Any]]: A list of dictionaries, where each dictionary represents a stored record.

clear

def clear(self):

Removes all records from the key-value storage system.