code: def test_chat(
      chat,
      openai_client,
      async_client,
      system_prompt,
      chat_conversation,
      add_chat_history_to_context,
      prompt,
      client_kwargs,
      stream_output,
      verbose,
  ):
      # COMPLETION
  
      if chat:
          client = openai_client.chat.completions
          async_client = async_client.chat.completions
  
          messages0 = []
          if system_prompt:
              messages0.append(
                  {"role": "system", "content": system_prompt}
              )
          if chat_conversation and add_chat_history_to_context:
              for message1 in chat_conversation:
                  if len(message1) == 2:
                      messages0.append(
                          {
                              "role": "user",
                              "content": message1[0]
                              if message1[0] is not None
                              else "",
                          }
                      )
                      messages0.append(
                          {
                              "role": "assistant",
                              "content": message1[1]
                              if message1[1] is not None
                              else "",
                          }
                      )
          messages0.append(
              {
                  "role": "user",
                  "content": prompt if prompt is not None else "",
              }
          )
  
          client_kwargs.update(dict(messages=messages0))
      else:
          client = openai_client.completions
          async_client = async_client.completions
  
          client_kwargs.update(dict(prompt=prompt))
  
      responses = client.create(**client_kwargs)
  
      if not stream_output:
          if chat:
              text = responses.choices[0].message.content
          else:
              text = responses.choices[0].text
          print(text)
      else:
          collected_events = []
          text = ""
          for event in responses:
              collected_events.append(event)  # save the event response
              if chat:
                  delta = event.choices[0].delta.content
              else:
                  delta = event.choices[0].text  # extract the text
              text += delta  # append the text
              if verbose:
                  print("delta: %s" % delta)
          print(text)
  
      if "Who" in prompt:
          assert "OpenAI" in text or "chatbot" in text
      else:
          assert "birds" in text
  
file_path: h2ogpt/openai_server/test_openai_server.py
imports: import time
  import pytest
  import os
  from tests.utils import wrap_test_forked
label_desc: Use image node_id 6 for calling a global function with example usage: test_chat(chat, openai_client, async_client, system_prompt, chat_conversation, add_chat_history_to_context, prompt, client_kwargs, stream_output, verbose) without return types