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.pswp.cn/web/41818.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/41818.shtml
英文地址,請注明出處:http://en.pswp.cn/web/41818.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

ECharts 最小高度設置指南

下面提供一份關于ECharts中設置最小高度的專業而詳細的文檔。這份文檔將涵蓋不同圖表類型的最小高度設置方法,適合初學者學習和參考。 ECharts 最小高度設置指南 1. 通用屬性 對于大多數圖表類型,可以使用以下通用屬性來控制最小高度: 1.…

算法 —— 二分查找

目錄 二分查找 在排序數組中查找元素的第一個和最后一個位置 搜索插入位置 x的平方根 山峰數組的峰頂索引 尋找峰值 搜索旋轉排序數組中的最?值 點名 二分查找模板分為三種:1、樸素的二分模板 2、查找左邊界的二分模板 3、查找右邊界的二分模板&#xf…

【基于R語言群體遺傳學】-12-超顯性與次顯性

歡迎先看前面的博客,再繼續進行后面的內容: 群體遺傳學_tRNA做科研的博客-CSDN博客 當雜合子的適應度超出純合子的范圍時,二倍體能夠展現出更多令人著迷的選擇實例。這種形式的一種是雜合子優勢,或稱為“超顯性”,其…

【包郵送書】AIGC時代程序員的躍遷——編程高手的密碼武器

歡迎關注博主 Mindtechnist 或加入【智能科技社區】一起學習和分享Linux、C、C、Python、Matlab,機器人運動控制、多機器人協作,智能優化算法,濾波估計、多傳感器信息融合,機器學習,人工智能等相關領域的知識和技術。關…

深入了解 Huber 損失函數

深入了解 Huber 損失函數 在機器學習和深度學習的訓練過程中,選擇合適的損失函數對于模型性能的提升至關重要。MSE(均方誤差) 和 RMSE(均方根誤差) 是我們常見的回歸損失函數。然而,當數據中存在異常值&am…

無線麥克風哪個品牌音質最好,揭秘手機收音麥克風哪個牌子好!

隨著全球直播和短視頻行業的蓬勃發展,領夾麥克風因其便攜性和出色的錄音質量而備受青睞。用戶在各種場合下追求清晰、真實的錄音效果,領夾麥克風無疑是一個理想的選擇。 然而,面對市場上琳瑯滿目的品牌和型號,想要挑選一款性能優…

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…

HTML標簽類型全面介紹

HTML標簽類型全面介紹 HTML(HyperText Markup Language)是構建網頁的基礎語言,它通過一系列的標簽(Tags)來定義網頁的結構和內容。HTML標簽根據其功能和用途可以分為多個類型,每個類型都扮演著不同的角色。…

「數據結構詳解·十四」對頂堆

「數據結構詳解一」樹的初步「數據結構詳解二」二叉樹的初步「數據結構詳解三」棧「數據結構詳解四」隊列「數據結構詳解五」鏈表「數據結構詳解六」哈希表「數據結構詳解七」并查集的初步「數據結構詳解八」帶權并查集 & 擴展域并查集「數據結構詳解九」圖的初步「數據結構…

【計算機畢業設計】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…

PLSQL Day3

--7.鍵盤輸入1-10之間的任意一個數字,輸出這個數字的階乘: [3!1*2*3] [5!1*2*3*4*5] declare n number : &輸入一個數字; s number : 1; begin if n between 1 and 10 then for i in 1..n loop s : i*s; end loop; dbms…

程序人生【追光的日子】今天我們不談技術,談一談:人工智能的意義到底是什么?來看看今天分享的故事...我想我們都愿意相信,也許AI真的會有溫度,這一天不遠了~!

有志者,事竟成,破釜沉舟,百二秦關終屬楚;苦心人,天不負,臥薪嘗膽,三千越甲可吞吳。 ??作者主頁: 追光者♂?? ??個人簡介: ??[1] 計算機專業碩士研究生?? ??[2] 2023年城市之星領跑者TOP1(哈爾濱)?? ??[3] 2022年度博客之星人工智能領域…

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

Java SpringBoot MongoPlus 使用MyBatisPlus的方式,優雅的操作MongoDB 介紹特性安裝新建SpringBoot工程引入依賴配置文件 使用新建實體類創建Service測試類進行測試新增方法查詢方法 官方網站獲取本項目案例代碼 介紹 Mongo-Plus(簡稱 MP)是一…

網絡服務器配置與管理

網絡服務器配置與管理是一個涉及多個方面的領域,它涵蓋了從物理硬件的設置到操作系統、網絡服務和應用的配置,再到日常維護和安全策略的實施。以下是網絡服務器配置與管理的一些核心概念和步驟: 硬件配置: 選擇合適的服務器硬件&a…