File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -84,11 +84,9 @@ def _find_and_process_media(
8484 max_levels = 10
8585
8686 def _process_data_recursively (data : Any , level : int ) -> Any :
87- if id ( data ) in seen or level > max_levels :
87+ if level > max_levels :
8888 return data
8989
90- seen .add (id (data ))
91-
9290 if isinstance (data , LangfuseMedia ):
9391 self ._process_media (
9492 media = data ,
@@ -176,6 +174,24 @@ def _process_data_recursively(data: Any, level: int) -> Any:
176174 for key , value in data .items ()
177175 }
178176
177+ if hasattr (data , "model_dump" ) and callable (data .model_dump ):
178+ # Pydantic v2 BaseModel
179+ if id (data ) in seen :
180+ return data
181+
182+ seen .add (id (data ))
183+
184+ return _process_data_recursively (data .model_dump (), level + 1 )
185+
186+ if hasattr (data , "dict" ) and callable (data .dict ) and hasattr (data , "__fields__" ):
187+ # Pydantic v1 BaseModel
188+ if id (data ) in seen :
189+ return data
190+
191+ seen .add (id (data ))
192+
193+ return _process_data_recursively (data .dict (), level + 1 )
194+
179195 return data
180196
181197 return _process_data_recursively (data , 1 )
You can’t perform that action at this time.
0 commit comments