Fix: prevent infinity bug on agent (#4876)
* Fix error handling and logging in build_flow function * Refactor: Update serialize_field function in utils.py This commit refactors the serialize_field function in utils.py to handle additional data types. It now properly serializes BaseModel objects and dictionaries by recursively calling the serialize_field function on their values. Additionally, it ensures that all other data types are converted to strings before returning. #4873 * update serialize
This commit is contained in:
parent
77289793c5
commit
907d9929e4
2 changed files with 8 additions and 4 deletions
|
|
@ -409,6 +409,10 @@ async def build_flow(
|
|||
for task in tasks:
|
||||
task.cancel()
|
||||
return
|
||||
except Exception as e:
|
||||
logger.error(f"Error building vertices: {e}")
|
||||
event_manager.on_error(data={"error": str(e)})
|
||||
raise
|
||||
event_manager.on_end(data={})
|
||||
await event_manager.queue.put((None, None, time.time))
|
||||
|
||||
|
|
|
|||
|
|
@ -79,14 +79,14 @@ def serialize_field(value):
|
|||
if isinstance(value, Document):
|
||||
return value.to_json()
|
||||
if isinstance(value, BaseModel):
|
||||
return value.model_dump()
|
||||
return serialize_field(value.model_dump())
|
||||
if isinstance(value, dict):
|
||||
return {k: serialize_field(v) for k, v in value.items()}
|
||||
if isinstance(value, V1BaseModel):
|
||||
if hasattr(value, "to_json"):
|
||||
return value.to_json()
|
||||
return value.dict()
|
||||
if isinstance(value, str):
|
||||
return {"result": value}
|
||||
return value
|
||||
return str(value)
|
||||
|
||||
|
||||
def get_artifact_type(value, build_result) -> str:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue