@@ -22,23 +22,30 @@ def deserialize(self, value: str) -> Any: ...
22
22
class JsonSerializer (BaseSerializer ):
23
23
def _serialize_value (self , value : Any ) -> Any :
24
24
"""Helper to serialize a single value."""
25
- # FIXME: move BaseComponent out of llamaindex core
26
- # if isinstance(value, BaseComponent):
27
- # return {
28
- # "__is_component": True,
29
- # "value": value.to_dict(),
30
- # "qualified_name": get_qualified_name(value),
31
- # }
25
+ # Note: to avoid circular dependencies we cannot import BaseComponent from llama_index.core
26
+ # if we want to use isinstance(value, BaseComponent) instead of guessing type from the presence
27
+ # of class_name, we need to move BaseComponent out of core
28
+ if hasattr (value , "class_name" ):
29
+ retval = {
30
+ "__is_component" : True ,
31
+ "value" : value .to_dict (),
32
+ "qualified_name" : get_qualified_name (value ),
33
+ }
34
+ return retval
35
+
32
36
if isinstance (value , BaseModel ):
33
37
return {
34
38
"__is_pydantic" : True ,
35
39
"value" : value .model_dump (),
36
40
"qualified_name" : get_qualified_name (value ),
37
41
}
38
- elif isinstance (value , dict ):
42
+
43
+ if isinstance (value , dict ):
39
44
return {k : self ._serialize_value (v ) for k , v in value .items ()}
40
- elif isinstance (value , list ):
45
+
46
+ if isinstance (value , list ):
41
47
return [self ._serialize_value (item ) for item in value ]
48
+
42
49
return value
43
50
44
51
def serialize (self , value : Any ) -> str :
0 commit comments