code: def create_gen_function(port=5555, chat=False):
      def get_generation(
          prompt,
          greedy,
          add_BOS,
          token_to_gen,
          min_tokens,
          temp,
          top_p,
          top_k,
          repetition,
          end_strings,
      ):
          data = {
              "sentences": [prompt],
              "tokens_to_generate": int(token_to_gen),
              "temperature": temp,
              "add_BOS": add_BOS,
              "top_k": top_k,
              "top_p": top_p,
              "greedy": greedy,
              "all_probs": False,
              "repetition_penalty": repetition,
              "min_tokens_to_generate": int(min_tokens),
              "end_strings": [
                  i.strip()
                  for i in end_strings.split(",")
                  if len(i) != 0
              ],
          }
          response = text_generation(data, port=port)
          sentences = response["sentences"]
          bot_message = sentences[0]
          if bot_message.find("<extra_id_0") < 0:
              # hack due to the problem that huggingface's tokenizer strips out the <extra_id_x> token
              prompt = (
                  prompt.replace("<extra_id_0>", "")
                  .replace("<extra_id_1>", "")
                  .replace("<extra_id_2>", "")
              )
          bot_message = bot_message[len(prompt) :]
          return bot_message
  
      return get_generation
  
file_path: NeMo/nemo/collections/nlp/modules/common/megatron_web_server.py
imports: import asyncio
  from nemo.collections.nlp.modules.common.chat_css import CSS
  from nemo.collections.nlp.modules.common.megatron.retrieval_services.util import convert_retrieved_to_md, request_data, text_generation
label_desc: Use image node_id 2 for calling a global function with example usage: create_gen_function(port, chat) and returns: get_generation, bot_message