prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Add "don't log" header to Alibi runtime
  
  
  </issue>
  <code>
  [start of runtimes/alibi-explain/mlserver_alibi_explain/common.py]
  1 import re
  2 from importlib import import_module
  3 from typing import Any, Optional, Type, Union, List
  4 
  5 import numpy as np
  6 import requests
  7 from pydantic import BaseSettings
  8 
  9 from mlserver.codecs import StringCodec, NumpyCodec
  10 from mlserver.types import (
  11     ResponseOutput,
  12     InferenceResponse,
  13     InferenceRequest,
  14     Parameters,
  15     MetadataModelResponse,
  16 )
  17 from mlserver.utils import generate_uuid
  18 
  19 from mlserver_alibi_explain.errors import RemoteInferenceError, InvalidExplanationShape
  20 
  21 _DEFAULT_INPUT_NAME = "predict"
  22 
  23 EXPLAINER_TYPE_TAG = "explainer_type"
  24 
  25 _MAX_RETRY_ATTEMPT = 3
  26 
  27 ENV_PREFIX_ALIBI_EXPLAIN_SETTINGS = "MLSERVER_MODEL_ALIBI_EXPLAIN_"
  28 EXPLAIN_PARAMETERS_TAG = "explain_parameters"
  29 
  30 
  31 #  TODO: add this utility in the codec.
  32 def convert_from_bytes(output: ResponseOutput, ty: Optional[Type] = None) -> Any:
  33     """
  34     This utility function decodes the response from bytes string to python object dict.
  35     It is related to decoding StringCodec
  36     """
  37     if output.shape not in ([1], [1, 1]):
  38         raise InvalidExplanationShape(output.shape)
  39 
  40     if ty == str:
  41         return bytearray(output.data[0]).decode("UTF-8")
  42     else:
  43         py_str = bytearray(output.data[0]).decode("UTF-8")
  44 
  45         from ast import literal_eval
  46 
  47         return literal_eval(py_str)
  48 
  49 
  50 # TODO: add retry and better exceptions handling
  51 def remote_predict(
  52     v2_payload: InferenceRequest, predictor_url: str, ssl_verify_path: str
  53 ) -> InferenceResponse:
  54     verify: Union[str, bool] = True
  55     if ssl_verify_path != "":
  56         verify = ssl_verify_path
  57     response_raw = requests.post(predictor_url, json=v2_payload.dict(), verify=verify)
  58     if response_raw.status_code != 200:
  59         raise RemoteInferenceError(response_raw.status_code, response_raw.reason)
  60     return InferenceResponse.parse_raw(response_raw.text)
  61 
  62 
  63 def remote_metadata(url: str, ssl_verify_path: str) -> MetadataModelResponse:
  64     """Get metadata from v2 endpoint"""
  65     verify: Union[str, bool] = True
  66     if ssl_verify_path != "":
  67         verify = ssl_verify_path
  68     response_raw = requests.get(url, verify=verify)
  69     if response_raw.status_code != 200:
  70         raise RemoteInferenceError(response_raw.status_code, response_raw.reason)
  71     return MetadataModelResponse.parse_raw(response_raw.text)
  72 
  73 
  74 def construct_metadata_url(infer_url: str) -> str:
  75     """Construct v2 metadata endpoint from v2 infer endpoint"""
  76     return re.sub(r"/infer$", "", infer_url)
  77 
  78 
  79 class AlibiExplainSettings(BaseSettings):
  80     """
  81     Parameters that apply only to alibi explain models
  82     """
  83 
  84     class Config:
  85         env_prefix = ENV_PREFIX_ALIBI_EXPLAIN_SETTINGS
  86 
  87     infer_uri: str
  88     explainer_type: str
  89     init_parameters: Optional[dict]
  90     ssl_verify_path: Optional[str]
  91 
  92 
  93 def import_and_get_class(class_path: str) -> type:
  94     last_dot = class_path.rfind(".")
  95     klass = getattr(import_module(class_path[:last_dot]), class_path[last_dot + 1 :])
  96     return klass
  97 
  98 
  99 def to_v2_inference_request(
  100     input_data: Union[np.ndarray, List[str]],
  101     metadata: Optional[MetadataModelResponse],
  102 ) -> InferenceRequest:
  103     """
  104     Encode numpy payload to v2 protocol.
  105 
  106     Note: We only fetch the first-input name and the list of outputs from the metadata
  107     endpoint currently. We should consider wider reconciliation with data types etc.
  108 
  109     Parameters
  110     ----------
  111     input_data
  112        Numpy ndarray to encode
  113     metadata
  114        Extra metadata that can help encode the payload.
  115     """
  116 
  117     # MLServer does not really care about a correct input name!
  118     input_name = _DEFAULT_INPUT_NAME
  119     id_name = generate_uuid()
  120     outputs = []
  121 
  122     if metadata is not None:
  123         if metadata.inputs:
  124             # we only support a big single input numpy
  125             input_name = metadata.inputs[0].name
  126         if metadata.outputs:
  127             outputs = metadata.outputs
  128 
  129     # For List[str] (e.g. AnchorText), we use StringCodec for input
  130     input_payload_codec = StringCodec if type(input_data) == list else NumpyCodec
  131     v2_request = InferenceRequest(
  132         id=id_name,
  133         parameters=Parameters(content_type=input_payload_codec.ContentType),
  134         # TODO: we probably need to tell alibi about the expected types to use
  135         # or even whether it is a probability of classes or targets etc
  136         inputs=[
  137             input_payload_codec.encode_input(  # type: ignore
  138                 name=input_name,
  139                 payload=input_data,
  140                 use_bytes=False,
  141             )
  142         ],
  143         outputs=outputs,
  144     )
  145     return v2_request
  146
  [end of runtimes/alibi-explain/mlserver_alibi_explain/common.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/runtimes/alibi-explain/mlserver_alibi_explain/common.py b/runtimes/alibi-explain/mlserver_alibi_explain/common.py
  --- a/runtimes/alibi-explain/mlserver_alibi_explain/common.py
  +++ b/runtimes/alibi-explain/mlserver_alibi_explain/common.py
  @@ -26,6 +26,7 @@
   
   ENV_PREFIX_ALIBI_EXPLAIN_SETTINGS = "MLSERVER_MODEL_ALIBI_EXPLAIN_"
   EXPLAIN_PARAMETERS_TAG = "explain_parameters"
  +SELDON_SKIP_LOGGING_HEADER = "Seldon-Skip-Logging"
   
   
   #  TODO: add this utility in the codec.
  @@ -54,7 +55,12 @@
       verify: Union[str, bool] = True
       if ssl_verify_path != "":
           verify = ssl_verify_path
  -    response_raw = requests.post(predictor_url, json=v2_payload.dict(), verify=verify)
  +    response_raw = requests.post(
  +        predictor_url,
  +        json=v2_payload.dict(),
  +        headers={SELDON_SKIP_LOGGING_HEADER: "true"},
  +        verify=verify,
  +    )
       if response_raw.status_code != 200:
           raise RemoteInferenceError(response_raw.status_code, response_raw.reason)
       return InferenceResponse.parse_raw(response_raw.text)
  
verification_info: {"golden_diff": "diff --git a/runtimes/alibi-explain/mlserver_alibi_explain/common.py b/runtimes/alibi-explain/mlserver_alibi_explain/common.py\n--- a/runtimes/alibi-explain/mlserver_alibi_explain/common.py\n+++ b/runtimes/alibi-explain/mlserver_alibi_explain/common.py\n@@ -26,6 +26,7 @@\n \n ENV_PREFIX_ALIBI_EXPLAIN_SETTINGS = \"MLSERVER_MODEL_ALIBI_EXPLAIN_\"\n EXPLAIN_PARAMETERS_TAG = \"explain_parameters\"\n+SELDON_SKIP_LOGGING_HEADER = \"Seldon-Skip-Logging\"\n \n \n #  TODO: add this utility in the codec.\n@@ -54,7 +55,12 @@\n     verify: Union[str, bool] = True\n     if ssl_verify_path != \"\":\n         verify = ssl_verify_path\n-    response_raw = requests.post(predictor_url, json=v2_payload.dict(), verify=verify)\n+    response_raw = requests.post(\n+        predictor_url,\n+        json=v2_payload.dict(),\n+        headers={SELDON_SKIP_LOGGING_HEADER: \"true\"},\n+        verify=verify,\n+    )\n     if response_raw.status_code != 200:\n         raise RemoteInferenceError(response_raw.status_code, response_raw.reason)\n     return InferenceResponse.parse_raw(response_raw.text)\n", "issue": "Add \"don't log\" header to Alibi runtime\n\n", "before_files": [{"content": "import re\nfrom importlib import import_module\nfrom typing import Any, Optional, Type, Union, List\n\nimport numpy as np\nimport requests\nfrom pydantic import BaseSettings\n\nfrom mlserver.codecs import StringCodec, NumpyCodec\nfrom mlserver.types import (\n    ResponseOutput,\n    InferenceResponse,\n    InferenceRequest,\n    Parameters,\n    MetadataModelResponse,\n)\nfrom mlserver.utils import generate_uuid\n\nfrom mlserver_alibi_explain.errors import RemoteInferenceError, InvalidExplanationShape\n\n_DEFAULT_INPUT_NAME = \"predict\"\n\nEXPLAINER_TYPE_TAG = \"explainer_type\"\n\n_MAX_RETRY_ATTEMPT = 3\n\nENV_PREFIX_ALIBI_EXPLAIN_SETTINGS = \"MLSERVER_MODEL_ALIBI_EXPLAIN_\"\nEXPLAIN_PARAMETERS_TAG = \"explain_parameters\"\n\n\n#  TODO: add this utility in the codec.\ndef convert_from_bytes(output: ResponseOutput, ty: Optional[Type] = None) -> Any:\n    \"\"\"\n    This utility function decodes the response from bytes string to python object dict.\n    It is related to decoding StringCodec\n    \"\"\"\n    if output.shape not in ([1], [1, 1]):\n        raise InvalidExplanationShape(output.shape)\n\n    if ty == str:\n        return bytearray(output.data[0]).decode(\"UTF-8\")\n    else:\n        py_str = bytearray(output.data[0]).decode(\"UTF-8\")\n\n        from ast import literal_eval\n\n        return literal_eval(py_str)\n\n\n# TODO: add retry and better exceptions handling\ndef remote_predict(\n    v2_payload: InferenceRequest, predictor_url: str, ssl_verify_path: str\n) -> InferenceResponse:\n    verify: Union[str, bool] = True\n    if ssl_verify_path != \"\":\n        verify = ssl_verify_path\n    response_raw = requests.post(predictor_url, json=v2_payload.dict(), verify=verify)\n    if response_raw.status_code != 200:\n        raise RemoteInferenceError(response_raw.status_code, response_raw.reason)\n    return InferenceResponse.parse_raw(response_raw.text)\n\n\ndef remote_metadata(url: str, ssl_verify_path: str) -> MetadataModelResponse:\n    \"\"\"Get metadata from v2 endpoint\"\"\"\n    verify: Union[str, bool] = True\n    if ssl_verify_path != \"\":\n        verify = ssl_verify_path\n    response_raw = requests.get(url, verify=verify)\n    if response_raw.status_code != 200:\n        raise RemoteInferenceError(response_raw.status_code, response_raw.reason)\n    return MetadataModelResponse.parse_raw(response_raw.text)\n\n\ndef construct_metadata_url(infer_url: str) -> str:\n    \"\"\"Construct v2 metadata endpoint from v2 infer endpoint\"\"\"\n    return re.sub(r\"/infer$\", \"\", infer_url)\n\n\nclass AlibiExplainSettings(BaseSettings):\n    \"\"\"\n    Parameters that apply only to alibi explain models\n    \"\"\"\n\n    class Config:\n        env_prefix = ENV_PREFIX_ALIBI_EXPLAIN_SETTINGS\n\n    infer_uri: str\n    explainer_type: str\n    init_parameters: Optional[dict]\n    ssl_verify_path: Optional[str]\n\n\ndef import_and_get_class(class_path: str) -> type:\n    last_dot = class_path.rfind(\".\")\n    klass = getattr(import_module(class_path[:last_dot]), class_path[last_dot + 1 :])\n    return klass\n\n\ndef to_v2_inference_request(\n    input_data: Union[np.ndarray, List[str]],\n    metadata: Optional[MetadataModelResponse],\n) -> InferenceRequest:\n    \"\"\"\n    Encode numpy payload to v2 protocol.\n\n    Note: We only fetch the first-input name and the list of outputs from the metadata\n    endpoint currently. We should consider wider reconciliation with data types etc.\n\n    Parameters\n    ----------\n    input_data\n       Numpy ndarray to encode\n    metadata\n       Extra metadata that can help encode the payload.\n    \"\"\"\n\n    # MLServer does not really care about a correct input name!\n    input_name = _DEFAULT_INPUT_NAME\n    id_name = generate_uuid()\n    outputs = []\n\n    if metadata is not None:\n        if metadata.inputs:\n            # we only support a big single input numpy\n            input_name = metadata.inputs[0].name\n        if metadata.outputs:\n            outputs = metadata.outputs\n\n    # For List[str] (e.g. AnchorText), we use StringCodec for input\n    input_payload_codec = StringCodec if type(input_data) == list else NumpyCodec\n    v2_request = InferenceRequest(\n        id=id_name,\n        parameters=Parameters(content_type=input_payload_codec.ContentType),\n        # TODO: we probably need to tell alibi about the expected types to use\n        # or even whether it is a probability of classes or targets etc\n        inputs=[\n            input_payload_codec.encode_input(  # type: ignore\n                name=input_name,\n                payload=input_data,\n                use_bytes=False,\n            )\n        ],\n        outputs=outputs,\n    )\n    return v2_request\n", "path": "runtimes/alibi-explain/mlserver_alibi_explain/common.py"}]}