code: def generate_polynomial(
      degree: int,
      num_variables: int,
      range_coeffs: Range,  # inclusive
      seed: Optional[int] = None,
      strict_degree=True,
      strict_variables=True,
      strict_constant=True,
  ) -> Polynomial:
      """Sample the coefficients (A, B, ...) of the polynomial equation y = ... + A x + B.
      A generic method used by the function class-specific methods below.
  
      Args:
          strict_degree (bool): if True, require `rel` to have degree strictly equal to `degree`
          strict_variables (bool): if True, require `rel` to use exactly `num_variables`
          strict_constant (bool): if True, require the constant (ie. term of degree 0) to be non-zero
      Returns:
          `rel` (Polynomial)
      """
      MAX_ATTEMPTS = 100
      if seed is not None:
          random.seed(seed)
          np.random.seed(seed)
      count = 0
      terms = generate_terms(degree, num_variables)
      while count < MAX_ATTEMPTS:
          done = True
          coeffs = [random.randint(r[0], r[1]) for r in range_coeffs]
          if strict_constant and coeffs[-1] == 0:
              done = False
          if strict_degree and not sum(
              coeffs[
                  : comb(degree + num_variables - 1, num_variables - 1)
              ]
          ):
              done = False
          if strict_variables:
              for idx in range(num_variables):
                  vals = np.zeros(num_variables)
                  vals[idx] = 1
                  res = np.dot(
                      coeffs[:-1],
                      np.array(
                          list(
                              map(
                                  lambda _: np.prod(
                                      vals.__getitem__(_)
                                  ),
                                  terms[:-1],
                              )
                          )
                      ),
                  )
                  if not res:
                      done = False
                      break
          if done:
              break
          count += 1
          if count >= MAX_ATTEMPTS:
              raise ValueError(
                  "Failed to sample valid polynomial equation within "
                  + f"{MAX_ATTEMPTS} attempts from ranges {str(range_coeffs)}."
              )
      return Polynomial(
          degree=degree,
          num_variables=num_variables,
          coeffs=np.array(coeffs),
      )
  
imports: from collections import defaultdict
  from dataclasses import dataclass, field
  from itertools import combinations_with_replacement, product
  import math
  from math import comb
  import numpy
  import numpy.typing
  import random
  import sympy
  from sympy import Symbol, Poly, diff
  from sympy.parsing.sympy_parser import standard_transformations, implicit_multiplication_application
  from typing import List, Optional, Tuple, Dict
  from helm.benchmark.adaptation.adapters.adapter_factory import ADAPT_GENERATION
  from helm.benchmark.adaptation.adapter_spec import AdapterSpec
  from helm.benchmark.window_services.tokenizer_service import TokenizerService
  from helm.common.authentication import Authentication
  from helm.proxy.services.server_service import ServerService
  from .scenario import Scenario, Instance, Reference, TRAIN_SPLIT, TEST_SPLIT, CORRECT_TAG, Input, Output
label_desc: Use image node_id 7 for calling a global function with example usage: generate_polynomial(degree, num_variables, range_coeffs, seed, strict_degree, strict_variables, strict_constant) and returns: Polynomial