docker 本地部署大模型(ollama)

docker 安装 ollama

docker search ollama
docker pull ollama/ollama###docker下载ollama部署
docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama### 下载模型
docker exec -it ollama ollama pull llama3### 交互式运行模型docker exec -it ollama ollama run llama3

注意有坑:docker -v ollama:/root/.ollama
此处由于挂载目录使用了相对路径,所以本地文件夹位于 /var/lib/docker/volumes/ollama
而非运行命令的相对路径

测试 api

$ curl http://localhost:14444/api/generate -d '{ "model": "llama3", "prompt": "請列出五樣台灣美食", "stream": true, "options": { "seed": 123, "top_k": 20, "top_p": 0.9, "temperature": 0 } }'
{"model":"llama3","created_at":"2024-07-08T03:49:16.611142384Z","response":"Here","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:16.758150085Z","response":" are","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:16.903960154Z","response":" ","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:17.048831268Z","response":"5","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:17.192653835Z","response":" must","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:17.340323632Z","response":"-","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:17.490090786Z","response":"try","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:17.630377981Z","response":" Taiwanese","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:17.79671948Z","response":" dishes","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:17.947959672Z","response":":\n\n","done":false}
.......
{"model":"llama3","created_at":"2024-07-08T03:49:51.670524112Z","response":" dishes","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:51.80466663Z","response":" showcase","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:51.953821627Z","response":" the","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:52.112141942Z","response":" diversity","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:52.274051058Z","response":" and","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:52.41761068Z","response":" richness","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:52.571736412Z","response":" of","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:52.719734804Z","response":" Taiwanese","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:52.857012216Z","response":" cuisine","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:52.998817903Z","response":",","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:53.166612385Z","response":" which","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:53.342996684Z","response":" often","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:53.510572997Z","response":" combines","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:53.668246714Z","response":" Chinese","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:53.836925764Z","response":",","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:53.986648055Z","response":" Japanese","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:54.13517455Z","response":",","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:54.283114108Z","response":" and","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:54.443445171Z","response":" indigenous","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:54.603118958Z","response":" influences","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:54.76832015Z","response":".","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:54.931017326Z","response":" Enjoy","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:55.083288072Z","response":"!","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:55.533841685Z","response":" 🍴","done":false}
{"model":"llama3","created_at":"2024-07-08T03:49:55.671222985Z","response":"","done":true,"done_reason":"stop","context":[128006,882,128007,271,109311,32218,20834,76208,112595,117342,58666,102456,128009,128006,78191,128007,271,8586,527,220,20,2011,12,1568,94037,26863,1473,16,13,3146,3513,830,452,31707,61434,1754,96618,362,11670,94037,12269,11,25309,46895,273,19724,374,264,82651,323,94631,45993,1903,449,6435,23283,11059,25309,11,61260,11,323,24822,627,17,13,3146,46,22604,507,2727,1169,1754,96618,362,5526,8761,3691,304,29389,11,297,22604,297,2727,10145,527,73624,41951,19335,10409,449,628,1538,297,100163,11,70181,11,323,6307,45697,13,328,2841,449,264,10437,323,94760,19737,627,18,13,3146,626,39134,350,1073,84,1754,96618,49386,369,1202,281,2234,306,22843,11,357,39134,80247,374,264,96080,29839,17937,2027,430,596,5655,2269,4588,311,39143,13,1102,596,3629,10434,449,264,86921,19737,323,649,387,5115,57407,4999,19,13,3146,33,93613,85034,97685,1754,96618,362,69130,323,9257,12269,11,20716,4147,36167,36517,374,6435,23283,11059,304,264,21655,315,29839,19737,11,13465,11,323,49659,3156,279,13339,374,28682,323,17503,10980,6847,627,20,13,3146,38,4381,426,3524,1754,96618,7429,3967,439,94037,63452,11,1709,64,103253,527,4179,3690,293,11099,10409,449,20716,4147,36167,11,3820,839,24822,11,323,42393,13,362,18406,323,37154,40459,477,15496,382,9673,26863,35883,279,20057,323,90030,315,94037,36105,11,902,3629,33511,8620,11,11002,11,323,39678,34453,13,23485,0,11410,235,112,128009],"total_duration":43461066356,"load_duration":3482212558,"prompt_eval_count":17,"prompt_eval_duration":916597000,"eval_count":260,"eval_duration":39060126000}

python + ollama

from ollama import Client 
client = Client(host=f'http://{IP_ADDRESS}:14444') 
response = client.chat(model='llama3', messages=[ { 'role': 'user', 'content': 'Why is the sky blue?', }, ])
response 
{'model': 'llama3','created_at': '2024-07-08T04:05:41.013483539Z','message': {'role': 'assistant','content': "The sky appears blue because of a phenomenon called Rayleigh scattering, which is named after the British physicist Lord Rayleigh. Here's what happens:\n\n1. **Sunlight**: When sunlight enters Earth's atmosphere, it contains all the colors of the visible spectrum (red, orange, yellow, green, blue, indigo, and violet).\n2. **Molecules**: The atmosphere is made up of tiny molecules of gases like nitrogen (N2) and oxygen (O2). These molecules are much smaller than the wavelength of light.\n3. **Scattering**: When sunlight hits these small molecules, it scatters in all directions. This scattering effect is more pronounced for shorter wavelengths, like blue and violet light, which have a higher frequency than longer wavelengths, like red and orange light.\n4. **Blue dominance**: As a result of this scattering, the blue light with its shorter wavelength is dispersed throughout the atmosphere, reaching our eyes from all parts of the sky. This is why the sky appears blue during the daytime, especially when the sun is overhead.\n\nThe same principle applies to other colors, but with different intensities:\n\n* **Red and orange**: These longer wavelengths are less affected by scattering and reach our eyes more directly, which is why we see them as dominant at sunrise and sunset.\n* **Green and yellow**: These wavelengths are scattered similarly to blue light, but their intensity decreases with distance from the sun, making them less visible in the sky.\n\nSo, to summarize: the sky appears blue because of the scattering of sunlight by tiny molecules in the atmosphere, which favors shorter wavelengths like blue and violet."},'done_reason': 'stop','done': True,'total_duration': 52984861518,'load_duration': 3257720984,'prompt_eval_count': 15,'prompt_eval_duration': 829317000,'eval_count': 325,'eval_duration': 4888172200

流式输出

import ollamastream = client.chat(model='llama3',messages=[{'role': 'user', 'content': 'Why is the sky blue?'}],stream=True,
)for chunk in stream:print(chunk['message']['content'], end='', flush=True)

在这里插入图片描述

参考

  • https://github.com/ollama/ollama-python/tree/main/

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.xdnf.cn/news/1475129.html

如若内容造成侵权/违法违规/事实不符,请联系一条长河网进行投诉反馈,一经查实,立即删除!

相关文章

Python采集京东标题,店铺,销量,价格,SKU,评论,图片

京东的许多数据是通过 JavaScript 动态加载的,包括销量、价格、评论和评论时间等信息。我们无法仅通过传统的静态网页爬取方法获取到这些数据。需要使用到如 Selenium 或 Pyppeteer 等能够模拟浏览器行为的工具。 另外,京东的评论系统是独立的一个系统&a…

SCI一区TOP|准随机分形搜索算法(QRFS)原理及实现【免费获取Matlab代码】

目录 1.背景2.算法原理2.1算法思想2.2算法过程 3.结果展示4.参考文献5.代码获取 1.背景 2024年,LA Beltran受到分形几何、低差异序列启发,提出了准随机分形搜索算法(Quasi-random Fractal Search, QRFS)。 2.算法原理 2.1算法思…

本地图片压缩工具

一、简介 1、一款免费的本地图片压缩工具,支持多种图片格式并且没有体积限制,支持批量压缩。本地运行的方式保护了图片的隐私。它兼容 JPG、PNG、GIF、SVG 等多种格式,并允许用户设置压缩强度、尺寸和输出格式 二、下载 1、文末有下载链接,不明白可以私聊我哈(麻烦咚咚咚,…

一.2.(4)放大电路静态工作点的稳定;

1.Rb对Q点及Au的影响 输入特性曲线:Rb减少,IBQ,UBEQ增大 输出特性曲线:ICQ增大,UCEQ减少 AUUO/Ui分子减少,分母增大,但由于分子带负号,所以|Au|减少 2.Rc对Q点及Au的影响 输入特性曲…

【TB作品】51单片机 Proteus仿真00016 乒乓球游戏机

课题任务 本课题任务 (联机乒乓球游戏)如下图所示: 同步显示 oo 8个LED ooooo oo ooooo 8个LED 单片机 单片机 按键 主机 从机 按键 设计题目:两机联机乒乓球游戏 图1课题任务示意图 具体说明: 共有两个单片机,每个单片机接8个LED和1 个按键,两个单片机使用串口连接。 (2)单片机…

UE C++ 多镜头设置缩放 平移

一.整体思路 首先需要在 想要控制的躯体Pawn上,生成不同相机对应的SpringArm组件。其次是在Controller上,拿到这个Pawn,并在其中设置输入响应,并定义响应事件。响应事件里有指向Pawn的指针,并把Pawn的缩放平移功能进行…

处理训练和验证数据集

📚博客主页:knighthood2001 ✨公众号:认知up吧 (目前正在带领大家一起提升认知,感兴趣可以来围观一下) 🎃知识星球:【认知up吧|成长|副业】介绍 ❤️如遇文章付费,可先看…

C++和Python蚂蚁搬食和蚊虫趋光性和浮标机群行为算法神经网络

🎯要点 🎯机器人群行为配置和C行为实现:🖊脚底机器人狭隘空间导航避让障碍物行为 | 🖊脚底机器人使用摄像头耦合共振,实现同步动作 | 🖊脚底机器群使用相机,计算彼此间“分子间势能…

Docker——简介、安装(Ubuntu22.04)

1、简介 Docker 是一个开源的容器化平台,旨在简化应用程序的开发、交付和运行。它通过将应用程序及其所有依赖项打包到一个称为容器的标准化单元中,使应用程序能够在任何环境中一致地运行。Docker 解决了“在我的机器上能运行”的问题,使开发…

8、开发与大模型对话的独立语音设备

一、设计原理 该系统的核心部分主要由ESP32-WROVER开发板和ESP32-CAM摄像头、MAX9814麦克风放大器模块、MAX98357功放、声音传感器和SU-03T语音识别芯片构成。通过使用ESP32-WROVER开发板,用户可以实现通过语音与ai进行交互并进行人脸识别。 系统中,从外部输入电源中获取电源…

计算机网络-组播分发树与组播协议

一、组播分发树 前面我们大致了解了下组播的转发原理,通过RPF反向路径检查可以形成无环的组播转发路径,今天继续学习下组播分发树和组播协议。 组播数据转发需要保证转发路径无环,无次优路径且无重复包。通过RPF机制与组播路由协议&#xff0…

王老师 linux c++ 通信架构 笔记(一)

(0)本门课程会涉及很多知识。在此集中记录,做笔记,也可能加入别的专栏。 (1) vmware 15 的下载和密钥上网查找。 ubuntu - 16 - 04 的版本才 800 M ,来 csdn 找镜像 下载。 (2&#…

React Native 和 Flutter 的开发对比

React Native (RN) 和 Flutter 都是用于构建跨平台移动应用程序的流行框架。两者都具有各自的优势和劣势,选择哪个框架取决于您的具体需求和项目。北京木奇移动技术有限公司,专业的软件外包开发公司,欢迎交流合作。 以下是一些 RN 和 Flutter…

1012-27SF 同轴连接器

型号简介 1012-27SF是Southwest Microwave的2.92 mm连接器。该连接器使用不锈钢合金外壳和镀金接触表面提供了良好的耐腐蚀性和耐磨损性,延长了连接器的使用寿命。适用于高频应用,最高可达 40 GHz,使其适用于微波和射频通信、雷达系统等领域。…

VMware Workstation桥接模式无法上网

问题背景 我之前创建过一个虚拟机,当时虚拟机的网络模式使用的是桥接模式,配置好了固定ip地址,是可以正常上网的,中间没有做任何网络上面的配置。但是今天再打开这台虚拟机时,发现竟然不能上网了。 物理主机的ip信息配…

【掌握C++ string 类】——【高效字符串操作】的【现代编程艺术】

专栏&#xff1a;C学习笔记 上一篇&#xff1a;【C】——【 STL简介】——【详细讲解】 1. 为什么要学习 string 类&#xff1f; 1.1 C 语言中的字符串 在 C 语言中&#xff0c;字符串是以 \0 结尾的字符集合。如下所示&#xff1a; #include <stdio.h>int main() {c…

AI产品经理必懂的13种技术

AI产品经理和互联网产品经理一样&#xff0c;也会面临要不要懂技术&#xff0c;懂什么技术&#xff0c;到什么程度的问题&#xff0c;本章针对这一常见问题给出了解答。 AI产品经理一定要懂技术&#xff0c;懂技术重点是要懂产品方案包含的AI算法、数据、算力及硬件的相关技术…

nftables(2)表、链、规则查询和管理(新增、插入、修改、删除)

简介 在上篇文章中&#xff0c;我们介绍了nftables基本原理以及与iptables的区别&#xff0c;nftables安装和配置保存的操作。这篇文章主要介绍nftables的基本操作&#xff0c;表、链、规则的新增、插入、修改、删除等操作。 注意&#xff1a;在进行nftables实验时和iptables…

AI自动生成PPT怎么用?看完这篇文章你就知道啦

小暑&#xff0c;作为夏季的第五个节气&#xff0c;标志着炎炎夏日的正式到来。在这个时节&#xff0c;阳光明媚&#xff0c;万物生长&#xff0c;人们的心情也随着气温的升高而变得热烈。 然而&#xff0c;对于许多职场人士来说&#xff0c;小暑的到来也意味着需要准备各种汇报…

spark shuffle写操作——SortShuffleWriter

写入的简单流程&#xff1a; 1.生成ExternalSorter对象 2.将消息都是插入ExternalSorter对象中 3.获取到mapOutputWriter&#xff0c;将中间产生的临时文件合并到一个临时文件 4.生成最后的data文件和index文件 可以看到写入的重点类是ExternalSorter对象 ExternalSorter 基…