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.mzph.cn/web/41818.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

算法 —— 二分查找

目录 二分查找 在排序数组中查找元素的第一个和最后一个位置 搜索插入位置 x的平方根 山峰数组的峰顶索引 寻找峰值 搜索旋转排序数组中的最⼩值 点名 二分查找模板分为三种:1、朴素的二分模板 2、查找左边界的二分模板 3、查找右边界的二分模板&#xf…

【基于R语言群体遗传学】-12-超显性与次显性

欢迎先看前面的博客,再继续进行后面的内容: 群体遗传学_tRNA做科研的博客-CSDN博客 当杂合子的适应度超出纯合子的范围时,二倍体能够展现出更多令人着迷的选择实例。这种形式的一种是杂合子优势,或称为“超显性”,其…

【包邮送书】AIGC时代程序员的跃迁——编程高手的密码武器

欢迎关注博主 Mindtechnist 或加入【智能科技社区】一起学习和分享Linux、C、C、Python、Matlab,机器人运动控制、多机器人协作,智能优化算法,滤波估计、多传感器信息融合,机器学习,人工智能等相关领域的知识和技术。关…

无线麦克风哪个品牌音质最好,揭秘手机收音麦克风哪个牌子好!

随着全球直播和短视频行业的蓬勃发展,领夹麦克风因其便携性和出色的录音质量而备受青睐。用户在各种场合下追求清晰、真实的录音效果,领夹麦克风无疑是一个理想的选择。 然而,面对市场上琳琅满目的品牌和型号,想要挑选一款性能优…

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

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

WAIC2024 上海 | Gooxi 全面展示智算新成果,加速人工智能落地应用

浦江之畔,大咖云集;智能浪潮,奔涌不息。7月4日,被誉为人工智能界风向标的世界人工智能大会暨人工智能全球治理高级别会议在上海盛大召开,Gooxi此次携最新AI服务器以及解决方案参与,以算为擎赋能新质生产力&…

如何对待信息技术课上学生玩游戏现象

对待信息技术课上学生玩游戏的现象,需要采取一系列综合措施,既要防止学生分心,又要确保课堂的教学质量和学生的积极参与。以下是一些建议: 1. 明确课堂规则:在课程开始之初,明确告知学生课堂上不允许玩游戏…

【UE Lua】 快速入门(基础语法、与UE引擎的交互)

目录 0 引言1 基础语法1.1 变量和数据类型1.2 注释1.3 控制结构1.4 函数1.5 表(Table)1.6 元表(Metatable)1.7 字符串操作1.8 模块和包1.9 错误处理 2 数据结构 - 表2.1 表(Table)2.2 元表(Meta…

「数据结构详解·十四」对顶堆

「数据结构详解一」树的初步「数据结构详解二」二叉树的初步「数据结构详解三」栈「数据结构详解四」队列「数据结构详解五」链表「数据结构详解六」哈希表「数据结构详解七」并查集的初步「数据结构详解八」带权并查集 & 扩展域并查集「数据结构详解九」图的初步「数据结构…

【计算机毕业设计】017基于微信小程序的学生公寓电费信息管理系统

🙊作者简介:拥有多年开发工作经验,分享技术代码帮助学生学习,独立完成自己的项目或者毕业设计。 代码可以私聊博主获取。🌹赠送计算机毕业设计600个选题excel文件,帮助大学选题。赠送开题报告模板&#xff…

多线程网络实战之仿qq群聊的服务器和客户端

目录 一、前言 二、设计需求 1.服务器需求 2.客户端需求 三、服务端设计 1.项目准备 2.初始化网络库 3.SOCKET创建服务器套接字 4. bind 绑定套接字 5. listen监听套接字 6. accept接受客户端连接 7.建立套接字数组 8. 建立多线程与客户端通信 9. 处理线程函数&…

【3GPP核心网】【5G】精讲5G核心网系统架构主要特征

目录 前言 1. 5G核心网系统架构主要特征 1.1 5G核心网与4G核心网EPC区别 1.2 5G核心网系统架构主要特征 2. 5G网络逻辑架构 2.1 新型基础设施平台 2.2 逻辑架构 前言 首先需要理解核心网的角色定位,作为移动通信网络的核心部分,核心网起着承上启下的作用…

【收藏】欧盟CE、美国FDA法规及标准查询常用网站

01 CE法规&标准查询网站 医疗器械主管部门的网站 网址: https://www.camd-europe.eu/ 简介: CAMD的全称是Competent authorities for medical devices,翻译成中文叫做医疗器械监管机构,实际上它指的是欧盟成员国医疗器械监管机构的联盟&#xff…

程序人生【追光的日子】今天我们不谈技术,谈一谈:人工智能的意义到底是什么?来看看今天分享的故事...我想我们都愿意相信,也许AI真的会有温度,这一天不远了~!

有志者,事竟成,破釜沉舟,百二秦关终属楚;苦心人,天不负,卧薪尝胆,三千越甲可吞吴。 🎯作者主页: 追光者♂🔥 🌸个人简介: 💖[1] 计算机专业硕士研究生💖 🌿[2] 2023年城市之星领跑者TOP1(哈尔滨)🌿 🌟[3] 2022年度博客之星人工智能领域…

Java SpringBoot MongoPlus 使用MyBatisPlus的方式,优雅的操作MongoDB

Java SpringBoot MongoPlus 使用MyBatisPlus的方式,优雅的操作MongoDB 介绍特性安装新建SpringBoot工程引入依赖配置文件 使用新建实体类创建Service测试类进行测试新增方法查询方法 官方网站获取本项目案例代码 介绍 Mongo-Plus(简称 MP)是一…

网络服务器配置与管理

网络服务器配置与管理是一个涉及多个方面的领域,它涵盖了从物理硬件的设置到操作系统、网络服务和应用的配置,再到日常维护和安全策略的实施。以下是网络服务器配置与管理的一些核心概念和步骤: 硬件配置: 选择合适的服务器硬件&a…

基于docker上安装elasticSearch7.12.1

部署elasticsearch 首先,先创建网络 # 创建网络 docker network create es-net拉取elasticSearch的镜像 #拉取镜像 docker pull elasticsearch:7.12.1创建挂载点目录 # 创建挂载点目录 mkdir -p /usr/local/es/data /usr/local/es/config /usr/local/es/plugin…

【SD教程】进阶篇图片复现AnimateDiff动画插件基础教程(附模型插件)

当你成功安装了SD(Stable Diffusion)后,是否也产生过这样的疑惑:为何我创作的图片与他人的作品在风格和质量上存在差异? 看着别人创作的精致、引人入胜的图片,你是否也渴望缩小这种质感上的差距&#xff1…

游戏AI的创造思路-技术基础-决策树(1)

决策树,是每个游戏人必须要掌握的游戏AI构建技术,难度小,速度快,结果直观,本篇将对决策树进行小小解读~~~~ 目录 1. 定义 2. 发展历史 3. 决策树的算法公式和函数 3.1. 信息增益(Information Gain&…

深度解析:STM32对接米家平台,打造WiFi智能插座(ESP8266、电流检测)

摘要: 智能插座作为智能家居的入门级设备,凭借其低成本、易部署等优势,受到了广大用户的青睐。本文将引领你从零开始,使用功能强大的STM32微控制器、广受欢迎的ESP8266 WiFi模块以及功能丰富的米家IoT平台,一步步打造出一款能够远…