You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+4-4
Original file line number
Diff line number
Diff line change
@@ -200,10 +200,10 @@ We recommend that you always instantiate a client (e.g., with `client = OpenAI()
200
200
201
201
## Using types
202
202
203
-
Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev), which provide helper methods for things like:
203
+
Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev) which also provide helper methods for things like:
204
204
205
-
- Serializing back into JSON, `model.model_dump_json(indent=2, exclude_unset=True)`
206
-
- Converting to a dictionary, `model.model_dump(exclude_unset=True)`
205
+
- Serializing back into JSON, `model.to_json()`
206
+
- Converting to a dictionary, `model.to_dict()`
207
207
208
208
Typed requests and responses provide autocomplete and documentation within your editor. If you would like to see type errors in VS Code to help catch bugs earlier, set `python.analysis.typeCheckingMode` to `basic`.
"""Recursively generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
104
+
105
+
By default, fields that were not set by the API will not be included,
106
+
and keys will match the API response, *not* the property names from the model.
107
+
108
+
For example, if the API responds with `"fooBar": true` but we've defined a `foo_bar: bool` property,
109
+
the output will use the `"fooBar"` key (unless `use_api_names=False` is passed).
110
+
111
+
Args:
112
+
mode:
113
+
If mode is 'json', the dictionary will only contain JSON serializable types. e.g. `datetime` will be turned into a string, `"2024-3-22T18:11:19.117000Z"`.
114
+
If mode is 'python', the dictionary may contain any Python objects. e.g. `datetime(2024, 3, 22)`
115
+
116
+
use_api_names: Whether to use the key that the API responded with or the property name. Defaults to `True`.
117
+
exclude_unset: Whether to exclude fields that have not been explicitly set.
118
+
exclude_defaults: Whether to exclude fields that are set to their default value from the output.
119
+
exclude_none: Whether to exclude fields that have a value of `None` from the output.
120
+
warnings: Whether to log warnings when invalid fields are encountered. This is only supported in Pydantic v2.
121
+
"""
122
+
returnself.model_dump(
123
+
mode=mode,
124
+
by_alias=use_api_names,
125
+
exclude_unset=exclude_unset,
126
+
exclude_defaults=exclude_defaults,
127
+
exclude_none=exclude_none,
128
+
warnings=warnings,
129
+
)
130
+
131
+
defto_json(
132
+
self,
133
+
*,
134
+
indent: int|None=2,
135
+
use_api_names: bool=True,
136
+
exclude_unset: bool=True,
137
+
exclude_defaults: bool=False,
138
+
exclude_none: bool=False,
139
+
warnings: bool=True,
140
+
) ->str:
141
+
"""Generates a JSON string representing this model as it would be received from or sent to the API (but with indentation).
142
+
143
+
By default, fields that were not set by the API will not be included,
144
+
and keys will match the API response, *not* the property names from the model.
145
+
146
+
For example, if the API responds with `"fooBar": true` but we've defined a `foo_bar: bool` property,
147
+
the output will use the `"fooBar"` key (unless `use_api_names=False` is passed).
148
+
149
+
Args:
150
+
indent: Indentation to use in the JSON output. If `None` is passed, the output will be compact. Defaults to `2`
151
+
use_api_names: Whether to use the key that the API responded with or the property name. Defaults to `True`.
152
+
exclude_unset: Whether to exclude fields that have not been explicitly set.
153
+
exclude_defaults: Whether to exclude fields that have the default value.
154
+
exclude_none: Whether to exclude fields that have a value of `None`.
155
+
warnings: Whether to show any warnings that occurred during serialization. This is only supported in Pydantic v2.
0 commit comments