Skip to content

Commit 12b7fec

Browse files
authored
fix: fix serialization of BaseComponent from llama_index core (#5)
1 parent babb11e commit 12b7fec

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/workflows/context/serializers.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,30 @@ def deserialize(self, value: str) -> Any: ...
2222
class JsonSerializer(BaseSerializer):
2323
def _serialize_value(self, value: Any) -> Any:
2424
"""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+
3236
if isinstance(value, BaseModel):
3337
return {
3438
"__is_pydantic": True,
3539
"value": value.model_dump(),
3640
"qualified_name": get_qualified_name(value),
3741
}
38-
elif isinstance(value, dict):
42+
43+
if isinstance(value, dict):
3944
return {k: self._serialize_value(v) for k, v in value.items()}
40-
elif isinstance(value, list):
45+
46+
if isinstance(value, list):
4147
return [self._serialize_value(item) for item in value]
48+
4249
return value
4350

4451
def serialize(self, value: Any) -> str:

0 commit comments

Comments
 (0)