code: def stream_chat(
      model, tokenizer, stopping_criteria, input_str, chat_history
  ):
      prompt = format_prompt(input_str, chat_history)
      # print(prompt)
      input_ids = tokenizer([prompt], return_tensors="pt").to("xpu")
      streamer = TextIteratorStreamer(
          tokenizer, skip_prompt=True, skip_special_tokens=True
      )
      generate_kwargs = dict(
          input_ids,
          streamer=streamer,
          max_new_tokens=512,
          stopping_criteria=stopping_criteria,
      )
      from threading import Thread
  
      # to ensure non-blocking access to the generated text, generation process should be ran in a separate thread
      thread = Thread(target=model.generate, kwargs=generate_kwargs)
      thread.start()
      output_str = []
      print(Fore.BLUE + "BigDL-LLM: " + Fore.RESET, end="")
      for partial_output_str in streamer:
          output_str.append(partial_output_str)
          # remove the last HUMAN_ID if exists
          print(partial_output_str.replace(f"{HUMAN_ID}", ""), end="")
      chat_history.append(
          (
              input_str,
              "".join(output_str).replace(f"{HUMAN_ID}", "").rstrip(),
          )
      )
  
file_path: BigDL/docker/llm/inference/xpu/docker/chat.py
imports: import intel_extension_for_pytorch
  import torch
  import argparse
  import sys
  from transformers import AutoModel, AutoModelForCausalLM, AutoTokenizer, AutoConfig
  from transformers import TextIteratorStreamer
  from transformers.tools.agents import StopSequenceCriteria
  from transformers.generation.stopping_criteria import StoppingCriteriaList
  from colorama import Fore
  from bigdl.llm import optimize_model
label_desc: Use image node_id 2 for calling a global function with example usage: stream_chat(model, tokenizer, stopping_criteria, input_str, chat_history) without return types