• Download LLama CPP -

    • git clone https://github.com/ggerganov/llama.cpp.git
    • The main goal of llama.cpp is to run the LLaMA model using 4-bit integer quantization on a MacBook. Plain C/C++ implementation without dependencies.
  • cd llama.cpp

  • make clean && LLAMA_METAL=1 make

  • Download the GGML version of the model -

    • wget https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGML/resolve/main/llama-2-7b-chat.ggmlv3.q4_0.bin
  • Install LlamaCpp library to run from Python script:

    • CMAKE_ARGS="-DLLAMA_CUBLAS=on" FORCE_CMAKE=1 pip install --upgrade --force-reinstall llama-cpp-python==0.1.77 --no-cache-dir
  • Here is the Python script:

    from langchain.llms import LlamaCpp
    from langchain import PromptTemplate, LLMChain
    from langchain.callbacks.manager import CallbackManager
    from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
    
    # Callbacks support token-wise streaming
    callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])
    # Verbose is required to pass to the callback manager
    
    path = (
        f"/Users/bipulvaibhav/Documents/AI/openai/llama.cpp/llama-2-7b-chat.ggmlv3.q4_0.bin"
    )
    
    llm = LlamaCpp(
        model_path=path,
        temperature=0,
        max_tokens=2000,
        callback_manager=callback_manager,
        verbose=True,
    )
    
    prompt = """
    Question: where is Taj Mahal?
    """
    llm(prompt)