open-webui 聊天应用

导出镜像

# 安装一个底层工具
yum install skopeo -y
# 拉取指定平台amd64或arm64的镜像
skopeo copy --override-os linux --override-arch amd64 \
docker://ghcr.io/open-webui/open-webui:0.8.10 \
docker-archive:open-webui-0.8.10_amd64.tar:ghcr.io/open-webui/open-webui:0.8.10
# 二次压缩
gzip open-webui-0.8.10_amd64.tar
# 本地加载docker镜像
docker load -i open-webui-0.8.10_amd64.tar.gz

docker-compose.yml

  • 预备目录:mkdir -p /www/open-webui/data/open-webui
services:
  open-webui:
    image: ghcr.io/open-webui/open-webui:0.8.12  # github源根本拉不动
    container_name: open-webui
    environment:
	
      # --- 基础与 API 设置 ---
      - TZ=Asia/Shanghai
      - WEBUI_AUTH=True
      - WEBUI_SECRET_KEY=kaicong # session加盐
      # - OPENAI_API_BASE_URL=http://192.168.1.120:1234/v1
      # - OPENAI_API_KEY=sk-lm-G69sckC7
	  - USE_OLLAMA_DOCKER=False
      - ENABLE_OLLAMA_API=False
	  
      # --- 联网搜索 ---
      - ENABLE_RAG_WEB_SEARCH=True
      - RAG_WEB_SEARCH_ENGINE=searxng
      - SEARXNG_QUERY_URL=http://searxng:8080/search?q=<query>
      - RAG_WEB_SEARCH_RESULT_COUNT=3
	  
      # --- 语音与 RAG 本地化设置 ---
      # - HF_ENDPOINT=https://hf-mirror.com
      - HF_HUB_OFFLINE=1 # 强制读取本地映射的模型
      - OFFLINE_MODE=True # 保留联网
	  
      # --- 语音识别  ---
      - STT_ENGINE=whisper
      - WHISPER_MODEL=base
      - WHISPER_MODEL_DIR=/root/.cache/huggingface 	# 容器内寻找模型的根目录
	  - WHISPER_LANGUAGE=zh # 消除迟疑, 直接约定中文语境
	  
      # --- RAG & Embedding ---	
      - RAG_EMBEDDING_MODEL=BAAI/bge-small-zh-v1.5
      - SENTENCE_TRANSFORMERS_HOME=/root/.cache/huggingface
      - RAG_TOP_K=5
	  
    volumes:
      - ./data/open-webui:/app/backend/data
      - ./data/hf_cache:/root/.cache/huggingface # 关键:映射模型缓存目录
      - /etc/localtime:/etc/localtime:ro
    networks:
      - ghost_net
    restart: unless-stopped

networks:
  ghost_net:
    external: true  # 声明使用已存在的外部网络

语音和Rag小模型本地化

# 1. 安装工具: huggingface_hub 1.8.0(新版),CLI 已改名 hf
sudo dnf install python3-pip -y
pip3 install -U huggingface_hub

# 2. 设置国内镜像加速(Oracle 连海外通常快,但用镜像更稳)
# export HF_ENDPOINT=https://hf-mirror.com

# 3. 一键下载整个模型文件夹到指定目录
# RAG 嵌入模型(bge-small-zh-v1.5)
hf download BAAI/bge-small-zh-v1.5 --local-dir /www/open-webui/data/hf_cache/bge-small-zh-v1.5
# 语音识别模型(whisper-base)
hf download openai/whisper-base --local-dir /www/open-webui/data/hf_cache/models-openai-whisper-base

# OpenWebUI 优先加载 safetensors,你可以删除其他框架的权重文件
cd /www/open-webui/data/hf_cache/models-openai-whisper-base;rm flax_model.msgpack tf_model.h5 pytorch_model.bin
cd /www/open-webui/data/hf_cache/bge-small-zh-v1.5;rm pytorch_model.bin

conf.d/open-webui.conf

server {
    listen 80;
    server_name chat.atibm.com;

    # 强制跳转 HTTPS
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name chat.atibm.com ;

    # ==================== SSL 证书配置 ====================
    ssl_certificate     /etc/letsencrypt/live/ghost.atibm.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/ghost.atibm.com/privkey.pem;

    # SSL 安全优化(标准配置)
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on;

    # ==================== 日志 ====================
    access_log  /var/log/nginx/chat-access.log main;
    error_log   /var/log/nginx/chat-error.log;

    # 上传文件大小限制
    client_max_body_size 100M;

    location / {
        proxy_pass http://open-webui:8080;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        # WebSocket + 流式输出
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        proxy_cache off;
        proxy_buffering off;
        proxy_read_timeout 300s;
    }
}

后续管理

  • 添加用户
  • 模型权限设为全员可用
  • 添加更多的openai,以及模型前缀便于识别不同来源
  • yml配置里 模型市场访问开关和仅限本地模型开关