We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Pydantic ValidationError due to dropped InferRequest id
/kind bug

**What steps did you take and what happened:**
[A clear and concise description of what the bug is.]
I am using kserve as a wrapper around Torchserve, with the v2 Inference API. A pydantic validation error is thrown when parsing the returned InferenceResponse due to the created InferRequest dropping the id. The downstream torchserve inferene then receives a null id, and returns null id in its response too.

```
2023-05-25 14:39:33.490 16 uvicorn.error ERROR [run_asgi():376] Exception in ASGI application
Traceback (most recent call last):
  File "/opt/env/lib/python3.9/site-packages/uvicorn/protocols/http/h11_impl.py", line 373, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/opt/env/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 75, in __call__
    return await self.app(scope, receive, send)
  File "/opt/env/lib/python3.9/site-packages/fastapi/applications.py", line 270, in __call__
    await super().__call__(scope, receive, send)
  File "/opt/env/lib/python3.9/site-packages/starlette/applications.py", line 124, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/opt/env/lib/python3.9/site-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/opt/env/lib/python3.9/site-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/opt/env/lib/python3.9/site-packages/timing_asgi/middleware.py", line 68, in __call__
    await self.app(scope, receive, send_wrapper)
  File "/opt/env/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
    raise exc
  File "/opt/env/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "/opt/env/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "/opt/env/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/opt/env/lib/python3.9/site-packages/starlette/routing.py", line 706, in __call__
    await route.handle(scope, receive, send)
  File "/opt/env/lib/python3.9/site-packages/starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "/opt/env/lib/python3.9/site-packages/starlette/routing.py", line 66, in app
    response = await func(request)
  File "/opt/env/lib/python3.9/site-packages/fastapi/routing.py", line 235, in app
    raw_response = await run_endpoint_function(
  File "/opt/env/lib/python3.9/site-packages/fastapi/routing.py", line 161, in run_endpoint_function
    return await dependant.call(**values)
  File "/opt/env/lib/python3.9/site-packages/kserve/protocol/rest/v2_endpoints.py", line 135, in infer
    res = InferenceResponse.parse_obj(response)
  File "pydantic/main.py", line 526, in pydantic.main.BaseModel.parse_obj
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for InferenceResponse
id
  none is not an allowed value (type=type_error.none.not_allowed)
```

I will create a simple PR to fix this.

**What did you expect to happen:**
Inference to succeed, with id passed through.


**What's the InferenceService yaml:**
[To help us debug please run `kubectl get isvc $name -n $namespace -oyaml` and paste the output]
Not applicable. Testing with docker.

**Anything else you would like to add:**
[Miscellaneous information that will assist in solving the issue.]
Not applicable.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `python/kserve/kserve/protocol/rest/v2_endpoints.py`
Content:
```
1 # Copyright 2022 The KServe Authors.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #    http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 from typing import Optional, Dict
16 
17 from fastapi.requests import Request
18 from fastapi.responses import Response
19 
20 from ..infer_type import InferInput, InferRequest
21 from .v2_datamodels import (
22     InferenceRequest, ServerMetadataResponse, ServerLiveResponse, ServerReadyResponse,
23     ModelMetadataResponse, InferenceResponse, ModelReadyResponse
24 )
25 from ..dataplane import DataPlane
26 from ..model_repository_extension import ModelRepositoryExtension
27 from ...errors import ModelNotReady
28 
29 
30 class V2Endpoints:
31     """KServe V2 Endpoints
32     """
33 
34     def __init__(self, dataplane: DataPlane, model_repository_extension: Optional[ModelRepositoryExtension] = None):
35         self.model_repository_extension = model_repository_extension
36         self.dataplane = dataplane
37 
38     async def metadata(self) -> ServerMetadataResponse:
39         """Server metadata endpoint.
40 
41         Returns:
42             ServerMetadataResponse: Server metadata JSON object.
43         """
44         return ServerMetadataResponse.parse_obj(self.dataplane.metadata())
45 
46     @staticmethod
47     async def live() -> ServerLiveResponse:
48         """Server live endpoint.
49 
50         Returns:
51             ServerLiveResponse: Server live message.
52         """
53         return ServerLiveResponse(live=True)
54 
55     @staticmethod
56     async def ready() -> ServerReadyResponse:
57         """Server ready endpoint.
58 
59         Returns:
60             ServerReadyResponse: Server ready message.
61         """
62         return ServerReadyResponse(ready=True)
63 
64     async def model_metadata(self, model_name: str, model_version: Optional[str] = None) -> ModelMetadataResponse:
65         """Model metadata handler. It provides information about a model.
66 
67         Args:
68             model_name (str): Model name.
69             model_version (Optional[str]): Model version (optional).
70 
71         Returns:
72             ModelMetadataResponse: Model metadata object.
73         """
74         # TODO: support model_version
75         if model_version:
76             raise NotImplementedError("Model versioning not supported yet.")
77 
78         metadata = await self.dataplane.model_metadata(model_name)
79         return ModelMetadataResponse.parse_obj(metadata)
80 
81     async def model_ready(self, model_name: str, model_version: Optional[str] = None) -> ModelReadyResponse:
82         """Check if a given model is ready.
83 
84         Args:
85             model_name (str): Model name.
86             model_version (str): Model version.
87 
88         Returns:
89             ModelReadyResponse: Model ready object
90         """
91         # TODO: support model_version
92         if model_version:
93             raise NotImplementedError("Model versioning not supported yet.")
94 
95         model_ready = self.dataplane.model_ready(model_name)
96 
97         if not model_ready:
98             raise ModelNotReady(model_name)
99 
100         return ModelReadyResponse.parse_obj({"name": model_name, "ready": model_ready})
101 
102     async def infer(
103         self,
104         raw_request: Request,
105         raw_response: Response,
106         model_name: str,
107         request_body: InferenceRequest,
108         model_version: Optional[str] = None
109     ) -> InferenceResponse:
110         """Infer handler.
111 
112         Args:
113             raw_request (Request): fastapi request object,
114             raw_response (Response): fastapi response object,
115             model_name (str): Model name.
116             request_body (InferenceRequest): Inference request body.
117             model_version (Optional[str]): Model version (optional).
118 
119         Returns:
120             InferenceResponse: Inference response object.
121         """
122         # TODO: support model_version
123         if model_version:
124             raise NotImplementedError("Model versioning not supported yet.")
125 
126         model_ready = self.dataplane.model_ready(model_name)
127 
128         if not model_ready:
129             raise ModelNotReady(model_name)
130 
131         request_headers = dict(raw_request.headers)
132         infer_inputs = [InferInput(name=input.name, shape=input.shape, datatype=input.datatype,
133                                    data=input.data,
134                                    parameters={} if input.parameters is None else input.parameters
135                                    ) for input in request_body.inputs]
136         infer_request = InferRequest(model_name=model_name, infer_inputs=infer_inputs,
137                                      parameters=request_body.parameters)
138         response, response_headers = await self.dataplane.infer(model_name=model_name,
139                                                                 request=infer_request,
140                                                                 headers=request_headers)
141 
142         response, response_headers = self.dataplane.encode(model_name=model_name,
143                                                            response=response,
144                                                            headers=response_headers, req_attributes={})
145 
146         if response_headers:
147             raw_response.headers.update(response_headers)
148         res = InferenceResponse.parse_obj(response)
149         return res
150 
151     async def load(self, model_name: str) -> Dict:
152         """Model load handler.
153 
154         Args:
155             model_name (str): Model name.
156 
157         Returns:
158             Dict: {"name": model_name, "load": True}
159         """
160         await self.model_repository_extension.load(model_name)
161         return {"name": model_name, "load": True}
162 
163     async def unload(self, model_name: str) -> Dict:
164         """Model unload handler.
165 
166         Args:
167             model_name (str): Model name.
168 
169         Returns:
170             Dict: {"name": model_name, "unload": True}
171         """
172         await self.model_repository_extension.unload(model_name)
173         return {"name": model_name, "unload": True}
174
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/python/kserve/kserve/protocol/rest/v2_endpoints.py b/python/kserve/kserve/protocol/rest/v2_endpoints.py
--- a/python/kserve/kserve/protocol/rest/v2_endpoints.py
+++ b/python/kserve/kserve/protocol/rest/v2_endpoints.py
@@ -133,7 +133,7 @@
                                    data=input.data,
                                    parameters={} if input.parameters is None else input.parameters
                                    ) for input in request_body.inputs]
-        infer_request = InferRequest(model_name=model_name, infer_inputs=infer_inputs,
+        infer_request = InferRequest(request_id=request_body.id, model_name=model_name, infer_inputs=infer_inputs,
                                      parameters=request_body.parameters)
         response, response_headers = await self.dataplane.infer(model_name=model_name,
                                                                 request=infer_request,

{"golden_diff": "diff --git a/python/kserve/kserve/protocol/rest/v2_endpoints.py b/python/kserve/kserve/protocol/rest/v2_endpoints.py\n--- a/python/kserve/kserve/protocol/rest/v2_endpoints.py\n+++ b/python/kserve/kserve/protocol/rest/v2_endpoints.py\n@@ -133,7 +133,7 @@\n                                    data=input.data,\n                                    parameters={} if input.parameters is None else input.parameters\n                                    ) for input in request_body.inputs]\n-        infer_request = InferRequest(model_name=model_name, infer_inputs=infer_inputs,\n+        infer_request = InferRequest(request_id=request_body.id, model_name=model_name, infer_inputs=infer_inputs,\n                                      parameters=request_body.parameters)\n         response, response_headers = await self.dataplane.infer(model_name=model_name,\n                                                                 request=infer_request,\n", "issue": "Pydantic ValidationError due to dropped InferRequest id\n/kind bug\r\n\r\n**What steps did you take and what happened:**\r\n[A clear and concise description of what the bug is.]\r\nI am using kserve as a wrapper around Torchserve, with the v2 Inference API. A pydantic validation error is thrown when parsing the returned InferenceResponse due to the created InferRequest dropping the id. The downstream torchserve inferene then receives a null id, and returns null id in its response too.\r\n\r\n```\r\n2023-05-25 14:39:33.490 16 uvicorn.error ERROR [run_asgi():376] Exception in ASGI application\r\nTraceback (most recent call last):\r\n  File \"/opt/env/lib/python3.9/site-packages/uvicorn/protocols/http/h11_impl.py\", line 373, in run_asgi\r\n    result = await app(self.scope, self.receive, self.send)\r\n  File \"/opt/env/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py\", line 75, in __call__\r\n    return await self.app(scope, receive, send)\r\n  File \"/opt/env/lib/python3.9/site-packages/fastapi/applications.py\", line 270, in __call__\r\n    await super().__call__(scope, receive, send)\r\n  File \"/opt/env/lib/python3.9/site-packages/starlette/applications.py\", line 124, in __call__\r\n    await self.middleware_stack(scope, receive, send)\r\n  File \"/opt/env/lib/python3.9/site-packages/starlette/middleware/errors.py\", line 184, in __call__\r\n    raise exc\r\n  File \"/opt/env/lib/python3.9/site-packages/starlette/middleware/errors.py\", line 162, in __call__\r\n    await self.app(scope, receive, _send)\r\n  File \"/opt/env/lib/python3.9/site-packages/timing_asgi/middleware.py\", line 68, in __call__\r\n    await self.app(scope, receive, send_wrapper)\r\n  File \"/opt/env/lib/python3.9/site-packages/starlette/middleware/exceptions.py\", line 79, in __call__\r\n    raise exc\r\n  File \"/opt/env/lib/python3.9/site-packages/starlette/middleware/exceptions.py\", line 68, in __call__\r\n    await self.app(scope, receive, sender)\r\n  File \"/opt/env/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py\", line 21, in __call__\r\n    raise e\r\n  File \"/opt/env/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py\", line 18, in __call__\r\n    await self.app(scope, receive, send)\r\n  File \"/opt/env/lib/python3.9/site-packages/starlette/routing.py\", line 706, in __call__\r\n    await route.handle(scope, receive, send)\r\n  File \"/opt/env/lib/python3.9/site-packages/starlette/routing.py\", line 276, in handle\r\n    await self.app(scope, receive, send)\r\n  File \"/opt/env/lib/python3.9/site-packages/starlette/routing.py\", line 66, in app\r\n    response = await func(request)\r\n  File \"/opt/env/lib/python3.9/site-packages/fastapi/routing.py\", line 235, in app\r\n    raw_response = await run_endpoint_function(\r\n  File \"/opt/env/lib/python3.9/site-packages/fastapi/routing.py\", line 161, in run_endpoint_function\r\n    return await dependant.call(**values)\r\n  File \"/opt/env/lib/python3.9/site-packages/kserve/protocol/rest/v2_endpoints.py\", line 135, in infer\r\n    res = InferenceResponse.parse_obj(response)\r\n  File \"pydantic/main.py\", line 526, in pydantic.main.BaseModel.parse_obj\r\n  File \"pydantic/main.py\", line 341, in pydantic.main.BaseModel.__init__\r\npydantic.error_wrappers.ValidationError: 1 validation error for InferenceResponse\r\nid\r\n  none is not an allowed value (type=type_error.none.not_allowed)\r\n```\r\n\r\nI will create a simple PR to fix this.\r\n\r\n**What did you expect to happen:**\r\nInference to succeed, with id passed through.\r\n\r\n\r\n**What's the InferenceService yaml:**\r\n[To help us debug please run `kubectl get isvc $name -n $namespace -oyaml` and paste the output]\r\nNot applicable. Testing with docker.\r\n\r\n**Anything else you would like to add:**\r\n[Miscellaneous information that will assist in solving the issue.]\r\nNot applicable.\r\n\n", "before_files": [{"content": "# Copyright 2022 The KServe Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom typing import Optional, Dict\n\nfrom fastapi.requests import Request\nfrom fastapi.responses import Response\n\nfrom ..infer_type import InferInput, InferRequest\nfrom .v2_datamodels import (\n    InferenceRequest, ServerMetadataResponse, ServerLiveResponse, ServerReadyResponse,\n    ModelMetadataResponse, InferenceResponse, ModelReadyResponse\n)\nfrom ..dataplane import DataPlane\nfrom ..model_repository_extension import ModelRepositoryExtension\nfrom ...errors import ModelNotReady\n\n\nclass V2Endpoints:\n    \"\"\"KServe V2 Endpoints\n    \"\"\"\n\n    def __init__(self, dataplane: DataPlane, model_repository_extension: Optional[ModelRepositoryExtension] = None):\n        self.model_repository_extension = model_repository_extension\n        self.dataplane = dataplane\n\n    async def metadata(self) -> ServerMetadataResponse:\n        \"\"\"Server metadata endpoint.\n\n        Returns:\n            ServerMetadataResponse: Server metadata JSON object.\n        \"\"\"\n        return ServerMetadataResponse.parse_obj(self.dataplane.metadata())\n\n    @staticmethod\n    async def live() -> ServerLiveResponse:\n        \"\"\"Server live endpoint.\n\n        Returns:\n            ServerLiveResponse: Server live message.\n        \"\"\"\n        return ServerLiveResponse(live=True)\n\n    @staticmethod\n    async def ready() -> ServerReadyResponse:\n        \"\"\"Server ready endpoint.\n\n        Returns:\n            ServerReadyResponse: Server ready message.\n        \"\"\"\n        return ServerReadyResponse(ready=True)\n\n    async def model_metadata(self, model_name: str, model_version: Optional[str] = None) -> ModelMetadataResponse:\n        \"\"\"Model metadata handler. It provides information about a model.\n\n        Args:\n            model_name (str): Model name.\n            model_version (Optional[str]): Model version (optional).\n\n        Returns:\n            ModelMetadataResponse: Model metadata object.\n        \"\"\"\n        # TODO: support model_version\n        if model_version:\n            raise NotImplementedError(\"Model versioning not supported yet.\")\n\n        metadata = await self.dataplane.model_metadata(model_name)\n        return ModelMetadataResponse.parse_obj(metadata)\n\n    async def model_ready(self, model_name: str, model_version: Optional[str] = None) -> ModelReadyResponse:\n        \"\"\"Check if a given model is ready.\n\n        Args:\n            model_name (str): Model name.\n            model_version (str): Model version.\n\n        Returns:\n            ModelReadyResponse: Model ready object\n        \"\"\"\n        # TODO: support model_version\n        if model_version:\n            raise NotImplementedError(\"Model versioning not supported yet.\")\n\n        model_ready = self.dataplane.model_ready(model_name)\n\n        if not model_ready:\n            raise ModelNotReady(model_name)\n\n        return ModelReadyResponse.parse_obj({\"name\": model_name, \"ready\": model_ready})\n\n    async def infer(\n        self,\n        raw_request: Request,\n        raw_response: Response,\n        model_name: str,\n        request_body: InferenceRequest,\n        model_version: Optional[str] = None\n    ) -> InferenceResponse:\n        \"\"\"Infer handler.\n\n        Args:\n            raw_request (Request): fastapi request object,\n            raw_response (Response): fastapi response object,\n            model_name (str): Model name.\n            request_body (InferenceRequest): Inference request body.\n            model_version (Optional[str]): Model version (optional).\n\n        Returns:\n            InferenceResponse: Inference response object.\n        \"\"\"\n        # TODO: support model_version\n        if model_version:\n            raise NotImplementedError(\"Model versioning not supported yet.\")\n\n        model_ready = self.dataplane.model_ready(model_name)\n\n        if not model_ready:\n            raise ModelNotReady(model_name)\n\n        request_headers = dict(raw_request.headers)\n        infer_inputs = [InferInput(name=input.name, shape=input.shape, datatype=input.datatype,\n                                   data=input.data,\n                                   parameters={} if input.parameters is None else input.parameters\n                                   ) for input in request_body.inputs]\n        infer_request = InferRequest(model_name=model_name, infer_inputs=infer_inputs,\n                                     parameters=request_body.parameters)\n        response, response_headers = await self.dataplane.infer(model_name=model_name,\n                                                                request=infer_request,\n                                                                headers=request_headers)\n\n        response, response_headers = self.dataplane.encode(model_name=model_name,\n                                                           response=response,\n                                                           headers=response_headers, req_attributes={})\n\n        if response_headers:\n            raw_response.headers.update(response_headers)\n        res = InferenceResponse.parse_obj(response)\n        return res\n\n    async def load(self, model_name: str) -> Dict:\n        \"\"\"Model load handler.\n\n        Args:\n            model_name (str): Model name.\n\n        Returns:\n            Dict: {\"name\": model_name, \"load\": True}\n        \"\"\"\n        await self.model_repository_extension.load(model_name)\n        return {\"name\": model_name, \"load\": True}\n\n    async def unload(self, model_name: str) -> Dict:\n        \"\"\"Model unload handler.\n\n        Args:\n            model_name (str): Model name.\n\n        Returns:\n            Dict: {\"name\": model_name, \"unload\": True}\n        \"\"\"\n        await self.model_repository_extension.unload(model_name)\n        return {\"name\": model_name, \"unload\": True}\n", "path": "python/kserve/kserve/protocol/rest/v2_endpoints.py"}], "after_files": [{"content": "# Copyright 2022 The KServe Authors.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom typing import Optional, Dict\n\nfrom fastapi.requests import Request\nfrom fastapi.responses import Response\n\nfrom ..infer_type import InferInput, InferRequest\nfrom .v2_datamodels import (\n    InferenceRequest, ServerMetadataResponse, ServerLiveResponse, ServerReadyResponse,\n    ModelMetadataResponse, InferenceResponse, ModelReadyResponse\n)\nfrom ..dataplane import DataPlane\nfrom ..model_repository_extension import ModelRepositoryExtension\nfrom ...errors import ModelNotReady\n\n\nclass V2Endpoints:\n    \"\"\"KServe V2 Endpoints\n    \"\"\"\n\n    def __init__(self, dataplane: DataPlane, model_repository_extension: Optional[ModelRepositoryExtension] = None):\n        self.model_repository_extension = model_repository_extension\n        self.dataplane = dataplane\n\n    async def metadata(self) -> ServerMetadataResponse:\n        \"\"\"Server metadata endpoint.\n\n        Returns:\n            ServerMetadataResponse: Server metadata JSON object.\n        \"\"\"\n        return ServerMetadataResponse.parse_obj(self.dataplane.metadata())\n\n    @staticmethod\n    async def live() -> ServerLiveResponse:\n        \"\"\"Server live endpoint.\n\n        Returns:\n            ServerLiveResponse: Server live message.\n        \"\"\"\n        return ServerLiveResponse(live=True)\n\n    @staticmethod\n    async def ready() -> ServerReadyResponse:\n        \"\"\"Server ready endpoint.\n\n        Returns:\n            ServerReadyResponse: Server ready message.\n        \"\"\"\n        return ServerReadyResponse(ready=True)\n\n    async def model_metadata(self, model_name: str, model_version: Optional[str] = None) -> ModelMetadataResponse:\n        \"\"\"Model metadata handler. It provides information about a model.\n\n        Args:\n            model_name (str): Model name.\n            model_version (Optional[str]): Model version (optional).\n\n        Returns:\n            ModelMetadataResponse: Model metadata object.\n        \"\"\"\n        # TODO: support model_version\n        if model_version:\n            raise NotImplementedError(\"Model versioning not supported yet.\")\n\n        metadata = await self.dataplane.model_metadata(model_name)\n        return ModelMetadataResponse.parse_obj(metadata)\n\n    async def model_ready(self, model_name: str, model_version: Optional[str] = None) -> ModelReadyResponse:\n        \"\"\"Check if a given model is ready.\n\n        Args:\n            model_name (str): Model name.\n            model_version (str): Model version.\n\n        Returns:\n            ModelReadyResponse: Model ready object\n        \"\"\"\n        # TODO: support model_version\n        if model_version:\n            raise NotImplementedError(\"Model versioning not supported yet.\")\n\n        model_ready = self.dataplane.model_ready(model_name)\n\n        if not model_ready:\n            raise ModelNotReady(model_name)\n\n        return ModelReadyResponse.parse_obj({\"name\": model_name, \"ready\": model_ready})\n\n    async def infer(\n        self,\n        raw_request: Request,\n        raw_response: Response,\n        model_name: str,\n        request_body: InferenceRequest,\n        model_version: Optional[str] = None\n    ) -> InferenceResponse:\n        \"\"\"Infer handler.\n\n        Args:\n            raw_request (Request): fastapi request object,\n            raw_response (Response): fastapi response object,\n            model_name (str): Model name.\n            request_body (InferenceRequest): Inference request body.\n            model_version (Optional[str]): Model version (optional).\n\n        Returns:\n            InferenceResponse: Inference response object.\n        \"\"\"\n        # TODO: support model_version\n        if model_version:\n            raise NotImplementedError(\"Model versioning not supported yet.\")\n\n        model_ready = self.dataplane.model_ready(model_name)\n\n        if not model_ready:\n            raise ModelNotReady(model_name)\n\n        request_headers = dict(raw_request.headers)\n        infer_inputs = [InferInput(name=input.name, shape=input.shape, datatype=input.datatype,\n                                   data=input.data,\n                                   parameters={} if input.parameters is None else input.parameters\n                                   ) for input in request_body.inputs]\n        infer_request = InferRequest(request_id=request_body.id, model_name=model_name, infer_inputs=infer_inputs,\n                                     parameters=request_body.parameters)\n        response, response_headers = await self.dataplane.infer(model_name=model_name,\n                                                                request=infer_request,\n                                                                headers=request_headers)\n\n        response, response_headers = self.dataplane.encode(model_name=model_name,\n                                                           response=response,\n                                                           headers=response_headers, req_attributes={})\n\n        if response_headers:\n            raw_response.headers.update(response_headers)\n        res = InferenceResponse.parse_obj(response)\n        return res\n\n    async def load(self, model_name: str) -> Dict:\n        \"\"\"Model load handler.\n\n        Args:\n            model_name (str): Model name.\n\n        Returns:\n            Dict: {\"name\": model_name, \"load\": True}\n        \"\"\"\n        await self.model_repository_extension.load(model_name)\n        return {\"name\": model_name, \"load\": True}\n\n    async def unload(self, model_name: str) -> Dict:\n        \"\"\"Model unload handler.\n\n        Args:\n            model_name (str): Model name.\n\n        Returns:\n            Dict: {\"name\": model_name, \"unload\": True}\n        \"\"\"\n        await self.model_repository_extension.unload(model_name)\n        return {\"name\": model_name, \"unload\": True}\n", "path": "python/kserve/kserve/protocol/rest/v2_endpoints.py"}]}