树莓派5用docker运行Ollama3

时间:2024-04-28 07:25:59

书接上回,树莓派5使用1panel安装 Ollama

点击终端就可以进入容器

输入以下代码

ollama run llama3

Llama3 是市场推崇的版本。您的 树莓派5上必须至少有 4.7GB 的可用空间,因此用树莓派玩机器学习就必须配置大容量的固态硬盘。用1panel部署网络下载速度高达每秒70MB。Ollama 在 Raspberry Pi 5上仅用两分钟完成 Llama3 模型安装,之后启动,您就可以开始与语言模型进行交互式通信了。
在这里插入图片描述

提问环节

输入您的问题:

Shakespeare's main works

树莓派5以每秒1.89 token的速度很快捷的给出了答案。
在这里插入图片描述

您对 Ollama3 的回答满意吗?

William Shakespeare is considered one of the greatest writers in the
English language and has written at least 38 plays and 154 sonnets. Here
are some of his most famous works:
Tragedies:
1.Romeo and Juliet (1595) - a classic tale of star-cross'd lovers.
2.Hamlet (1599-1602) - a prince's quest for justice and revenge.
3.Macbeth (1605-1606) - a Scottish nobleman's descent into madness
and tyranny.
4. Othello (1603-1604) - a tragic love story of a Moorish general and
his white wife.
5. King Lear (1605-1606) - an aging king's struggle with power,
family, and mortality.
Comedies:
1.A Midsummer Night's Dream (1595-1596) - a magical forest, love
potions, and mischief.
2. As You Like It (1599-1600) - a banished duke's journey to
self-discovery and love.
3. Twelfth Night (1601-1602) - a shipwrecked heroine's quest for love
and identity.
4. The Taming of the Shrew (1590-1595) - a battle-of-wits between two
strong-willed individuals.
Histories:
1.Henry IV, Part 1 (1596-1597) - a king's struggle with his own son
and his right to rule.
2. Henry V (1598-1599) - a young king's leadership in the Hundred
Years' War.
3. The First Part of Henry VI (1590-1591) - the early reign of King
Henry VI.
Romances:
1.Pericles, Prince of Tyre (1606-1608) - a prince's journey to
self-discovery and love.
2. Cymbeline (1609-1610) - a king's struggle with his own identity and
power.
3. The Tempest (1611-1612) - a sorcerer's quest for revenge and
forgiveness.
These are just some of the many works by Shakespeare, but they give you an
idea of the range and diversity of his writing.

使用 Curl 在终端上与 Ollama 3通信

Ollama 的一个很酷的功能是它的 API,您可以查询它。使用此 API,您可以请求它使用特定模型生成对提示的响应。

我们点击容器内ollama的端口地址
在这里插入图片描述
浏览器跳转http://192.168.3.9:32768/的ollama容器内,并且显示:Ollama is running
在这里插入图片描述
打开树莓派终端输入如下的json数据

curl  http://192.168.3.9:32768/api/generate -d '{
"model":"llama3",
"prompt": "Which writer is the Little Match Girl?",
"stream": false
}'

解释一下

在JSON的这一部分中,我们指定了以下信息:
model:这是我们希望 Ollama 在 Raspberry Pi 上运行的大型语言模型。我们坚持使用llama3模型。
prompt:提示是你想对模型说的话,通常这是一个问题。我们将询问模型Which writer is the Little Match Girl?。
stream:通过将 “stream” 选项设置为 false,我们告诉 Ollama 我们希望它等到模型完成生成后再发出响应。如果您不想处理来自模型的数据流,这将非常有用。通常,模型一次流式传输回一个单词。

Ollama 将返回结果 JSON 数据。在此内容中,您可以看到结果以及各种附加信息,例如完成提示所需的时间。
在这里插入图片描述
我把response提取出来看看回答的效果。

"response":"The Little Match Girl is a character from a short story by Hans Christian Andersen, titled \"The Little Match-Girl\". It was first published in 1845 and has since become one of Andersen's most famous stories. The story tells the tale of a young girl who sells matches on the street to support her family, but ultimately dies a tragic death after being unable to find any warmth or comfort despite her efforts to light her matches on New Year's Eve."