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

Method model_dump_json

src/openai/_models.py:374–432  ·  view source on GitHub ↗

Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump_json Generates a JSON representation of the model using Pydantic's `to_json` method. Args: indent: Indentation to use in the JSON output. If None is passed, the output will be

(
            self,
            *,
            indent: int | None = None,
            ensure_ascii: bool = False,
            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

372
373 @override
374 def model_dump_json(
375 self,
376 *,
377 indent: int | None = None,
378 ensure_ascii: bool = False,
379 include: IncEx | None = None,
380 exclude: IncEx | None = None,
381 context: Any | None = None,
382 by_alias: bool | None = None,
383 exclude_unset: bool = False,
384 exclude_defaults: bool = False,
385 exclude_none: bool = False,
386 exclude_computed_fields: bool = False,
387 round_trip: bool = False,
388 warnings: bool | Literal["none", "warn", "error"] = True,
389 fallback: Callable[[Any], Any] | None = None,
390 serialize_as_any: bool = False,
391 ) -> str:
392 """Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump_json
393
394 Generates a JSON representation of the model using Pydantic's `to_json` method.
395
396 Args:
397 indent: Indentation to use in the JSON output. If None is passed, the output will be compact.
398 include: Field(s) to include in the JSON output. Can take either a string or set of strings.
399 exclude: Field(s) to exclude from the JSON output. Can take either a string or set of strings.
400 by_alias: Whether to serialize using field aliases.
401 exclude_unset: Whether to exclude fields that have not been explicitly set.
402 exclude_defaults: Whether to exclude fields that have the default value.
403 exclude_none: Whether to exclude fields that have a value of `None`.
404 round_trip: Whether to use serialization/deserialization between JSON and class instance.
405 warnings: Whether to show any warnings that occurred during serialization.
406
407 Returns:
408 A JSON string representation of the model.
409 """
410 if round_trip != False:
411 raise ValueError("round_trip is only supported in Pydantic v2")
412 if warnings != True:
413 raise ValueError("warnings is only supported in Pydantic v2")
414 if context is not None:
415 raise ValueError("context is only supported in Pydantic v2")
416 if serialize_as_any != False:
417 raise ValueError("serialize_as_any is only supported in Pydantic v2")
418 if fallback is not None:
419 raise ValueError("fallback is only supported in Pydantic v2")
420 if ensure_ascii != False:
421 raise ValueError("ensure_ascii is only supported in Pydantic v2")
422 if exclude_computed_fields != False:
423 raise ValueError("exclude_computed_fields is only supported in Pydantic v2")
424 return super().json( # type: ignore[reportDeprecated]
425 indent=indent,
426 include=include,
427 exclude=exclude,
428 by_alias=by_alias if by_alias is not None else False,
429 exclude_unset=exclude_unset,
430 exclude_defaults=exclude_defaults,
431 exclude_none=exclude_none,

Callers 3

to_jsonMethod · 0.95
model_jsonFunction · 0.80

Calls 1

jsonMethod · 0.45