code: def test_gradio_inference_server(
      base_model,
      force_langchain_evaluate,
      do_langchain,
      enforce_h2ogpt_ui_key,
      enforce_h2ogpt_api_key,
      prompt="Who are you?",
      stream_output=False,
      max_new_tokens=256,
      langchain_mode="Disabled",
      langchain_action=LangChainAction.QUERY.value,
      langchain_agents=[],
      user_path=None,
      langchain_modes=["UserData", "MyData", "LLM", "Disabled"],
      docs_ordering_type="reverse_sort",
  ):
      if (
          enforce_h2ogpt_api_key
          and base_model != "h2oai/h2ogpt-oig-oasst1-512-6_9b"
      ):
          # no need for so many cases
          return
      if force_langchain_evaluate:
          langchain_mode = "MyData"
      if do_langchain:
          langchain_mode = "UserData"
          from tests.utils import make_user_path_test
  
          user_path = make_user_path_test()
          # from src.gpt_langchain import get_some_dbs_from_hf
          # get_some_dbs_from_hf()
  
      max_seq_len_client = None
      if base_model in [
          "h2oai/h2ogpt-oig-oasst1-512-6_9b",
          "h2oai/h2ogpt-oasst1-512-12b",
      ]:
          prompt_type = PromptType.human_bot.name
      elif base_model in [
          "h2oai/h2ogpt-gm-oasst1-en-2048-falcon-7b-v2"
      ]:
          prompt_type = PromptType.prompt_answer.name
      elif base_model in ["llama"]:
          max_seq_len_client = 2048
          prompt_type = PromptType.llama2.name
      elif base_model in ["gptj"]:
          max_seq_len_client = 2048
          prompt_type = PromptType.gptj.name
      else:
          raise NotImplementedError(base_model)
  
      main_kwargs = dict(
          base_model=base_model,
          prompt_type=prompt_type,
          chat=True,
          stream_output=stream_output,
          gradio=True,
          num_beams=1,
          block_gradio_exit=False,
          max_new_tokens=max_new_tokens,
          langchain_mode=langchain_mode,
          langchain_action=langchain_action,
          langchain_agents=langchain_agents,
          user_path=user_path,
          langchain_modes=langchain_modes,
          docs_ordering_type=docs_ordering_type,
          force_langchain_evaluate=force_langchain_evaluate,
          system_prompt="",
          verbose=True,
      )
  
      # inference server
      from src.gen import main
  
      main(**main_kwargs)
      inference_server = get_inf_server()
      inf_port = get_inf_port()
  
      # server that consumes inference server has different port
      from src.gen import main
  
      client_port = (
          inf_port + 2
      )  # assume will not use +  2 in testing, + 1 reserved for non-gradio inference servers
      # only case when GRADIO_SERVER_PORT and HOST should appear in tests because using 2 gradio instances
      os.environ["GRADIO_SERVER_PORT"] = str(client_port)
      os.environ["HOST"] = "http://127.0.0.1:%s" % client_port
  
      h2ogpt_key = "foodoo#"
      main_kwargs = main_kwargs.copy()
      if enforce_h2ogpt_api_key:
          main_kwargs.update(
              dict(
                  enforce_h2ogpt_api_key=True,
                  h2ogpt_api_keys=[h2ogpt_key],
              )
          )
      main_kwargs.update(dict(max_seq_len=max_seq_len_client))
      main(**main_kwargs, inference_server=inference_server)
  
      # client test to server that only consumes inference server
      from src.client_test import run_client_chat
  
      res_dict, client = run_client_chat(
          prompt=prompt,
          prompt_type=prompt_type,
          stream_output=stream_output,
          max_new_tokens=max_new_tokens,
          langchain_mode=langchain_mode,
          langchain_action=langchain_action,
          langchain_agents=langchain_agents,
      )
      assert res_dict["prompt"] == prompt
      assert res_dict["iinput"] == ""
  
      # will use HOST from above
      if enforce_h2ogpt_api_key:
          # try without key first
          ret1, ret2, ret3, ret4, ret5, ret6, ret7 = run_client_many(
              prompt_type=None
          )
          assert "Invalid Access Key" in ret1["response"]
          assert "Invalid Access Key" in ret2["response"]
          assert "Invalid Access Key" in ret3["response"]
          assert "Invalid Access Key" in ret4["response"]
          assert "Invalid Access Key" in ret5["response"]
          assert "Invalid Access Key" in ret6["response"]
          assert "Invalid Access Key" in ret7["response"]
          ret1, ret2, ret3, ret4, ret5, ret6, ret7 = run_client_many(
              prompt_type=None, h2ogpt_key="foo"
          )
          assert "Invalid Access Key" in ret1["response"]
          assert "Invalid Access Key" in ret2["response"]
          assert "Invalid Access Key" in ret3["response"]
          assert "Invalid Access Key" in ret4["response"]
          assert "Invalid Access Key" in ret5["response"]
          assert "Invalid Access Key" in ret6["response"]
          assert "Invalid Access Key" in ret7["response"]
  
      # try normal or with key if enforcing
      ret1, ret2, ret3, ret4, ret5, ret6, ret7 = run_client_many(
          prompt_type=None, h2ogpt_key=h2ogpt_key
      )  # client shouldn't have to specify
      if base_model == "h2oai/h2ogpt-oig-oasst1-512-6_9b":
          assert "h2oGPT" in ret1["response"]
          assert "Birds" in ret2["response"]
          assert "Birds" in ret3["response"]
          assert "h2oGPT" in ret4["response"]
          assert "h2oGPT" in ret5["response"]
          assert "h2oGPT" in ret6["response"]
          assert "h2oGPT" in ret7["response"]
      elif base_model == "h2oai/h2ogpt-gm-oasst1-en-2048-falcon-7b-v2":
          assert (
              "I am a language model trained" in ret1["response"]
              or "I am a helpful assistant" in ret1["response"]
              or "I am a chatbot." in ret1["response"]
              or "a chat-based assistant that can answer questions"
              in ret1["response"]
              or "I am an AI language model" in ret1["response"]
              or "I am an AI assistant." in ret1["response"]
          )
          assert "Once upon a time" in ret2["response"]
          assert "Once upon a time" in ret3["response"]
          assert (
              "I am a language model trained" in ret4["response"]
              or "I am a helpful assistant" in ret4["response"]
              or "I am a chatbot." in ret4["response"]
              or "a chat-based assistant that can answer questions"
              in ret4["response"]
              or "I am an AI language model" in ret4["response"]
              or "I am an AI assistant." in ret4["response"]
          )
          assert (
              "I am a language model trained" in ret5["response"]
              or "I am a helpful assistant" in ret5["response"]
              or "I am a chatbot." in ret5["response"]
              or "a chat-based assistant that can answer questions"
              in ret5["response"]
              or "I am an AI language model" in ret5["response"]
              or "I am an AI assistant." in ret5["response"]
          )
          assert (
              "I am a language model trained" in ret6["response"]
              or "I am a helpful assistant" in ret6["response"]
              or "I am a chatbot." in ret6["response"]
              or "a chat-based assistant that can answer questions"
              in ret6["response"]
              or "I am an AI language model" in ret6["response"]
              or "I am an AI assistant." in ret6["response"]
          )
          assert (
              "I am a language model trained" in ret7["response"]
              or "I am a helpful assistant" in ret7["response"]
              or "I am a chatbot." in ret7["response"]
              or "a chat-based assistant that can answer questions"
              in ret7["response"]
              or "I am an AI language model" in ret7["response"]
              or "I am an AI assistant." in ret7["response"]
          )
      elif base_model == "llama":
          assert (
              "I am a bot." in ret1["response"]
              or "can I assist you today?" in ret1["response"]
              or "How can I assist you?" in ret1["response"]
              or "I'm LLaMA" in ret1["response"]
          )
          assert (
              "Birds" in ret2["response"]
              or "Once upon a time" in ret2["response"]
          )
          assert (
              "Birds" in ret3["response"]
              or "Once upon a time" in ret3["response"]
          )
          assert (
              "I am a bot." in ret4["response"]
              or "can I assist you today?" in ret4["response"]
              or "How can I assist you?" in ret4["response"]
              or "I'm LLaMA" in ret4["response"]
          )
          assert (
              "I am a bot." in ret5["response"]
              or "can I assist you today?" in ret5["response"]
              or "How can I assist you?" in ret5["response"]
              or "I'm LLaMA" in ret5["response"]
          )
          assert (
              "I am a bot." in ret6["response"]
              or "can I assist you today?" in ret6["response"]
              or "How can I assist you?" in ret6["response"]
              or "I'm LLaMA" in ret6["response"]
          )
          assert (
              "I am a bot." in ret7["response"]
              or "can I assist you today?" in ret7["response"]
              or "How can I assist you?" in ret7["response"]
              or "I'm LLaMA" in ret7["response"]
          )
      elif base_model == "gptj":
          assert (
              "I am a bot." in ret1["response"]
              or "can I assist you today?" in ret1["response"]
              or "a student at" in ret1["response"]
              or "am a person who" in ret1["response"]
              or "I am" in ret1["response"]
              or "I'm a student at" in ret1["response"]
          )
          assert (
              "Birds" in ret2["response"]
              or "Once upon a time" in ret2["response"]
          )
          assert (
              "Birds" in ret3["response"]
              or "Once upon a time" in ret3["response"]
          )
          assert (
              "I am a bot." in ret4["response"]
              or "can I assist you today?" in ret4["response"]
              or "a student at" in ret4["response"]
              or "am a person who" in ret4["response"]
              or "I am" in ret4["response"]
              or "I'm a student at" in ret4["response"]
          )
          assert (
              "I am a bot." in ret5["response"]
              or "can I assist you today?" in ret5["response"]
              or "a student at" in ret5["response"]
              or "am a person who" in ret5["response"]
              or "I am" in ret5["response"]
              or "I'm a student at" in ret5["response"]
          )
          assert (
              "I am a bot." in ret6["response"]
              or "can I assist you today?" in ret6["response"]
              or "a student at" in ret6["response"]
              or "am a person who" in ret6["response"]
              or "I am" in ret6["response"]
              or "I'm a student at" in ret6["response"]
          )
          assert (
              "I am a bot." in ret7["response"]
              or "can I assist you today?" in ret7["response"]
              or "a student at" in ret7["response"]
              or "am a person who" in ret7["response"]
              or "I am" in ret7["response"]
              or "I'm a student at" in ret7["response"]
          )
      print("DONE", flush=True)
  
imports: import os
  import subprocess
  import time
  from datetime import datetime
  import pytest
  from src.utils import get_ngpus_vis, makedirs
  from tests.utils import wrap_test_forked, get_inf_port, get_inf_server
  from tests.test_langchain_units import have_openai_key, have_replicate_key
  from src.client_test import run_client_many, test_client_basic_api_lean
  from src.enums import PromptType, LangChainAction
label_desc: Use image node_id 1 for calling a global function with example usage: test_gradio_inference_server(base_model, force_langchain_evaluate, do_langchain, enforce_h2ogpt_ui_key, enforce_h2ogpt_api_key, prompt, stream_output, max_new_tokens, langchain_mode, langchain_action, langchain_agents, user_path, langchain_modes, docs_ordering_type) without return types