docstr: Sort the conversations by length of user_input + completion
  or by length of user_input only
  
  Args:
      conversations (List[Dict]): list of conversations
      only_input (bool, optional): sort by length of user_input only.
          Defaults to False.
      reverse (bool, optional): sort in descending order.
          Defaults to True.
      shuffle (bool, optional): shuffle the dataset leaving only the
          first 100 samples sorted. Defaults to True.
  
  Returns:
      List[Dict]: sorted list of conversations
docstr_tok: ["Sort","the","conversations","by","length","of","user_input","+","completion","or","by","length","of","user_input","only","Args",":","conversations","(","List","[","Dict","]",")",":","list","of","conversations","only_input","(","bool",",","optional",")",":","sort","by","length","of","user_input","only",".","Defaults","to","False",".","reverse","(","bool",",","optional",")",":","sort","in","descending","order",".","Defaults","to","True",".","shuffle","(","bool",",","optional",")",":","shuffle","the","dataset","leaving","only","the","first","100","samples","sorted",".","Defaults","to","True",".","Returns",":","List","[","Dict","]",":","sorted","list","of","conversations"]
code: def sort_conversation(
      conversations: List[Dict],
      only_input: bool = False,
      reverse: bool = True,
      shuffle: bool = True,
  ) -> List[Dict]:
      """Sort the conversations by length of user_input + completion
      or by length of user_input only
  
      Args:
          conversations (List[Dict]): list of conversations
          only_input (bool, optional): sort by length of user_input only.
              Defaults to False.
          reverse (bool, optional): sort in descending order.
              Defaults to True.
          shuffle (bool, optional): shuffle the dataset leaving only the
              first 100 samples sorted. Defaults to True.
  
      Returns:
          List[Dict]: sorted list of conversations
      """
  
      # define the sorting function
      if only_input is True:
  
          def sort_fun(x):
              return len(x["user_input"])
  
      else:
  
          def sort_fun(x):
              return len(x["user_input"]) + len(x["completion"])
  
      # sort
      conversations = sorted(
          conversations,
          key=sort_fun,
          reverse=reverse,
      )
  
      # shuffle
      if shuffle is True:
          conversations = (
              conversations[:10]
              + np.random.choice(
                  conversations[10:],
                  size=len(conversations[10:]),
                  replace=False,
              ).tolist()
          )
  
      return conversations
  
imports: import json
  import os
  import numpy
  from beartype.typing import Dict, List, Union
  from datasets import load_dataset
  from chatllama.rlhf.config import Config, ConfigActor, ConfigReward
  from chatllama.rlhf.reward import RewardModel, CriticModel
  from chatllama.rlhf.actor import ActorModel
label_desc: Use image node_id 2 for calling the BaseDataset obj's underlying member method code with example usage: obj.sort_conversation(conversations, only_input, reverse, shuffle) and returns: conversations, len, unknown