目标:Ubuntu安装Ollama(大模型qwen qwen:7b gemma:7b等),m3e处理,
通过one-api暴露为openapi格式,
供给FastGPT做问答和知识库
============================================================
参考微信:【完全私有的AI知识库,ChatGLM3无GPU也能跑】Docker一键部署,oneapi快速嵌入AI应用
https://mp.weixin.qq.com/s/IX_TuRvnDc62LW4cuY7Yhw
============================================================
安装Ollama
curl -fsSL https://ollama.com/install.sh | sh
>>> Downloading ollama...
如果走远程proxy,需要20分钟不到时间
root@u2204:~# curl -fsSL https://ollama.com/install.sh | sh
>>> Downloading ollama...
######################################################################## 100.0%-#O#- # #
>>> Installing ollama to /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.
>>> NVIDIA GPU installed.
问题:安装很慢,一个小时?怎么办
答案:用魔法,小几分钟内
vi /etc/hosts
192.168.1.235 myproxy
vi .bashrc
export HTTP_PROXY=http://myproxy:8086
export HTTPS_PROXY=http://myproxy:8086
export http_proxy=http://myproxy:8086
export https_proxy=http://myproxy:8086
问题:curl: (22) The requested URL returned error: 500
服务器有时候这样,正常
ollama run qwen
下面的指令,可以ssh退出后,ollama还在运行
apt install screen
screen ollama run qwen &
http://192.168.1.235:11434/
显示 Ollama is running
============================================================
手搓one-api,里面支持 qwen/m3e
apt install docker -y
apt install docker.io -y
docker stop open-webui
docker rm open-webui
rm -rf /data/open-webui/
本地Ollama IP地址 192.168.1.235
docker run -d \
-p 11433:8080 \
--add-host=host.docker.internal:host-gateway \
-v /data/open-webui:/app/backend/data --name open-webui \
-e WEBUI_SECRET_KEY=123456 \
-e OLLAMA_API_BASE_URL=http://127.0.0.1:11434/api \
-e HTTP_PROXY=http://myproxy:8086 \
-e HTTPS_PROXY=http://myproxy:8086 \
-e http_proxy=http://myproxy:8086 \
-e https_proxy=http://myproxy:8086 \
--restart always ghcr.io/ollama-webui/ollama-webui:main
登录测试:
http://192.168.1.235:11434/
注册一个账号进去 作者:小杨生存日记 https://www.bilibili.com/read/cv32462618/ 出处:bilibili
1088133@qq.com
Passw0rd
Ollama Version: Not Detected
Ollama WebUI: Server Connection Error
systemctl disable ufw
systemctl stop ufw
问题:日志怎么看
docker logs open-webui
root@u22:/data# docker logs open-webui
INFO: Started server process [1]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8080 (Press CTRL+C to quit)
问题:
http://192.168.1.235:11434/
不能访问
ollama 缺省只能用http://127.0.0.1:11434来访问
https://github.com/ollama/ollama/blob/main/docs/faq.md#how-do-i-configure-ollama-server
解决办法:
让ollama 服务 外网可以访问
systemctl edit ollama.service
[Service]
Environment="OLLAMA_HOST=0.0.0.0"
mkdir /etc/systemd/system/ollama.service.d/
root@u2204:~# vi /etc/systemd/system/ollama.service.d/override.conf
systemctl daemon-reload
systemctl restart ollama
问题:如果不有魔法会提示, 不能从浏览器访问
OSError: We couldn't connect to 'https://huggingface.co' to load this file, couldn't find it in the cached files and it looks like sentence-transformers/all-MiniLM-L6-v2 is not the path to a directory containing a file named config.json.
Checkout your internet connection or see how to run the library in offline mode at 'https://huggingface.co/docs/transformers/installation#offline-mode'
如果有魔法, 选不了model
log提示
Cannot connect to host host.docker.internal:11434 ssl:default [Name or service not known]
那么加个参数
--add-host=host.docker.internal:host-gateway \
可能需要修改 修改 /etc/hosts
192.168.1.232 host.docker.internal
可能需要修改 魔法服务器的hosts文件 也加入上面一行
问题:docker日志错误:
/ollama/api/chat
http://host.docker.internal:11434
b'{"model":"qwen:7b","messages":[{"role":"user","content":"hello"},{"role":"assistant","content":""}],"options":{},"stream":true}'
HTTPConnectionPool(host='myproxy', port=8086): Max retries exceeded with url: http://host.docker.internal:11434/api/chat (Caused by ProxyError('Cannot connect to proxy.', RemoteDisconnected('Remote end closed connection without response')))
INFO: 192.168.1.202:17722 - "POST /ollama/api/chat HTTP/1.1" 500 Internal Server Error
http://host.docker.internal:11434
INFO: 192.168.1.202:17722 - "POST /ollama/api/generate HTTP/1.1" 500 Internal Server Error
问题:第一次run需要设置proxy,否则启动不了;
然后遗留 后面呢又访问修改不了 ollama的地址
============================================================
============================================================
部署one-api
因为后续FastGPT默认为3000端口,这里我们使用3001端口部署。启动完成后使用该端口即可访问。
docker stop one-api
docker pull justsong/one-api:latest
docker rm one-api
rm -rf /data/one-api
docker run --name one-api -d --restart always -p 3001:3000 -e TZ=Asia/Shanghai -v /data/one-api:/data justsong/one-api:latest
http://192.168.1.235:3001/
root/123456
密码登录后就让修改,我修改密码为Passw0rd
============================================================
部署 m3e运行环境 m3e-large-api
需要魔法才能快速部署,下半夜运行
apt install lsof
lsof -i:6008
docker pull registry.cn-hangzhou.aliyuncs.com/fastgpt_docker/m3e-large-api
docker run -d --restart always --name m3e -p 6008:6008 registry.cn-hangzhou.aliyuncs.com/fastgpt_docker/m3e-large-api
http://192.168.1.235:6008/
显示 {"detail":"Not Found"}
https://mp.weixin.qq.com/s/p4c9vzvEGAGOMnksFmQ4IA
=============================================================
错误:one-api中配置 m3e,测试不通过
docker logs m3e 提示 POST /v1/chat/completions HTTP/1.1" 404 Not Found
解答:正常
但由于不是对话生成模型(/v1/chat/completions)所以会 404。
参考:
https://zhuanlan.zhihu.com/p/668867210
=============================================================
部署 fastgpt 用3000
参考:
https://www.xmeta.cn/news/96569.html
mkdir fastgpt
cd fastgpt
wget http://raw.githubusercontent.com/labring/FastGPT/main/files/deploy/fastgpt/docker-compose.yml
wget https://raw.githubusercontent.com/labring/FastGPT/main/projects/app/data/config.json
按照这个文档 修改 两个配置文件
openssl rand -base64 756 > ./mongodb.key
chmod 600 ./mongodb.key
chown 999:root ./mongodb.key
docker-compose pull
docker-compose up -d
docker stop fastgpt
docker rm fastgpt
docker stop mongo
docker stop pg
docker rm mongo
docker rm pg
rm -rf pg/
rm -rf mongo/data/
docker-compose up -d
问题:mongo启动报错
mongo | {"t":{"$date":"2024-03-15T21:03:56.726+00:00"},"s":"I", "c":"-", "id":4939300, "ctx":"monitoring-keys-for-HMAC","msg":
"Failed to refresh key cache","attr":{"error":"NotYetInitialized: Cannot use non-local read concern until replica set is finished initializing.","nextWakeupMillis":1400}}
解决办法:
docker exec -it mongo bash
mongo --host 127.0.0.1 27017
use admin
db.auth('myusername','mypassword')
rs.initiate({
_id: "rs0", // 这应与配置文件中的replSetName相同
members: [
{ _id: 0, host: "192.168.1.235:27017" }
]
})
http://192.168.1.235:3000/
登录fastgpt,用户名root,密码1234
错误:
登录提示Operation `users.findOne()` buffering timed out after 10000ms
解决:下面的IP地址不对
rs.initiate({
_id: "rs0", // 这应与配置文件中的replSetName相同
members: [
{ _id: 0, host: "192.168.1.235:27017" }
]
})
错误:
登录提示 用户为注册
解决:重新启动docker mongo
docker restart mongo
=============================================================
现在是6个 docker
3 one-api 里面目前配置 ollama,测试可以过
但是配置 open-webui,提示 405/401
4 FastGPT中AI的下来列表为空
正常应该至少有四个
gpt-3.5-turbo
gpt-3.5-turbo-16k
gpt-4-turbo
gpt-4-vision
按照下面的做法修改config.json文件
https://zhuanlan.zhihu.com/p/668861152
11434: ollama API
11433: one-api API
fastgpt 配置 11433报错 405 status code (no body)
fastgpt 配置 11434 成功了~~~
树上有3只鸟,开了一枪,还有几只鸟
=============================================================
https://ollama.com/search?q=nomic&p=1
ollama run nomic-embed-text