mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-08 15:05:17 +02:00
update comment
This commit is contained in:
parent
4846f60d60
commit
5ff3e0de7d
2 changed files with 8 additions and 8 deletions
|
|
@ -147,7 +147,7 @@ class SerializationMixin(BaseModel, extra="forbid"):
|
|||
|
||||
serialized_data = self.model_dump()
|
||||
|
||||
write_json_file(file_path, serialized_data)
|
||||
write_json_file(file_path, serialized_data, use_fallback=True)
|
||||
logger.debug(f"{self.__class__.__qualname__} serialization successful. File saved at: {file_path}")
|
||||
|
||||
return file_path
|
||||
|
|
|
|||
|
|
@ -581,20 +581,20 @@ def read_json_file(json_file: str, encoding: str = "utf-8") -> list[Any]:
|
|||
|
||||
|
||||
def handle_unknown_serialization(x: Any) -> str:
|
||||
"""For `to_jsonable_python` debug, unknown values will be logged instead of raising an exception."""
|
||||
"""For `to_jsonable_python` debug, get more detail about the x."""
|
||||
|
||||
if inspect.ismethod(x):
|
||||
logger.error(f"Method: {x.__self__.__class__.__name__}.{x.__func__.__name__}")
|
||||
tip = f"Cannot serialize method '{x.__func__.__name__}' of class '{x.__self__.__class__.__name__}'"
|
||||
elif inspect.isfunction(x):
|
||||
logger.error(f"Function: {x.__name__}")
|
||||
tip = f"Cannot serialize function '{x.__name__}'"
|
||||
elif hasattr(x, "__class__"):
|
||||
logger.error(f"Instance of: {x.__class__.__name__}")
|
||||
tip = f"Cannot serialize instance of '{x.__class__.__name__}'"
|
||||
elif hasattr(x, "__name__"):
|
||||
logger.error(f"Class or module: {x.__name__}")
|
||||
tip = f"Cannot serialize class or module '{x.__name__}'"
|
||||
else:
|
||||
logger.error(f"Unknown type: {type(x)}")
|
||||
tip = f"Cannot serialize object of type '{type(x).__name__}'"
|
||||
|
||||
return f"<Unserializable {type(x).__name__} object>"
|
||||
raise TypeError(tip)
|
||||
|
||||
|
||||
def write_json_file(json_file: str, data: Any, encoding: str = "utf-8", indent: int = 4, use_fallback: bool = False):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue