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 _eval(
      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:
          return {
              "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,
                  "completion_tokens": 0,
                  "total_tokens": prompt_len,
              },
          }
  
      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():
              break
  
      text = self.detokenize(input_tokens)
      split_text = text[len(prompt) :]
      split_text.rstrip("�")  # remove partial emoji
      if stop != []:
          for stop_word in stop:
              split_text = split_text.split(stop_word)[0]
      if split_text != text:
          finish_reason = "stop"
      else:
          finish_reason = None
      completion_len = len(input_tokens) - prompt_len
      return {
          "id": completion_id,
          "object": "text_completion",
          "created": created,
          "model": model_name,
          "choices": [
              {
                  "text": prompt + split_text,
                  "index": 0,
                  "logprobs": None,
                  "finish_reason": finish_reason,
              }
          ],
          "usage": {
              "prompt_tokens": prompt_len,
              "completion_tokens": completion_len,
              "total_tokens": prompt_len + completion_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 4 for calling the ChatGLM obj's underlying member method code with example usage: obj._eval(prompt, max_tokens, temperature, top_p, top_k, stop, model) and returns: dict, dict