MCPcopy
hub / github.com/openai/openai-python / model_dump

Function model_dump

src/openai/_compat.py:138–166  ·  view source on GitHub ↗
(
    model: pydantic.BaseModel,
    *,
    exclude: IncEx | None = None,
    exclude_unset: bool = False,
    exclude_defaults: bool = False,
    warnings: bool = True,
    mode: Literal["json", "python"] = "python",
    by_alias: bool | None = None,
)

Source from the content-addressed store, hash-verified

136
137
138def model_dump(
139 model: pydantic.BaseModel,
140 *,
141 exclude: IncEx | None = None,
142 exclude_unset: bool = False,
143 exclude_defaults: bool = False,
144 warnings: bool = True,
145 mode: Literal["json", "python"] = "python",
146 by_alias: bool | None = None,
147) -> dict[str, Any]:
148 if (not PYDANTIC_V1) or hasattr(model, "model_dump"):
149 kwargs: _ModelDumpKwargs = {}
150 if by_alias is not None:
151 kwargs["by_alias"] = by_alias
152 return model.model_dump(
153 mode=mode,
154 exclude=exclude,
155 exclude_unset=exclude_unset,
156 exclude_defaults=exclude_defaults,
157 # warnings are not supported in Pydantic v1
158 warnings=True if PYDANTIC_V1 else warnings,
159 **kwargs,
160 )
161 return cast(
162 "dict[str, Any]",
163 model.dict( # pyright: ignore[reportDeprecated, reportUnnecessaryCast]
164 exclude=exclude, exclude_unset=exclude_unset, exclude_defaults=exclude_defaults, by_alias=bool(by_alias)
165 ),
166 )
167
168
169def model_parse(model: type[_ModelT], data: Any) -> _ModelT:

Callers 10

test_unknown_fieldsFunction · 0.90
_build_requestMethod · 0.85
defaultMethod · 0.85
_transform_recursiveFunction · 0.85
accumulate_run_stepFunction · 0.85
accumulate_eventFunction · 0.85
_accumulate_chunkMethod · 0.85

Calls 1

model_dumpMethod · 0.80