code: def get_responses_and_suggestions_per_user(
      dataset: Union["FeedbackDataset", "RemoteFeedbackDataset"],
      question_name: str,
      filter_by: Optional[
          Dict[
              str,
              Union[
                  "ResponseStatusFilter", List["ResponseStatusFilter"]
              ],
          ]
      ] = None,
      sort_by: Optional[List["SortBy"]] = None,
      max_records: Optional[int] = None,
      show_progress: bool = True,
  ) -> Tuple[Dict[int, "Responses"], "Suggestions"]:
      """Extract the responses per user and the suggestions from a FeedbackDataset.
  
      Helper function for the metrics module where we want to compare the responses
      in relation to the suggestions offered.
  
      Args:
          dataset: FeedbackDataset or RemoteFeedbackDataset.
          question_name: The name of the question to filter from the dataset.
          filter_by: A dict with key the field to filter by, and values the filters to apply.
              Can be one of: draft, pending, submitted, and discarded. If set to None,
              no filter will be applied. Defaults to None (no filter is applied).
          sort_by: A list of `SortBy` objects to sort your dataset by.
              Defaults to None (no filter is applied).
          max_records: The maximum number of records to use for training. Defaults to None.
  
      Raises:
          NotImplementedError:
              When no user_id is given. We need that information to compute the metrics.
  
      Returns:
          Tuple containing the responses per user as a dict, with keys the user id and values the responses,
          and the suggestions.
      """
      if filter_by:
          dataset = dataset.filter_by(**filter_by)
      if sort_by:
          dataset = dataset.sort_by(sort_by)
      if max_records:
          dataset = dataset.pull(max_records=max_records)
  
      hf_dataset = dataset.format_as("datasets")
      question_type = type(dataset.question_by_name(question_name))
      is_ranking_question = (question_type == RankingQuestion) or (
          question_type == RemoteRankingQuestion
      )
  
      responses_and_suggestions_per_user = defaultdict(
          lambda: defaultdict(list)
      )
  
      for responses_, suggestion in tqdm(
          zip(
              hf_dataset[question_name],
              hf_dataset[f"{question_name}-suggestion"],
          ),
          desc="Extracting responses and suggestions per user",
          total=len(hf_dataset),
          disable=not show_progress,
      ):
          if is_ranking_question:
              suggestion = suggestion["rank"]
  
          if isinstance(suggestion, list):
              # To make it hashable
              suggestion = tuple(suggestion)
  
          for response in responses_:
              user_id = response["user_id"]
              if user_id is None:
                  raise NotImplementedError(
                      "In order to use this functionality the records need to be assigned to a user."
                  )
  
              if is_ranking_question:
                  value = response["value"]["rank"]
              else:
                  value = response["value"]
  
              if value is None:
                  continue
              # To avoid errors with the MASI distance function
              if isinstance(value, list):
                  if len(value) == 0:
                      continue
  
              if isinstance(value, list):
                  # To make it hashable
                  value = tuple(value)
  
              responses_and_suggestions_per_user[user_id][
                  "responses"
              ].append(value)
              responses_and_suggestions_per_user[user_id][
                  "suggestions"
              ].append(suggestion)
  
      return responses_and_suggestions_per_user
  
file_path: argilla/src/argilla/client/feedback/metrics/utils.py
imports: from collections import defaultdict
  from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Union
  import numpy
  from tqdm import tqdm
  from argilla.client.feedback.dataset.remote.dataset import RemoteFeedbackDataset
  from argilla.client.feedback.schemas import RankingQuestion, TextQuestion
  from argilla.client.feedback.schemas.enums import ResponseStatusFilter
  from argilla.client.feedback.schemas.remote.questions import RemoteRankingQuestion
label_desc: Use image node_id 1 for calling a global function with example usage: get_responses_and_suggestions_per_user(dataset, question_name, filter_by, sort_by, max_records, show_progress) and returns: responses_and_suggestions_per_user