Featured image of post Install ollama on Linux and use the ollama Python package

Install ollama on Linux and use the ollama Python package

📌 Introduction

Install ollama and use large language models such as llama2 on Linux, and utilize the ollama package in Python.

在 Linux 安裝 ollama 以及使用 llama2 等大語言模型,並在 python 中使用 ollama 的套件。

📝 Steps

在 Linux 安裝

curl -fsSL https://ollama.com/install.sh | sh

快速啟動

使用下方指令將自動下載語言模型的檔案並啟動對話視窗

$ ollama run llama2

查看已經安裝的模型清單

$ ollama ls

在 Python 使用

import ollama

response = ollama.chat(model='llama2', messages=[
  {
    'role': 'user',
    'content': 'Why is the sky blue?',
  },
])

print(response['message']['content'])

建立多個 Ollama

https://github.com/ollama/ollama/issues/764#issuecomment-1836760366

解除安裝 Ollama

Remove the ollama service:

sudo systemctl stop ollama
sudo systemctl disable ollama
sudo rm /etc/systemd/system/ollama.service

Remove the ollama binary from your bin directory (either /usr/local/bin, /usr/bin, or /bin):

sudo rm $(which ollama)

Remove the downloaded models and Ollama service user and group:

sudo rm -r /usr/share/ollama
sudo userdel ollama
sudo groupdel ollama

📖 Ref.

 

Licensed under CC BY-NC-SA 4.0
Last updated on Apr 13, 2024 20:11 CST