Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(pydantic): Remaining migrations for deprecated functions #1757

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/examples/content-type/README.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
"\n",
"response = requests.post(\n",
" \"http://localhost:8080/v2/models/content-type-example/infer\",\n",
" json=payload.dict()\n",
" json=payload.model_dump()\n",
")\n",
"\n",
"response_payload = InferenceResponse.parse_raw(response.text)\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/content-type/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ payload = InferenceRequest(

response = requests.post(
"http://localhost:8080/v2/models/content-type-example/infer",
json=payload.dict()
json=payload.model_dump()
)

response_payload = InferenceResponse.parse_raw(response.text)
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/custom/README.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@
")\n",
"\n",
"endpoint = \"http://localhost:8080/v2/models/numpyro-divorce/infer\"\n",
"response = requests.post(endpoint, json=inference_request.dict())\n",
"response = requests.post(endpoint, json=inference_request.model_dump())\n",
"\n",
"response.json()"
]
Expand Down Expand Up @@ -411,7 +411,7 @@
")\n",
"\n",
"endpoint = \"http://localhost:8080/v2/models/numpyro-divorce/infer\"\n",
"response = requests.post(endpoint, json=inference_request.dict())\n",
"response = requests.post(endpoint, json=inference_request.model_dump())\n",
"\n",
"response.json()"
]
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/custom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ inference_request = InferenceRequest(
)

endpoint = "http://localhost:8080/v2/models/numpyro-divorce/infer"
response = requests.post(endpoint, json=inference_request.dict())
response = requests.post(endpoint, json=inference_request.model_dump())

response.json()
```
Expand Down Expand Up @@ -285,7 +285,7 @@ inference_request = InferenceRequest(
)

endpoint = "http://localhost:8080/v2/models/numpyro-divorce/infer"
response = requests.post(endpoint, json=inference_request.dict())
response = requests.post(endpoint, json=inference_request.model_dump())

response.json()
```
Expand Down
184 changes: 92 additions & 92 deletions docs/getting-started/index.md
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explain: The whitespace changes are for trailing spaces, which shouldn't be there.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/user-guide/content-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ MLServer) you will need to **convert them to a Python dict or a JSON string**.

Luckily, these classes leverage [Pydantic](https://docs.pydantic.dev/latest/)
under the hood.
Therefore you can just call the `.dict()` or `.json()` method to convert them.
Therefore you can just call the `.model_dump()` or `.model_dump_json()` method to convert them.
Likewise, to read them back from JSON, we can always pass the JSON fields as
kwargs to the class' constructor (or use any of the [other
methods](https://docs.pydantic.dev/latest/usage/models/#model-properties)
Expand Down
2 changes: 1 addition & 1 deletion tests/repository/test_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def custom_module_settings_path(
# Add modified settings, pointing to local module
model_settings_path = os.path.join(tmp_path, DEFAULT_MODEL_SETTINGS_FILENAME)
with open(model_settings_path, "w") as f:
settings_dict = sum_model_settings.dict()
settings_dict = sum_model_settings.model_dump()
# Point to local module
settings_dict["implementation"] = "fixtures.SumModel"
f.write(json.dumps(settings_dict))
Expand Down
6 changes: 1 addition & 5 deletions tests/rest/test_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"data": [21.0],
"parameters": {
"content_type": NumpyCodec.ContentType,
"headers": None,
},
},
),
Expand All @@ -35,7 +34,6 @@
"data": ["\x01\x02"],
"parameters": {
"content_type": NumpyCodec.ContentType,
"headers": None,
},
},
),
Expand All @@ -49,7 +47,6 @@
"data": ["hey", "what's", "up"],
"parameters": {
"content_type": StringCodec.ContentType,
"headers": None,
},
},
),
Expand All @@ -63,7 +60,6 @@
"data": ["UHl0aG9uIGlzIGZ1bg=="],
"parameters": {
"content_type": Base64Codec.ContentType,
"headers": None,
},
},
),
Expand All @@ -73,7 +69,7 @@ def test_encode_output_tensor(decoded: Any, codec: InputCodec, expected: dict):
# Serialise response into final output bytes
payload = codec.encode_output(name="output-0", payload=decoded)
response = Response(content=None)
rendered_as_bytes = response.render(payload.dict())
rendered_as_bytes = response.render(payload.model_dump())

# Decode response back into JSON and check if it matches the expected one
rendered = rendered_as_bytes.decode("utf8")
Expand Down
Loading