Skip to content

Commit

Permalink
refactor(pydantic): Remaining migrations for deprecated functions (#1757
Browse files Browse the repository at this point in the history
)

These were missed in #1748.
  • Loading branch information
Jesse Claven authored May 13, 2024
1 parent bcd8e7f commit a2c0d64
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 105 deletions.
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

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

0 comments on commit a2c0d64

Please sign in to comment.