code: def get_rate_index(
      market, valuation_date, rate_type=None, currency=None, dtype=None
  ):
      """Return the relevant rate from the market data."""
      del currency
      if rate_type == RateIndexType.LIBOR:
          rate = market.libor_rate or tf.zeros(
              valuation_date.shape, dtype=dtype
          )
      elif rate_type == RateIndexType.SWAP:
          rate = market.swap_rate or tf.zeros(
              valuation_date.shape, dtype=dtype
          )
      else:
          raise ValueError("Unrecognized rate type.")
      return rate
  
imports: import enum
  from typing import Optional
  import tensorflow.compat.v2
  from tf_quant_finance import datetime
  from tf_quant_finance import types
  from tf_quant_finance import utils
label_desc: Use image node_id 3 for calling a global function with example usage: get_rate_index(market, valuation_date, rate_type, currency, dtype) and returns: rate