指尖上的记忆指尖上的记忆
首页
  • 基础
  • Laravel框架
  • Symfony框架
  • 基础
  • Gin框架
  • 基础
  • Spring框架
  • 命令
  • Nginx
  • Ai
  • Deploy
  • Docker
  • K8s
  • Micro
  • RabbitMQ
  • Mysql
  • PostgreSsql
  • Redis
  • MongoDb
  • Html
  • Js
  • 前端
  • 后端
  • Git
  • 知识扫盲
  • Golang
🌟 gitHub
首页
  • 基础
  • Laravel框架
  • Symfony框架
  • 基础
  • Gin框架
  • 基础
  • Spring框架
  • 命令
  • Nginx
  • Ai
  • Deploy
  • Docker
  • K8s
  • Micro
  • RabbitMQ
  • Mysql
  • PostgreSsql
  • Redis
  • MongoDb
  • Html
  • Js
  • 前端
  • 后端
  • Git
  • 知识扫盲
  • Golang
🌟 gitHub

ollama本地初次尝试使用:

  • 安装
$ curl -fsSL https://ollama.com/install.sh | sh
>>> Installing ollama to /usr/local
>>> Downloading Linux amd64 CLI
######################################################################## 100.0%##O=#  #                                                                      
>>> Making ollama accessible in the PATH in /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 --version
ollama version is 0.3.6
  • 访问服务
可以通过如下访问本地ollama服务:
http://127.0.0.1:11434/
  • 修改service文件,在环境变量后添加 "OLLAMA_HOST=0.0.0.0", 这样便于后续在容器中运行的OpenWebUI可以访问到Ollama API服务
$ sudo vim /etc/systemd/system/ollama.service
[Unit]
Description=Ollama Service
After=network-online.target
  
[Service]
ExecStart=/usr/local/bin/ollama serve
User=ollama
Group=ollama
Restart=always
RestartSec=3
Environment="PATH=.:/usr/local/jdk-17/jdk-17.0.7/bin:/usr/local/jdk-17/jdk-17.0.7/lib:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/usr/local/go/bin:/home/guoshipeng/Documents/go/bin" "OLLAMA_HOST=0.0.0.0"
  
[Install]
WantedBy=default.target
修改后执行:
systemctl daemon-reload
systemctl restart ollama
  • ollama 相关命令
$ ollama --help
Large language model runner
  
Usage:
  ollama [flags]
  ollama [command]
  
Available Commands:
  serve       Start ollama
  create      Create a model from a Modelfile
  show        Show information for a model
  run         Run a model
  pull        Pull a model from a registry
  push        Push a model to a registry
  list        List models
  ps          List running models
  cp          Copy a model
  rm          Remove a model
  help        Help about any command
  
Flags:
  -h, --help      help for ollama
  -v, --version   Show version information
  
Use "ollama [command] --help" for more information about a command.
  • ollama 模型库
ollama模型库:https://ollama.com/library
  • 使用 ollama 跑一个模型
$ ollama run qwen2:1.5b
  • ollama 列出本地易安装模型
ollama list //用于列出本地安传的model
NAME      	ID          	SIZE  	MODIFIED          
qwen2:1.5b	f6daf2b25194	934 MB	About an hour ago
  • ollama api使用文档
https://github.com/ollama/ollama/blob/main/docs/api.md //非常详细的介绍了api的使用,包含各种操作,增删改查都有
其中这个:
Send a chat message with a conversation history. You can use this same approach to start the conversation using multi-shot or chain-of-thought prompting.
curl http://localhost:11434/api/chat -d '{
  "model": "llama3",
  "messages": [
    {
      "role": "user",
      "content": "why is the sky blue?"
    },
    {
      "role": "assistant",
      "content": "due to rayleigh scattering."
    },
    {
      "role": "user",
      "content": "how is that different than mie scattering?"
    }
  ]
}'
  
这个主要是把chat的上下文再每次chat的时候一起传递给接口,用于创建语境,我打算用另一种方式实现,到时候新开一篇
  • 本地docker部署open-webui
$ docker run -d -p 3000:8080 --add-host=host.docker.internal:host-gateway -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:main
^[[CUnable to find image 'ghcr.io/open-webui/open-webui:main' locally
main: Pulling from open-webui/open-webui
e4fff0779e6d: Already exists 
d97016d0706d: Pull complete 
53db1713e5d9: Pull complete 
a8cd795d9ccb: Pull complete 
de3ba92de392: Pull complete 
6f4d87c224b0: Pull complete 
4f4fb700ef54: Pull complete 
dd92a6022ddb: Pull complete 
bbbfed48a772: Pull complete 
a825beebdb5b: Pull complete 
638c7f4708d7: Pull complete 
dcd98ca2af09: Pull complete 
a3a183a1eb40: Pull complete 
a3b19b039cc9: Pull complete 
f86974dcccd6: Pull complete 
d026397a4a16: Pull complete 
Digest: sha256:d05b69e71c8011d3031c159aff1ed4942d3c0d98d1c531ae267962bcdcb603a6
Status: Downloaded newer image for ghcr.io/open-webui/open-webui:main
25c7f24d49b7b4de3d1924e6c36354d5895fcefbd47e5b8889636a2fe2f9bf9e
  
然后可以通过 http://localhost:3000/ 访问open-webui,首次需要注册账号,然后可以选择本地已经安装的模型进行对话,我发现通过这个webui可以实现上下文对话,但是直接通过之前提到的API确不行,不知道为什么,后来发现是因为每次把之前的chat记录一起发给后台了,我想这个对于普通服务器来说,压力还是很大的,因为有很多数据需要处理和存储。
  
总结一下:
首先,想玩大模型,不管他天花乱坠整各种黑话什么Agent、ChatBot,其实我们要看的核心组件无非就是两个:训练好的大模型,以及UI界面。于是就有各种开源大佬在这两方面下手了。大模型的收集和调用方面,由ollama提供支持(ollama一键在本地运行大模型,被运行的模型可以像API一样被调用),而UI界面方面,则有open-webui、lobe-chat等。本次主要关注ollama和open-webui。