def process_response(response) -> List[dict]:
    """General-purpose response processing for single responses and streams."""
    if hasattr(response, "json"):  ## For single response (i.e. non-streaming)
        try:
            return [response.json()]
        except json.JSONDecodeError:
            response = str(response.__dict__)
    if isinstance(response, str):  ## For set of responses (i.e. streaming)
        msg_list = []
        for msg in response.split("\n\n"):
            if "{" not in msg:
                continue
            msg_list += [json.loads(msg[msg.find("{") :])]
        return msg_list
    raise ValueError(f"Received ill-formed response: {response}")
General-purpose response processing for single responses and streams.
llama-index-integrations/multi_modal_llms/llama-index-multi-modal-llms-nvidia/llama_index/multi_modal_llms/nvidia/utils.py