Run LLMs Locally with Ollama
Ollama is used to run and manage large language models (LLMs) locally on your own computer for offline, private, and efficient AI operations. It simplifies downloading, running, and customizing open-source LLMs like Llama 3 or Mistral through a simple command-line interface, making it a valuable tool for developers, researchers, and anyone concerned with data privacy.
Ollama server is used to serve large language models (LLMs) locally on a user's machine, making them accessible via an API, a web UI, or through various applications like code assistants. It provides a simple way to download, run, and manage models for tasks such as building chatbots, developing applications, and conducting research, with a focus on local execution for data privacy and lower latency.
Here are simple steps to work on this exercise:
1) Install Ollama: Download and install Ollama from Ollama Download
2) Start the server: Run ollama serve in a separate terminal to make the server available. (This is often automatic on startup, but it's good to verify.)
Eg: C:\Users\Admin\AppData\Local\Programs\Ollama>ollama serve
Check the browser to track the Ollama server status:
3) Pull a model: Download a model to your local machine.
Eg: C:\Users\Admin\AppData\Local\Programs\Ollama>ollama pull llama3.2
Few of the below options I tried to get the response from a simple Prompt: What is Large Language Model?
Option#1: Run the below command from command line and enter the prompt in
>>> Send a message (/? for help) and the response comes from the selected llma3.2 model like below.
C:\Users\Admin\AppData\Local\Programs\Ollama>ollama run llama3.2
Option#2: Use curl command to use Ollama API service
C:\Users\Admin\AppData\Local\Programs\Ollama>curl http://localhost:11434/api/generate -d "{\"model\": \"llama3.2\", \"prompt\": \"What is a large language model?\",\"stream\": false}"
JSON response containing the model's answer:
Option#3: Run the Ollama API from Postman but for this we need to install the Desktop app since the Ollama server runs on localhost
Option#4: Run a python program & the package: langchain, langchain-ollama, ollama with the below steps using Windows
1) Install Python3 and above
2) Open the Visual Studio env to run the below DOS commands from the terminal inside Visual Studio
1) C:\Users\Admin>python -m venv chatbot
2) (chatbot) C:\Users\Admin\>cd chatbot\Scripts
3) (chatbot) C:\Users\Admin\chatbot\Scripts>activate.bat
4) (chatbot) C:\Users\Admin\chatbot\Scripts>pip install langchain langchain-ollama ollama
langchain: This installs the core LangChain framework.langchain-ollama: This installs the specific integration package that allows LangChain to interact with Ollama.
3) Add a new main.py file under C:\Users\Admin\chatbot\Scripts directory and add the simple code to run the prompt using model:llama3.2
from langchain_ollama import OllamaLLM
model=OllamaLLM(model="llama3.2")
result=model.invoke(input="What is LLM")
print(result)
Here is the response from Visual Studio environment: