CentOS Stream 9
Sponsored Link

Ollama インストール2024/06/04

 

LLM をローカル環境で実行可能な Ollama をインストールします。

GPU なしのコンピューターでもそれなりの速度で動作します。

[1] Ollama をインストールします。
[root@dlp ~]#
wget https://ollama.ai/install.sh

[root@dlp ~]#
sh ./install.sh

>>> Downloading ollama...
########################################
>>> Installing ollama to /usr/local/bin...
>>> Creating ollama user...
>>> Adding ollama user to render group...
>>> Adding ollama user to video group...
>>> Adding current user to ollama group...
>>> Creating ollama systemd service...
>>> Enabling and starting ollama service...
Created symlink /etc/systemd/system/default.target.wants/ollama.service → /etc/systemd/system/ollama.service.
>>> The Ollama API is now available at 127.0.0.1:11434.
>>> Install complete. Run "ollama" from the command line.
WARNING: No NVIDIA/AMD GPU detected. Ollama will run in CPU-only mode.

# ollama サービスが起動

[root@dlp ~]#
systemctl status ollama

*  ollama.service - Ollama Service
     Loaded: loaded (/etc/systemd/system/ollama.service; enabled; preset: disabled)
     Active: active (running) since Tue 2024-06-04 15:24:01 JST; 27s ago
   Main PID: 1343 (ollama)
      Tasks: 14 (limit: 100254)
     Memory: 870.0M
        CPU: 7.554s
     CGroup: /system.slice/ollama.service
             +-- 1343 /usr/local/bin/ollama serve

# ローカルホストのポート 11434 をリスン

[root@dlp ~]#
ss -napt | grep ollama

LISTEN 0      4096       127.0.0.1:11434      0.0.0.0:*     users:(("ollama",pid=1343,fd=3))
[2] 他ホストから直接アクセスしたい場合は、リスンする範囲を変更できます。
[root@dlp ~]#
systemctl edit ollama.service
# OLLAMA_HOST を追記
# 全てリスンする場合は [0.0.0.0] を指定
# インターナルネットワークをリスンする場合はその IP アドレスを指定

[Service]
Environment="OLLAMA_HOST=0.0.0.0"

[root@dlp ~]#
systemctl restart ollama.service
[root@dlp ~]#
ss -napt | grep ollama

LISTEN 0      4096               *:11434            *:*     users:(("ollama",pid=1394,fd=3))
[3] Ollama を使用するには、まずモデルをダウンロードします。
# 例として Llama3 の 8B モデルをダウンロード

[root@dlp ~]#
ollama pull llama3:8b

pulling manifest
pulling 6a0746a1ec1a... 100% 
pulling 4fa551d4f938... 100% 
pulling 8ab4849b038c... 100% 
pulling 577073ffcc6c... 100% 
pulling 3f8eb4da87fa... 100% 
verifying sha256 digest
writing manifest
removing any unused layers
success

# 例として Microsoft の Phi3 モデルをダウンロード

[root@dlp ~]#
ollama pull phi3

pulling manifest
pulling b26e6713dc74... 100%
pulling fa8235e5b48f... 100%
pulling 542b217f179c... 100%
pulling 8dde1baf1db0... 100%
pulling f91db7a2deb9... 100%
verifying sha256 digest
writing manifest
removing any unused layers
success

# 例として Google の Gemma モデルをダウンロード

[root@dlp ~]#
ollama pull gemma

pulling manifest
pulling ef311de6af9d... 100% 
pulling 097a36493f71... 100% 
pulling 109037bec39c... 100% 
pulling 65bb16cf5983... 100% 
pulling 0c2a5137eb3c... 100% 
verifying sha256 digest
writing manifest
removing any unused layers
success

# 例として IBM の Granite Code モデルをダウンロード

root@dlp:~#
ollama pull granite-code:8b

pulling manifest
pulling 8718ec280572... 100%
pulling 0d7c97d535b6... 100%
pulling e50df8490144... 100%
pulling 9893bb2c2917... 100%
pulling 6be564cde5be... 100%
verifying sha256 digest
writing manifest
removing any unused layers
success
[4] Ollama の使用方法です。
[root@dlp ~]#
ollama run llama3:8b

>>> Send a message (/? for help)
>>> Who are you?
I am LLaMA, a large language model trained by a team of researcher at Meta AI. My primary function is to generate
human-like text based on the input I receive. This can include answering questions, providing information on various
topics, and even creating original stories or poems.

I'm an AI designed to be helpful and engaging, so feel free to ask me anything that's on your mind!

>>> What are you good at?
I'm a large language model, so I'm good at:

1. **Answering questions**: I can process natural language queries and provide relevant answers from my training data.
2. **Generating text**: I can create human-like text based on a prompt or topic. This can be useful for writing articles,
creating content, or even generating creative stories.
3. **Chatting**: I'm designed to have a conversation with you, understanding context and responding accordingly.
4. **Summarizing information**: If you give me a long piece of text, I can summarize the main points for you.
5. **Language translation**: While not perfect, I can translate short phrases or sentences from one language to another.
6. **Creative writing**: I can generate creative writing, such as poetry or short stories, based on prompts or topics.
7. **Jokes and humor**: I've been trained on a wide range of humor styles, so I can try to make you laugh!
8. **Conversational dialogue**: I can engage in natural-sounding conversations, using context to guide my responses.
9. **Trivia and knowledge**: My training data includes a vast amount of information on various topics, making me a great
resource for trivia or general knowledge questions.

Remember, while I'm good at these things, I'm not perfect. I may make mistakes or struggle with complex topics. But I'll
always do my best to assist you!

exit する場合は [/bye] と入力
>>> /bye

[root@dlp ~]#
ollama run phi3

>>> Who are you?
 I am Phi, an AI developed by Microsoft to assist users with their queries and provide helpful information. How can I
assist you today?

>>> What are you good at?
 As an AI, I excel in various tasks such as processing large amounts of data quickly, understanding natural language to
interpret questions and commands, providing accurate information based on my training, and learning from interactions to
improve future responses. My capabilities span across multiple domains including but not limited to customer service,
tutoring, recommendations, and general knowledge queries.

>>> /bye

[root@dlp ~]#
ollama run gemma

>>> Who are you?
I am a large language model, trained by Google. I am designed to understand and generate human language, and to assist you
with various tasks such as information retrieval, conversation, and content creation.

>>> What are you good at?
I am skilled in:

* **Language processing:** Understanding and generating human language, including text summarization, translation, and
sentiment analysis.
* **Information retrieval:** Finding and summarizing relevant information from vast amounts of data.
* **Conversation:** Engaging in natural and informative conversations.
* **Content creation:** Generating creative and informative text, such as stories, articles, and code.
* **Problem-solving:** Solving puzzles and answering trivia questions.

I am still under development, but I am constantly learning and improving my abilities.

>>> /bye
[5] Ollama を API 経由でも利用できます。
[root@dlp ~]# curl http://localhost:11434/api/chat -d '{
  "model": "gemma",
  "stream": false,
  "messages": [
    { "role": "user", "content": "Where will the next Summer Olympics be held?" }
  ]
}'
{"model":"gemma","created_at":"2024-06-04T07:08:40.939562582Z","message":{"role":"assistant","content":"The next Summer Olympics will be held in **Los Angeles, California, United States** in 2028."},"done_reason":"stop","done":true,"total_duration":9761561320,"load_duration":2989669897,"prompt_eval_count":35,"prompt_eval_duration":2551778000,"eval_count":25,"eval_duration":4096143000}

[root@dlp ~]# curl http://dlp.srv.world:11434/api/chat -d '{
  "model": "phi3",
  "stream": false,
  "messages": [
    { "role": "user", "content": "Tell me the recommended sightseeing spots in Hiroshima, Japan." }
  ]
}'
{"model":"phi3","created_at":"2024-06-04T07:10:50.975014079Z","message":{"role":"assistant","content":" Hiroshima is a beautiful city with many fascinating sights that are sure to captivate any visitor. Here's a list of some highly recommended sites for your visit:\n\n1. Peace Memorial Park and Museum: This park was established after the atomic bombing in 1945, as a symbol of peace and reconciliation. The Hiroshima Peace Memorial (Genbaku Dome) is an iconic structure within this park that still bears visible signs from the bombing. The museum offers insight into both the pre-war era and post-bombing reconstruction efforts, as well as a poignant account of the human impact of nuclear warfare.\n\n2. Hiroshima Castle: This castle dates back to 1589 and is an excellent example of traditional Japanese architecture. It was destroyed during World War II but rebuilt with many historical artifacts preserved within its walls. The castle grounds are perfect for a leisurely stroll, offering picturesque views of the city's skyline from above.\n\n3. Hiroshima Peace Memorial Museum: As part of the larger Peace Memorial Park complex, this museum provides an in-depth account of the bombing and its aftermath. It also offers an engaging educational experience that encourages visitors to think about peace, coexistence, and nuclear disarmament.\n\n4. Hiroshima Castle Museum: This is another museum housed within the castle grounds which focuses on local history from a pre-World War II perspective, showcasing artifacts relating to life in Hiroshima before the bombing.\n\n5. Miyajima (Itsukushima Shrine): Located about an hour by ferry from central Hiroshima, this scenic island is home to Itsukushima Shrine - a UNESCO World Heritage Site famous for its \"floating\" torii gate that appears to float above the water during high tide. The surrounding forest and walking paths provide stunning views of the city from afar as well.\n\n6. Hiroshima City Museum of Contemporary Art: For modern art enthusiasts, this museum showcases a wide variety of contemporary works by both Japanese and international artists. It offers an insightful look into current trends in visual arts.\n\n7. Misono Park: This serene park is located near Hiroshima Station and features beautiful cherry blossoms each spring. The peace-themed sculptures, ponds, and walking paths make for a relaxing afternoon stroll with family or friends.\n\n8. Hijiyama Park: This picturesque spot offers panoramic views of the city from its 135-meter observation tower. It is ideal for enjoying sunsets over Hiroshima Bay and has numerous cafes and restaurants to explore along the way.\n\n9. Mitsubishi Ichigokan Museum: This museum focuses on showcasing the artwork of renowned Japanese artist Yayoi Kusama, including her famous polka dot paintings. It's a great spot for visitors interested in contemporary and pop-art styles.\n\n10. Hiroshima Castle Park: Located adjacent to the castle grounds, this large park is perfect for picnics or leisentic walks with picturesque sights of the city skyline against the setting sun.\n\nThese are just some highlights from the beautiful city of Hiroshima, but there's no shortage of attractions waiting to be explored in this vibrant and resilient metropolis!"},"done_reason":"stop","done":true,"total_duration":62678157131,"load_duration":1115689336,"prompt_eval_count":21,"prompt_eval_duration":735051000,"eval_count":778,"eval_duration":60783662000}
関連コンテンツ