在这个例子中,exclude_unset 和exclude_defaults 都排除了 age 和email 字段,因为它们要么未设置(exclude_unset),要么等于默认值(exclude_defaults)。 综上所述,exclude 参数在 model_dump 方法中提供了一种灵活的方式来排除不需要的字段,无论是顶层字段还是嵌套字段。
model_dump(exclude_unset=True) extra_data = {} if "password" in hero_data: password = hero_data["password"] hashed_password = hash_password(password) extra_data["hashed_password"] = hashed_password db_hero.sqlmodel_update(hero_data, update=extra_data) ...
model_dump(exclude_unset=True)) if "key" in props: props["key"] = AssetKey.from_user_string(props["key"]) return props class AssetSpecModel(_ResolvableAssetAttributesMixin, ResolvableModel[AssetSpec]): key: Annotated[Optional[str], ResolvableFieldInfo(output_type=AssetKey)] def resolve(self...
model_dump( mode='json', exclude_none=True, exclude_unset=True, exclude_defaults=True ) DictToModelValidator = convert_dict_to_model_validator_factory ModelToDictValidator = AfterValidator(convert_model_to_dict) class Child(SQLModel): one: int two: float class Custom(SQLModel): boolean: ...
model_dump(exclude_unset=True) db_hero.sqlmodel_update(hero_data) session.add(db_hero) session.commit() session.refresh(db_hero) return db_hero 👀 Full file preview Python 3.10+ from fastapi import FastAPI, HTTPException, Query from sqlmodel import Field, Session, SQLModel, create_engine...
exclude: Union[IncEx, None] = None, context: Union[Dict[str, Any], None] = None, by_alias: bool = False, exclude_unset: bool = False, @@ -908,8 +913,8 @@ def model_dump( def dict( self, *, include: IncEx = None, exclude: IncEx = None, include: Union[IncEx, None] ...
yield"{}".format(chunk.model_dump_json(exclude_unset=True)) Expand All@@ -327,7 +333,7 @@ async def predict(model_id: str, params: dict): delta=DeltaMessage(), finish_reason="stop" ) chunk=ChatCompletionResponse(model=model_id,choices=[ ...
8 + # registry.cn-hangzhou.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.7.1-py38-torch2.0.1-tf1.15.5-1.8.0 9 + # registry.cn-beijing.aliyuncs.com/modelscope-repo/modelscope:ubuntu20.04-cuda11.7.1-py38-torch2.0.1-tf1.15.5-1.8.0 10 + FROM registry.cn-hangzhou.aliyuncs...