Super hacky, but when testing, I just save the entire index map to a local file and open it in VS Code
logger.info(f"Conversation to Index Map... FOUND")
# Save to local txt file
with open(f"convo_id_to_index_{datetime.now().strftime('%Y%m%d_%H%M%S')}.txt", "w") as f:
f.write(json.dumps(convo_id_to_index, indent=4, sort_keys=True, default=custom_serializer))
and built a
custom_serializer
to unnest objects
def custom_serializer(obj, depth=0, max_depth=4):
if depth > max_depth:
return str(obj) # or other generic handling
if isinstance(obj, (str, int, float, bool, type(None))):
return obj
elif isinstance(obj, uuid.UUID):
return str(obj)
elif isinstance(obj, dict):
return {key: custom_serializer(value, depth+1, max_depth) for key, value in obj.items()}
elif isinstance(obj, list):
return [custom_serializer(element, depth+1, max_depth) for element in obj]
# elif isinstance(obj, datetime.datetime): # if `import datetime`
# return str(obj)
elif isinstance(obj, datetime): # if `from datetime import datetime`
return str(obj)
elif hasattr(obj, '__dict__'):
return custom_serializer(obj.__dict__, depth+1, max_depth)
else:
return str(obj)