分類彙整: AI
Integrating MCP Servers with FastAPI
建立 MCP 伺服器與整合 LangGraph
The Best Free Offline AI for Video Generation (The Results Are Unreal)
OLlama 安裝 Google MedGemma 模型(失敗)
以下步驟示範如何把 MedGemma(Google 針對醫療領域釋出的 Gemma 3 變體)裝進 Ollama,並分別說明「文字版 27 B」和「多模態 4 B(看圖)」兩種情境。
建議放在專用資料夾
mkdir -p ~/ollama-models/medgemma && cd ~/ollama-models/medgemma
27 B(文字版,Q4_K_M 量化)
wget -c https://huggingface.co/unsloth/medgemma-27b-text-it-GGUF/resolve/main/medgemma-27b-text-it-Q4_K_M.gguf
4 B(多模態版,Q4_K_M 量化 + mmproj 投影層)
wget -c https://huggingface.co/unsloth/medgemma-4b-it-GGUF/resolve/main/medgemma-4b-it-Q4_K_M.gguf
wget -c https://huggingface.co/unsloth/medgemma-4b-it-GGUF/resolve/main/mmproj-F16.gguf
若想用 原生 pre-train (-pt) 版,檔名一樣要注意大小寫:wget -c https://huggingface.co/mradermacher/medgemma-4b-pt-GGUF/resolve/main/medgemma-4b-pt-F16.gguf
2. 撰寫 Modelfile
2.1 文字版 27 B
Modelfile
內容(放在同一目錄):
Modelfile27B
FROM ./medgemma-27b-text-it-Q4_K_M.gguf
TEMPLATE """
{{- if .System }}<|im_start|>system
{{.System}}<|im_end|>{{ end -}}
{{- if .Prompt }}<|im_start|>user
{{.Prompt}}<|im_end|>{{ end -}}
<|im_start|>assistant
{{.Response}}<|im_end|>
"""
PARAMETER num_ctx 8192
2.2 多模態 4 B
多模態必須同時載入 主 GGUF 與 mmproj 投影層檔案;Ollama 允許用兩行 FROM
:Ollama
Modelfile4B
FROM ./mmproj-F16.gguf # 第 1 行:視覺投影層
FROM ./medgemma-4b-it-Q4_K_M.gguf # 第 2 行:4B 主模型
TEMPLATE """
{{- if .System }}<|im_start|>system
{{.System}}<|im_end|>{{ end -}}
{{- if .Prompt }}<|im_start|>user
{{.Prompt}}<|im_end|>{{ end -}}
<|im_start|>assistant
{{.Response}}<|im_end|>
"""
PARAMETER num_ctx 4096
3. 建立並測試模型
# 建立 27B
ollama create medgemma-27b -f ./Modelfile27B
# 建立 4B
ollama create medgemma-4b-vision -f ./Modelfile4B
文字測試
ollama run medgemma-27b
你是誰?
圖像/多模態測試(Ollama CLI)
ollama run medgemma-4b-vision \
--image chest_xray.png \
-p "請描述這張影像的主要異常位置"
或透過 HTTP API:
curl http://localhost:11434/api/generate \
-d '{
"model": "medgemma-4b-vision",
"prompt": "Read this fundus photo and report findings in Chinese",
"images": ["data:image/png;base64,...."]
}'
使用 docker-compose.yml 安裝 n8n
https://github.com/dean9703111/n8n-google-sheet-exmaple
使用 docker-compose.yml 安裝 n8n
你可以直接 git clone 筆者的 GitHub 專案,或者建立一個 n8n
的資料夾,新增 docker-compose.yml
檔案。
volumes: n8n_storage: services: n8n: image: n8nio/n8n:latest restart: always ports: - "127.0.0.1:5678:5678" # 根據實際需求設定 volumes: - n8n_storage:/home/node/.n8n
貼上內容後,在終端機(Terminal)
輸入 docker compose
n8n --project-name
up
-d
即可啟動
加上
environment:
- N8N_SECURE_COOKIE=false # 或改成 true 並上 HTTPS
- N8N_PROTOCOL=http
🔐 1. 安裝憑證(仍需暫時用 port 80)
sudo apt install certbot python3-certbot-apache
sudo certbot certonly --standalone -d yourdomain.com
成功後,憑證位置會是:
/etc/letsencrypt/live/yourdomain.com/
🛠 2. 設定 Apache SSL(以 8443 為例)
建立檔案:
sudo nano /etc/apache2/sites-available/n8n-ssl.conf
內容如下:
<VirtualHost *:8443>
ServerName yourdomain.com
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/yourdomain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/yourdomain.com/privkey.pem
ProxyPreserveHost On
ProxyPass / http://localhost:5678/
ProxyPassReverse / http://localhost:5678/
ErrorLog ${APACHE_LOG_DIR}/n8n_error.log
CustomLog ${APACHE_LOG_DIR}/n8n_access.log combined
</VirtualHost>
啟用必要模組與設定:
sudo a2enmod ssl
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2ensite n8n-ssl.conf
sudo systemctl reload apache2
🐳 3. Docker Compose 設定 (n8n 走 http 5678)
services:
n8n:
image: n8nio/n8n
restart: always
ports:
– “5678:5678”
environment:
– N8N_HOST=yourdomain.com
– N8N_PORT=5678
– N8N_PROTOCOL=http
– N8N_SECURE_COOKIE=true
🔎 存取方式:
Dify 安裝
https://ithelp.ithome.com.tw/articles/10360064
git clone https://github.com/langgenius/dify.git
先到 Docker 的官網裝好 docker,將 Dify 複製到你的裝置中
將 dify 複製到你的任何目錄底下git clone https://github.com/langgenius/dify.git
進到 dify/docker
中,這邊放了所有和 docker 有關的設定cd dify/docker
創建環境檔案 (.env
) 這邊直接複製他的範例即可cp .env.example .env
這邊 Dify 有 nginx 的 container,會將服務開在我們電腦的 80 port 和 443 port (如果有啟動 https),如果你不想開在這些 port 或者電腦這些 port 已經被使用了可以自行修改 .env
# HTTP port NGINX_PORT=80
# 這邊改成你想要的 port
# ------------------------------
# Docker Compose Service Expose Host Port Configurations
# ------------------------------
EXPOSE_NGINX_PORT=80
# 這邊也要改
啟動 docker composedocker compose --project-name dify up -d # 這邊的 -d 是背景執行的意思
-p 命名 DockerName
NGINX
SSL 設定
.evn 編輯
APP_URL=https://ai.example.com
API_HOST=https://ai.example.com
NGINX_SSL_CERT_FILENAME=fullchain.crt
NGINX_SSL_CERT_KEY_FILENAME=privkey.key
docker-compose.yml 編輯
volumes:
/etc/letsencrypt.sh/certs/tahsda.org.tw/privkey.key:/etc/ssl/privkey.key:ro
/etc/letsencrypt.sh/certs/tahsda.org.tw/fullchain.crt:/etc/ssl/fullchain.crt:ro
注意 新增多個 Dify 需要設定 DockerName
docker composedocker compose
--project-name
dockername up -d
5003 port 也需要修改
PLUGIN_DEBUGGING_PORT=5003
EXPOSE_PLUGIN_DEBUGGING_PORT=5003
/etc/letsencrypt.sh/certs/tahsda.org.tw/fullchain.crt:/etc/ssl/fullchain.crt:ro
不使用 NGINX
並使用 Apache proxy 至 Dify
啟用 Apache 反向代理模組
sudo a2enmod proxy proxy_http proxy_wstunnel headers rewrite
sudo systemctl restart apache2
在 docker-compose.yaml
把 nginx:
區塊註解。
或保留,但改 EXPOSE_NGINX_PORT
、EXPOSE_NGINX_SSL_PORT
至高位埠,Apache 反代到該埠。
services:
web:
ports:
– “3000:3000”
api:
ports:
– “5001:5001”
/etc/apache2/sites-available/dify-ssl.conf
<VirtualHost *:8443>
ServerName xxxx.com.tw
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/xxxxx.com.tw/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/xxxxx.com.tw/privkey.pem
SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1
#Include /etc/letsencrypt/options-ssl-apache.conf
# Web 前端(React,含 websocket)
ProxyPreserveHost On
RequestHeader set X-Forwarded-Proto "https"
# (1) Dify API:必須寫在最前面,避免被根路徑蓋掉
ProxyPass /console/api/ http://127.0.0.1:5001/console/api/ retry=0
ProxyPassReverse /console/api/ http://127.0.0.1:5001/console/api/
# (2) Dify Web Frontend (React,預設 3000)
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
ProxyPass /socket.io/ http://127.0.0.1:3000/socket.io/ retry=0
ProxyPassReverse /socket.io/ http://127.0.0.1:3000/socket.io/
# 可選:強制將 http 轉 https
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
ErrorLog ${APACHE_LOG_DIR}/dify_ssl_error.log
CustomLog ${APACHE_LOG_DIR}/dify_ssl_access.log combined
</VirtualHost>
啟用站點並重載
sudo a2ensite dify-ssl.conf
sudo systemctl reload apache2