def _request_embeddings()

in ez_wsi_dicomweb/patch_embedding_endpoints.py [0:0]


  def _request_embeddings(self, json_msg: str) -> str:
    """Sends json request to Vertex AI endpoint."""
    try:
      headers = self.vertex_endpoint_authentication_header()
      headers['Content-Length'] = f'{len(json_msg)}'
      headers['Content-Type'] = 'application/json'
      response = requests.post(
          self._end_point_url,
          headers=headers,
          data=json_msg,
          timeout=self.timeout,
      )
      # Raises a HTTPError if the response code was not 200
      response.raise_for_status()
      return response.text
    except requests.exceptions.HTTPError as exp:
      ez_wsi_errors.raise_ez_wsi_http_exception(exp.response.reason, exp)
    except requests.exceptions.Timeout as timeout_error:
      raise ez_wsi_errors.HttpRequestTimeoutError(
          str(timeout_error), 'Request Timeout'
      ) from timeout_error