code: def test_llama_patch(mock_llama):
      n_ctx = 128
      llama = llama_cpp.Llama(
          model_path=MODEL, vocab_only=True, n_ctx=n_ctx
      )
      n_vocab = llama_cpp.llama_n_vocab(llama._model.model)
      assert n_vocab == 32000
  
      text = "The quick brown fox"
      output_text = " jumps over the lazy dog."
      all_text = text + output_text
  
      ## Test basic completion from bos until eos
      mock_llama(llama, all_text)
      completion = llama.create_completion("", max_tokens=36)
      assert completion["choices"][0]["text"] == all_text
      assert completion["choices"][0]["finish_reason"] == "stop"
  
      ## Test basic completion until eos
      mock_llama(llama, all_text)
      completion = llama.create_completion(text, max_tokens=20)
      assert completion["choices"][0]["text"] == output_text
      assert completion["choices"][0]["finish_reason"] == "stop"
  
      ## Test streaming completion until eos
      mock_llama(llama, all_text)
      chunks = list(
          llama.create_completion(text, max_tokens=20, stream=True)
      )
      assert (
          "".join(chunk["choices"][0]["text"] for chunk in chunks)
          == output_text
      )
      assert chunks[-1]["choices"][0]["finish_reason"] == "stop"
  
      ## Test basic completion until stop sequence
      mock_llama(llama, all_text)
      completion = llama.create_completion(
          text, max_tokens=20, stop=["lazy"]
      )
      assert completion["choices"][0]["text"] == " jumps over the "
      assert completion["choices"][0]["finish_reason"] == "stop"
  
      ## Test streaming completion until stop sequence
      mock_llama(llama, all_text)
      chunks = list(
          llama.create_completion(
              text, max_tokens=20, stream=True, stop=["lazy"]
          )
      )
      assert (
          "".join(chunk["choices"][0]["text"] for chunk in chunks)
          == " jumps over the "
      )
      assert chunks[-1]["choices"][0]["finish_reason"] == "stop"
  
      ## Test basic completion until length
      mock_llama(llama, all_text)
      completion = llama.create_completion(text, max_tokens=2)
      assert completion["choices"][0]["text"] == " jumps"
      assert completion["choices"][0]["finish_reason"] == "length"
  
      ## Test streaming completion until length
      mock_llama(llama, all_text)
      chunks = list(
          llama.create_completion(text, max_tokens=2, stream=True)
      )
      assert (
          "".join(chunk["choices"][0]["text"] for chunk in chunks)
          == " jumps"
      )
      assert chunks[-1]["choices"][0]["finish_reason"] == "length"
  
file_path: llama-cpp-python/tests/test_llama.py
imports: import ctypes
  import numpy
  import pytest
  from scipy.special import log_softmax
  import llama_cpp
label_desc: Use image node_id 3 for calling a global function with example usage: test_llama_patch(mock_llama) without return types