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

Method model_dump

src/openai/_models.py:303–371  ·  view source on GitHub ↗

Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump Generate a dictionary representation of the model, optionally specifying which fields to include or exclude. Args: mode: The mode in which `to_python` should run.

(
            self,
            *,
            mode: Literal["json", "python"] | str = "python",
            include: IncEx | None = None,
            exclude: IncEx | None = None,
            context: Any | None = None,
            by_alias: bool | None = None,
            exclude_unset: bool = False,
            exclude_defaults: bool = False,
            exclude_none: bool = False,
            exclude_computed_fields: bool = False,
            round_trip: bool = False,
            warnings: bool | Literal["none", "warn", "error"] = True,
            fallback: Callable[[Any], Any] | None = None,
            serialize_as_any: bool = False,
        )

Source from the content-addressed store, hash-verified

301
302 @override
303 def model_dump(
304 self,
305 *,
306 mode: Literal["json", "python"] | str = "python",
307 include: IncEx | None = None,
308 exclude: IncEx | None = None,
309 context: Any | None = None,
310 by_alias: bool | None = None,
311 exclude_unset: bool = False,
312 exclude_defaults: bool = False,
313 exclude_none: bool = False,
314 exclude_computed_fields: bool = False,
315 round_trip: bool = False,
316 warnings: bool | Literal["none", "warn", "error"] = True,
317 fallback: Callable[[Any], Any] | None = None,
318 serialize_as_any: bool = False,
319 ) -> dict[str, Any]:
320 """Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump
321
322 Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
323
324 Args:
325 mode: The mode in which `to_python` should run.
326 If mode is 'json', the output will only contain JSON serializable types.
327 If mode is 'python', the output may contain non-JSON-serializable Python objects.
328 include: A set of fields to include in the output.
329 exclude: A set of fields to exclude from the output.
330 context: Additional context to pass to the serializer.
331 by_alias: Whether to use the field's alias in the dictionary key if defined.
332 exclude_unset: Whether to exclude fields that have not been explicitly set.
333 exclude_defaults: Whether to exclude fields that are set to their default value.
334 exclude_none: Whether to exclude fields that have a value of `None`.
335 exclude_computed_fields: Whether to exclude computed fields.
336 While this can be useful for round-tripping, it is usually recommended to use the dedicated
337 `round_trip` parameter instead.
338 round_trip: If True, dumped values should be valid as input for non-idempotent types such as Json[T].
339 warnings: How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
340 "error" raises a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError].
341 fallback: A function to call when an unknown value is encountered. If not provided,
342 a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError] error is raised.
343 serialize_as_any: Whether to serialize fields with duck-typing serialization behavior.
344
345 Returns:
346 A dictionary representation of the model.
347 """
348 if mode not in {"json", "python"}:
349 raise ValueError("mode must be either 'json' or 'python'")
350 if round_trip != False:
351 raise ValueError("round_trip is only supported in Pydantic v2")
352 if warnings != True:
353 raise ValueError("warnings is only supported in Pydantic v2")
354 if context is not None:
355 raise ValueError("context is only supported in Pydantic v2")
356 if serialize_as_any != False:
357 raise ValueError("serialize_as_any is only supported in Pydantic v2")
358 if fallback is not None:
359 raise ValueError("fallback is only supported in Pydantic v2")
360 if exclude_computed_fields != False:

Calls 1

json_safeFunction · 0.85