class_docstr: High-level Python wrapper for a chatglm.cpp model.
class_docstr_tok: ["High-level","Python","wrapper","for","a","chatglm.cpp","model","."]
code: def stream(
      self,
      prompt: str,
      max_tokens: int,
      temperature: float,
      top_p: float,
      top_k: int,
      stop: Optional[List[str]] = [],
      model: Optional[str] = None,
  ):
      completion_id: str = f"cmpl-{str(uuid.uuid4())}"
      created: int = int(time.time())
      if model is None:
          model_name = self.model_path
      else:
          model_name = model
      input_tokens = self._tokenize(prompt)
      prompt_len = len(input_tokens)
      if max_tokens < 1:
          yield {
              "id": completion_id,
              "object": "text_completion",
              "created": created,
              "model": model_name,
              "choices": [
                  {
                      "text": prompt,
                      "index": 0,
                      "logprobs": None,
                      "finish_reason": "length",
                  }
              ],
              "usage": {"prompt_tokens": prompt_len},
          }
      else:
          history_text = prompt
          for i in range(max_tokens):
              token = self.forward(
                  input_ids=input_tokens,
                  top_k=top_k,
                  top_p=top_p,
                  temperature=temperature,
              )
              input_tokens.append(token)
              if token == self.eos_token():
                  print("\n")
                  break
              text = self.detokenize(input_tokens)
              if text.endswith("�"):
                  # generated new token is part of an emoji
                  # (some emoji consists of multiple tokens)
                  # continue to generate more tokens to decode this emoji
                  continue
              text = text[len(history_text) :]
              history_text += text
              yield {
                  "id": completion_id,
                  "object": "text_completion",
                  "created": created,
                  "model": model_name,
                  "choices": [
                      {
                          "text": text,
                          "index": 0,
                          "logprobs": None,
                          "finish_reason": None,
                      }
                  ],
                  "usage": {"prompt_tokens": prompt_len},
              }
  
file_path: BigDL/python/llm/src/bigdl/llm/ggml/model/chatglm/chatglm.py
imports: from .chatglm_cpp import chatglm_load, chatglm_tokenize, chatglm_detokenize, chatglm_forward, chatglm_eos_token
  from bigdl.llm.utils.common import invalidInputError
  from bigdl.llm.ggml.model.generation import GenerationMixin
  from typing import List, Optional, Generator, Sequence, Union
  import time
  import uuid
  import warnings
label_desc: Use image node_id 5 for calling the ChatGLM obj's underlying member method code with example usage: obj.stream(prompt, max_tokens, temperature, top_p, top_k, stop, model) without return types