Setup a Ollama chat application locally
Learn to use the Ollama for local development
It would take sometime for the models to get donloaded. Duration depends on your machine and speed of internet.
ollama run gemma2
ollama run llama3.1
ollama serve
Note: In the lesson video, I used the HTML UI application; so if you are not able to make up your mind on which app to use, go with ‘HTML UI’ - it is easy to follow & install.
In this part of the exercise, you will write code to interact with the models hosted in OLlama. Recall that any HTTP library can be used for these interactions.
Start by creating a new notebook under [root-folder-for-course]/gen-ai-app-dev-template/[Endpoints]/[ollama-usage.ipynb]. Add the code below and run it.
import requests
# URL for the endpoints
base_url = 'http://localhost:11434'
The API indepoint to get the model information : /api/show.
# Create the URL for getting model information
url = base_url + '/api/show'
# Query to be sent in body
query = {
"name": "llama3.1"
}
# Invoke API
response = requests.post(url, json=query)