code: def stream_chat(
      model, tokenizer, kv_cache=None, max_gen_len=512, stop_words=[]
  ):
      past_key_values = None
      while True:
          user_input = input(Fore.GREEN + "\nHuman: " + Fore.RESET)
          # let's stop the conversation when user input "stop"
          if user_input == "stop":
              break
          prompt = f"{HUMAN_ID} {user_input}\n{BOT_ID} "
          input_ids = tokenizer(prompt, return_tensors="pt").input_ids
          seq_len = input_ids.shape[1]
          if kv_cache is not None:
              space_needed = seq_len + max_gen_len
              past_key_values = kv_cache.evict_for_space(
                  past_key_values, space_needed
              )
  
          past_key_values = greedy_generate(
              model,
              tokenizer,
              input_ids,
              past_key_values,
              max_gen_len=max_gen_len,
              stop_words=stop_words,
          )
  
file_path: BigDL/python/llm/portable-zip/chat.py
imports: 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
  from kv_cache import StartRecentKVCache
label_desc: Use image node_id 3 for calling a global function with example usage: stream_chat(model, tokenizer, kv_cache, max_gen_len, stop_words) without return types