mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-10-04 20:14:13 +00:00
chore(replay): improve replay robustness with un-validated construction
some providers do not produce spec compliant outputs. when this happens the replay infra will fail to construct the proper types and will return a dict to the client. the client likely does not expect a dict. this was discovered with tgi, which returns finish_reason="" when valid values are "stop", "length" or "content_filter"
This commit is contained in:
parent
c04f1c1e8c
commit
b0364572b2
1 changed files with 6 additions and 2 deletions
|
@ -105,8 +105,12 @@ def _deserialize_response(data: dict[str, Any]) -> Any:
|
||||||
|
|
||||||
return cls.model_validate(data["__data__"])
|
return cls.model_validate(data["__data__"])
|
||||||
except (ImportError, AttributeError, TypeError, ValueError) as e:
|
except (ImportError, AttributeError, TypeError, ValueError) as e:
|
||||||
logger.warning(f"Failed to deserialize object of type {data['__type__']}: {e}")
|
logger.warning(f"Failed to deserialize object of type {data['__type__']} with model_validate: {e}")
|
||||||
return data["__data__"]
|
try:
|
||||||
|
return cls.model_construct(**data["__data__"])
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"Failed to deserialize object of type {data['__type__']} with model_construct: {e}")
|
||||||
|
return data["__data__"]
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue