網頁

顯示具有 open-webui 標籤的文章。 顯示所有文章
顯示具有 open-webui 標籤的文章。 顯示所有文章

2026年6月9日 星期二

Open-webui 歷史對話過多,卡死

Admin Panel/Settings/Models
點選 模型 的編輯
點開 Advanced Params
max_tokens: 4096
num_ctx (Ollama): 32768
按 Save & Update

2026年1月2日 星期五

將 open webui 的 http 轉成 https

產生證書,需先執行一個 nginx 在 80 port 上,以便 cerbot 產生證書
$ sta_nginx_certbot.sh
$ docker run --rm -it \
  -v $(pwd)/nginx/certs:/etc/letsencrypt \
  -v $(pwd)/nginx/acme:/var/www/certbot \
  certbot/certbot certonly \
  --webroot \
  -w /var/www/certbot \
  -d www.host.com.tw
證書產生在下列目錄
nginx/certs/live/www.host.com.tw/fullchain.pem
nginx/certs/live/www.host.com.tw/privkey.pem
停止 nginx_certbot

docker nginx 加入 nginx_certbot.conf, 以便在更新證書時,不用停止 nginx
server {
    listen 80 default_server;
    server_name _;

    root /var/www/html;
    index index.html index.htm index.nginx-debian.html;
    
    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }

    location / {
        return 200 "nginx certbot ok\n";
    }
}

更新證書
$ docker run --rm \
  -v $(pwd)/nginx/certs:/etc/letsencrypt \
  -v $(pwd)/nginx/acme:/var/www/certbot \
  certbot/certbot renew

測試證書
$ docker run --rm \
  -v $(pwd)/nginx/certs:/etc/letsencrypt \
  -v $(pwd)/nginx/acme:/var/www/certbot \
  certbot/certbot renew --dry-run


# 1. Nginx 是否在 webnet
docker network inspect webnet
# 2. open-webui 是否在 webnet
docker ps
# 3. Nginx 內部能否解析
docker exec -it nginx getent hosts open-webui
# 4. Nginx 內部直連測試
docker exec -it nginx curl http://open-webui:8080
# nginx.conf 修改後 nginx 重開
docker restart nginx
# 測試命令
curl -k -H "Cache-Control: no-cache" \
     -H "Pragma: no-cache" \
     https://www.host.com.tw/

為了避免一些 docker 沒有啟動,造成 nginx 無法啟動,將
    location /sub-path/ {
        proxy_pass http://sub-path:8001;
    }
改成
    location /sub-path/ {
        set $p8001 http://sub-path:8001;
        rewrite ^/sub-path/(.*)$ /$1 break;
        proxy_pass $p8001;
    }

open-webui 無法掛到 https://www.host.com.tw/open-webui 必須使用 /
    location / {
        set $webui http://open-webui:8080;
        # 無法使用 rewrite, 只能用 location /
        proxy_pass $webui;
        # 避免下列 WebSocket 錯誤
        # "GET /ws/socket.io/?EIO=4&transport=websocket HTTP/1.1" 400 46
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }

原先也要加入 dashboard, 但兩者同時都使用 WebSocket, 而且是 GET /ws 開頭,所以只好放棄
    location /dashboard/ {
        set $dashboard http://dashboard:8080;
        rewrite ^/dashboard/(.*)$ /$1 break;
        proxy_pass $dashboard;
        # 避免下列 WebSocket 錯誤
        # "GET /ws HTTP/1.1" 500 21
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }

2025年12月30日 星期二

DGX Spark 之 Open WebUI 配合 vLLM 或 TRT LLM

# ollama 連接 vllm 或 trt_llm
$ docker run -d --rm \
  --name open-webui-vllm \
  -p 8501:8080 \
  -v open-webui:/app/backend/data \
  -e OPENAI_API_BASE_URL=http://192.168.0.108:8000/v1 \
  -e OPENAI_API_KEY=token-abc123 \
  ghcr.io/open-webui/open-webui:main
其中 8080 為固定,不需改變
開啟 Open WebUI(http://localhost:8501)
登入後點選左下 使用者 → Admin Panel → Settings → Connections → OpenAI
你會看到已自動配置的 OpenAI 連線(指向 vLLM)

上述命令只可使用單一 vLLM 模型
改用下述命令,由網頁手動輸入多組 vLLM 模型
$ docker run -d --rm --gpus=all \
  -p 8501:8080 \
  -v open-webui:/app/backend/data \
  -v open-webui-ollama:/root/.ollama \
  --name open-webui ghcr.io/open-webui/open-webui:ollama
若啟動失敗,應該是 open-webui volume 不一致,使用下列命令
$ docker volume rm open-webui

網頁左下使用者名稱/Admin Panel/Settings/Connections/ +
URL: http://192.168.0.108:8000/v1
按 Save

2025年2月20日 星期四

open webui 使用網頁搜尋

https://developers.google.com/custom-search/v1/introduction?hl=zh-tw
點選 程式化搜尋引擎 (免費版) 使用者:取得金鑰

https://programmablesearchengine.google.com/controlpanel/all
點選 新增
輸入 搜尋引擎名稱
在 Paid Element API 金鑰 欄位,輸入之前取得的 金鑰
取得 搜尋引擎 ID

進入 open webui, 點選左下角使用者,選擇 設定
點選 管理員設定/網頁搜尋
開啟 啟用網頁搜尋
網頁搜尋引擎: google_pse
開啟 Full Context Mode
輸入 Google PSE API 金鑰
輸入 Google PSE 引擎 ID

網頁搜尋引擎: duckduckgo
可以直接使用

在 open webui 的傳送訊息欄位下方,可以點選 網頁搜尋

2025年2月19日 星期三

安裝 ollama open-webui nginx

參考 https://github.com/ollama/ollama
參考 https://hub.docker.com/r/ollama/ollama
參考 https://www.53ai.com/news/OpenSourceLLM/2024072585037.html

$ docker run -d --gpus=all -p 11434:11434 --name ollama \
  -v /mnt/Data/ollama/ollama_volume:/root/.ollama \
  ollama/ollama
$ docker exec -it ollama ollama run deepseek-r1
$ git clone https://github.com/ggerganov/llama.cpp.git
$ cd llama.cpp
$ cmake -B build
$ cmake --build build --config Release
$ pip install huggingface_hub

轉換 huggingface 上的 model, 成為 GGUF 格式
vi download.py 
from huggingface_hub import snapshot_download, login

login("hf_BqLATKBqbVzOWNBJcFMwHKzCJfu")

# 下载模型
snapshot_download(
    "taide/Llama-3.1-TAIDE-LX-8B-Chat",
    local_dir="taide_Llama-3.1-TAIDE-LX-8B-Chat",
    local_dir_use_symlinks=False,
    ignore_patterns=["*.gguf"]
)

$ vi convert_hf_to_gguf_update.py
在 models 中, 加入下行, 注意 TOKENIZER_TYPE 的選擇
    {"name": "taide_Llama-3.1-TAIDE-LX-8B-Chat", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/taide/Llama-3.1-TAIDE-LX-8B-Chat"},
    {"name": "yentinglin_Llama-3-Taiwan-8B-Instruct", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/yentinglin/Llama-3-Taiwan-8B-Instruct"},
$ python convert_hf_to_gguf_update.py hf_BqLATKBqbVzOWNBJcFMwHKzCJfu
$ python convert_hf_to_gguf.py taide_Llama-3.1-TAIDE-LX-8B-Chat --outtype f16 --outfile taide_Llama-3.1-TAIDE-LX-8B-Chat.fp16.gguf
$ llama.cpp/build/bin/llama-quantize taide_Llama-3.1-TAIDE-LX-8B-Chat.fp16.gguf Q4_K_M
$ mv ggml-model-Q4_K_M.gguf taide_Llama-3.1-TAIDE-LX-8B-Chat-Q4_K_M.gguf
$ vi Modelfile.taide-8b
FROM ./yentinglin_Llama-3-Taiwan-8B-Instruct.Q4_K_M.gguf
# set the temperature to 1 [higher is more creative, lower is more coherent]
PARAMETER temperature 1
# set the system message
SYSTEM """
我是一個萬事通
"""

$ docker exec -it ollama /bin/bash
# cd /root/.ollama
# ollama create taide-8b -f ./Modelfile.taide-8b
# ollama list
# ollama show taide-8b
# ollama rm taide-8b
# ollama ps
# ollama run taide-8b
>>> /bye
# OLLAMA_HOST=127.0.0.1:11434 ollama serve
$ curl http://localhost:11434/api/generate -d '{
  "model": "yentinglin-8b", 
  "prompt": "建議適合ai的程式語言"
}'
$ curl http://localhost:11434/api/generate -d '{
  "model": "yentinglin-8b", 
  "prompt": "建議適合ai的程式語言",
  "stream", false
}'
$ curl http://localhost:11434/api/chat -d '{
  "model": "yentinglin-8b", 
  "messages": [
    {"role": "user", "content": "建議適合ai的程式語言"}
  ]
}'
$ curl http://localhost:11434/v1/chat/completions \
    -H "Content-Type: application/json" \
    -d '{
        "model": "yentinglin-8b",
        "messages": [
            {
                "role": "system",
                "content": "你是一個萬事通"
            },
            {
                "role": "user",
                "content": "眼睛酸痛,怎麼辦?"
            }
        ]
    }'

$ docker logs ollama

$ python ../llama.cpp/convert_hf_to_gguf.py yentinglin_Llama-3-Taiwan-8B-Instruct --outtype f16 --outfile yentinglin_Llama-3-Taiwan-8B-Instruct.fp16.gguf
$ llama.cpp/build/bin/llama-quantize yentinglin_Llama-3-Taiwan-8B-Instruct.fp16.gguf Q4_K_M


建議適合ai的程式語言

$ docker run -d -p 3000:8080 --gpus all \
  --add-host=host.docker.internal:host-gateway \
  -v /mnt/Data/ollama/open-webui_volume:/app/backend/data \
  --name open-webui \
  --restart always \
  ghcr.io/open-webui/open-webui:cuda
  
Firefox Web Browser 輸入 http://localhost:3000
出現 This address is restricted 錯誤
進入 Firefox Web Browser 設定
網址列輸入 about:config, 按 "Accept the Risk and Continue" 按鈕
在收尋欄輸入 network.security.ports.banned.override, 點選 "String", 按 +
輸入 port 3000, 按 V
重新載入 http://localhost:3000

chrome 設定
chrome://flags/#unsafely-treat-insecure-origin-as-secure
輸入網址 http://localhost:3000

安裝 nginx
參考 https://docs.openwebui.com/tutorials/https-nginx/
參考 https://yingrenn.blogspot.com/2020/07/ssl-nginx.html
vi nginx.conf
server {
    listen 443 ssl;
    server_name  www.domain.com.tw;
    ssl_certificate /etc/nginx/conf/Certs/server.pem;
    ssl_certificate_key /etc/nginx/conf/Certs/server.key;
    ssl_trusted_certificate /etc/nginx/conf/Certs/caChain.crt;
    ssl_stapling on;
    ssl_stapling_verify on;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;
    
    location / {
        proxy_set_header HOST $host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://host.docker.internal:3000;
        
        # Add WebSocket support (Necessary for version 0.5.0 and up)
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        
        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;
        
        # (Optional) Disable proxy buffering for better streaming response from models
        proxy_buffering off;
    }
}
server {
     listen 80;
     server_name www.domain.com.tw;
     return 301 https://$host$request_uri; 
}

docker run -itd --name nginx \
  -p 80:80 -p 443:443 \
  --add-host=host.docker.internal:host-gateway \
  -v /mnt/Data/ollama/nginx/conf.d/nginx.conf:/etc/nginx/conf.d/nginx.conf \
  -v /mnt/Data/ollama/nginx/conf:/etc/nginx/conf \
  -m 100m library/nginx:latest

https://www.domain.com.tw