code: def handle_prediction_response(
      prediction_url, api_token, print_verbose
  ):
      output_string = ""
      headers = {
          "Authorization": f"Token {api_token}",
          "Content-Type": "application/json",
      }
  
      status = ""
      logs = ""
      while True and (
          status not in ["succeeded", "failed", "canceled"]
      ):
          print_verbose(
              f"replicate: polling endpoint: {prediction_url}"
          )
          time.sleep(0.5)
          response = requests.get(prediction_url, headers=headers)
          if response.status_code == 200:
              response_data = response.json()
              if "output" in response_data:
                  output_string = "".join(response_data["output"])
                  print_verbose(f"Non-streamed output:{output_string}")
              status = response_data.get("status", None)
              logs = response_data.get("logs", "")
              if status == "failed":
                  replicate_error = response_data.get("error", "")
                  raise ReplicateError(
                      status_code=400,
                      message=f"Error: {replicate_error}, \nReplicate logs:{logs}",
                  )
          else:
              # this can fail temporarily but it does not mean the replicate request failed, replicate request fails when status=="failed"
              print_verbose(
                  "Replicate: Failed to fetch prediction status and output."
              )
      return output_string, logs
  
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 2 for calling a global function with example usage: handle_prediction_response(prediction_url, api_token, print_verbose) and returns: output_string,  logs