prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Support .json and .ubj model format for XGBoost server image
  /kind feature
  
  
  **Description**
  In the XGBoost image, the only supported model format is .bst: https://github.com/kserve/kserve/blob/56b8fe0d189fc0d557e9a8af07eab0c12852d5fd/python/xgbserver/xgbserver/model.py#L28
  
  This format has been deprecated for a while and is not backwards compatible between xgboost framework versions. The recommended model format is .json or .ubj: https://xgboost.readthedocs.io/en/stable/tutorials/saving_model.html
  
  Users that want to use the recommended model format for XGBoost models, are currently not able to do so.
  
  
  **Proposed solution**
  Support the recommended file formats, while also keeping support for the old .bst format. 
  
  
  
  
  
  
  </issue>
  <code>
  [start of python/xgbserver/xgbserver/model.py]
  1 # Copyright 2021 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 
  16 import os
  17 from typing import Dict, Union
  18 
  19 import xgboost as xgb
  20 from kserve.errors import InferenceError, ModelMissingError
  21 from kserve.protocol.infer_type import InferRequest, InferResponse
  22 from kserve.utils.utils import get_predict_input, get_predict_response
  23 from xgboost import XGBModel
  24 
  25 from kserve import Model
  26 from kserve.storage import Storage
  27 
  28 BOOSTER_FILE_EXTENSION = ".bst"
  29 
  30 
  31 class XGBoostModel(Model):
  32     def __init__(
  33         self, name: str, model_dir: str, nthread: int, booster: XGBModel = None
  34     ):
  35         super().__init__(name)
  36         self.name = name
  37         self.model_dir = model_dir
  38         self.nthread = nthread
  39         if booster is not None:
  40             self._booster = booster
  41             self.ready = True
  42 
  43     def load(self) -> bool:
  44         model_path = Storage.download(self.model_dir)
  45         model_files = []
  46         for file in os.listdir(model_path):
  47             file_path = os.path.join(model_path, file)
  48             if os.path.isfile(file_path) and file.endswith(BOOSTER_FILE_EXTENSION):
  49                 model_files.append(file_path)
  50         if len(model_files) == 0:
  51             raise ModelMissingError(model_path)
  52         elif len(model_files) > 1:
  53             raise RuntimeError(
  54                 "More than one model file is detected, "
  55                 f"Only one is allowed within model_dir: {model_files}"
  56             )
  57 
  58         self._booster = xgb.Booster(
  59             params={"nthread": self.nthread}, model_file=model_files[0]
  60         )
  61         self.ready = True
  62         return self.ready
  63 
  64     def predict(
  65         self, payload: Union[Dict, InferRequest], headers: Dict[str, str] = None
  66     ) -> Union[Dict, InferResponse]:
  67         try:
  68             # Use of list as input is deprecated see https://github.com/dmlc/xgboost/pull/3970
  69             instances = get_predict_input(payload)
  70             dmatrix = xgb.DMatrix(instances, nthread=self.nthread)
  71             result = self._booster.predict(dmatrix)
  72             return get_predict_response(payload, result, self.name)
  73         except Exception as e:
  74             raise InferenceError(str(e))
  75
  [end of python/xgbserver/xgbserver/model.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/python/xgbserver/xgbserver/model.py b/python/xgbserver/xgbserver/model.py
  --- a/python/xgbserver/xgbserver/model.py
  +++ b/python/xgbserver/xgbserver/model.py
  @@ -25,7 +25,7 @@
   from kserve import Model
   from kserve.storage import Storage
   
  -BOOSTER_FILE_EXTENSION = ".bst"
  +BOOSTER_FILE_EXTENSIONS = (".bst", ".json", ".ubj")
   
   
   class XGBoostModel(Model):
  @@ -45,7 +45,7 @@
           model_files = []
           for file in os.listdir(model_path):
               file_path = os.path.join(model_path, file)
  -            if os.path.isfile(file_path) and file.endswith(BOOSTER_FILE_EXTENSION):
  +            if os.path.isfile(file_path) and file.endswith(BOOSTER_FILE_EXTENSIONS):
                   model_files.append(file_path)
           if len(model_files) == 0:
               raise ModelMissingError(model_path)
  
verification_info: {"golden_diff": "diff --git a/python/xgbserver/xgbserver/model.py b/python/xgbserver/xgbserver/model.py\n--- a/python/xgbserver/xgbserver/model.py\n+++ b/python/xgbserver/xgbserver/model.py\n@@ -25,7 +25,7 @@\n from kserve import Model\n from kserve.storage import Storage\n \n-BOOSTER_FILE_EXTENSION = \".bst\"\n+BOOSTER_FILE_EXTENSIONS = (\".bst\", \".json\", \".ubj\")\n \n \n class XGBoostModel(Model):\n@@ -45,7 +45,7 @@\n         model_files = []\n         for file in os.listdir(model_path):\n             file_path = os.path.join(model_path, file)\n-            if os.path.isfile(file_path) and file.endswith(BOOSTER_FILE_EXTENSION):\n+            if os.path.isfile(file_path) and file.endswith(BOOSTER_FILE_EXTENSIONS):\n                 model_files.append(file_path)\n         if len(model_files) == 0:\n             raise ModelMissingError(model_path)\n", "issue": "Support .json and .ubj model format for XGBoost server image\n/kind feature\r\n\r\n\r\n**Description**\r\nIn the XGBoost image, the only supported model format is .bst: https://github.com/kserve/kserve/blob/56b8fe0d189fc0d557e9a8af07eab0c12852d5fd/python/xgbserver/xgbserver/model.py#L28\r\n\r\nThis format has been deprecated for a while and is not backwards compatible between xgboost framework versions. The recommended model format is .json or .ubj: https://xgboost.readthedocs.io/en/stable/tutorials/saving_model.html\r\n\r\nUsers that want to use the recommended model format for XGBoost models, are currently not able to do so.\r\n\r\n\r\n**Proposed solution**\r\nSupport the recommended file formats, while also keeping support for the old .bst format. \r\n\r\n\r\n\r\n\r\n\n", "before_files": [{"content": "# Copyright 2021 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\n\nimport os\nfrom typing import Dict, Union\n\nimport xgboost as xgb\nfrom kserve.errors import InferenceError, ModelMissingError\nfrom kserve.protocol.infer_type import InferRequest, InferResponse\nfrom kserve.utils.utils import get_predict_input, get_predict_response\nfrom xgboost import XGBModel\n\nfrom kserve import Model\nfrom kserve.storage import Storage\n\nBOOSTER_FILE_EXTENSION = \".bst\"\n\n\nclass XGBoostModel(Model):\n    def __init__(\n        self, name: str, model_dir: str, nthread: int, booster: XGBModel = None\n    ):\n        super().__init__(name)\n        self.name = name\n        self.model_dir = model_dir\n        self.nthread = nthread\n        if booster is not None:\n            self._booster = booster\n            self.ready = True\n\n    def load(self) -> bool:\n        model_path = Storage.download(self.model_dir)\n        model_files = []\n        for file in os.listdir(model_path):\n            file_path = os.path.join(model_path, file)\n            if os.path.isfile(file_path) and file.endswith(BOOSTER_FILE_EXTENSION):\n                model_files.append(file_path)\n        if len(model_files) == 0:\n            raise ModelMissingError(model_path)\n        elif len(model_files) > 1:\n            raise RuntimeError(\n                \"More than one model file is detected, \"\n                f\"Only one is allowed within model_dir: {model_files}\"\n            )\n\n        self._booster = xgb.Booster(\n            params={\"nthread\": self.nthread}, model_file=model_files[0]\n        )\n        self.ready = True\n        return self.ready\n\n    def predict(\n        self, payload: Union[Dict, InferRequest], headers: Dict[str, str] = None\n    ) -> Union[Dict, InferResponse]:\n        try:\n            # Use of list as input is deprecated see https://github.com/dmlc/xgboost/pull/3970\n            instances = get_predict_input(payload)\n            dmatrix = xgb.DMatrix(instances, nthread=self.nthread)\n            result = self._booster.predict(dmatrix)\n            return get_predict_response(payload, result, self.name)\n        except Exception as e:\n            raise InferenceError(str(e))\n", "path": "python/xgbserver/xgbserver/model.py"}]}