code: def apply_policy_and_sample(
      networks: ValueDiceNetworks, eval_mode: bool = False
  ) -> actor_core_lib.FeedForwardPolicy:
      """Returns a function that computes actions."""
      sample_fn = (
          networks.sample if not eval_mode else networks.sample_eval
      )
      if not sample_fn:
          raise ValueError("sample function is not provided")
  
      def apply_and_sample(params, key, obs):
          return sample_fn(
              networks.policy_network.apply(params, obs), key
          )
  
      return apply_and_sample
  
file_path: acme/acme/agents/jax/value_dice/networks.py
imports: import dataclasses
  from typing import Callable, Optional, Tuple
  from acme import specs
  from acme.agents.jax import actor_core
  from acme.jax import networks
  from acme.jax import utils
  import haiku
  import jax
  import jax.numpy
  import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: apply_policy_and_sample(networks, eval_mode) and returns: apply_and_sample, sample_fn