code: def handle_prediction_response_streaming(
      prediction_url, api_token, print_verbose
  ):
      previous_output = ""
      output_string = ""
  
      headers = {
          "Authorization": f"Token {api_token}",
          "Content-Type": "application/json",
      }
      status = ""
      while True and (
          status not in ["succeeded", "failed", "canceled"]
      ):
          time.sleep(0.5)  # prevent being rate limited by replicate
          print_verbose(
              f"replicate: polling endpoint: {prediction_url}"
          )
          response = requests.get(prediction_url, headers=headers)
          if response.status_code == 200:
              response_data = response.json()
              status = response_data["status"]
              if "output" in response_data:
                  output_string = "".join(response_data["output"])
                  new_output = output_string[len(previous_output) :]
                  print_verbose(f"New chunk: {new_output}")
                  yield {"output": new_output, "status": status}
                  previous_output = output_string
              status = response_data["status"]
              if status == "failed":
                  replicate_error = response_data.get("error", "")
                  raise ReplicateError(
                      status_code=400,
                      message=f"Error: {replicate_error}",
                  )
          else:
              # this can fail temporarily but it does not mean the replicate request failed, replicate request fails when status=="failed"
              print_verbose(
                  f"Replicate: Failed to fetch prediction status and output.{response.status_code}{response.text}"
              )
  
imports: import os, types
  import json
  import requests
  import time
  from typing import Callable, Optional
  from litellm.utils import ModelResponse, Usage
  import litellm
  import httpx
  from .prompt_templates.factory import prompt_factory, custom_prompt
label_desc: Use image node_id 3 for calling a global function with example usage: handle_prediction_response_streaming(prediction_url, api_token, print_verbose) without return types