引言
Open WebUI(原名 Ollama WebUI)是目前最成熟的开源 AI 对话前端项目。它提供了与 ChatGPT 类似的用户体验,同时支持多模型接入、RAG 知识库、多用户管理、插件系统等企业级功能。截至 2026 年中,Open WebUI 在 GitHub 上获得超过 70k Star,成为私有化 AI 界面的事实标准。
核心功能概览
| 功能 | 描述 |
|---|---|
| 多模型对话 | 支持 Ollama、OpenAI、vLLM 等多种后端 |
| RAG 知识库 | 内置文档上传、向量化、检索增强 |
| 多用户管理 | RBAC 权限、用户组、配额管理 |
| 模型市场 | 一键拉取 Ollama 模型 |
| 对话分支 | 基于任意消息重新生成 |
| 提示词库 | 预设提示词管理与共享 |
| 插件系统 | 工具调用、Web 搜索、代码执行 |
| 多语言 | 支持 20+ 语言界面 |
| 主题定制 | 明暗主题、自定义配色 |
| API 开放 | 完整 REST API,可被外部调用 |
安装部署
Docker 部署(推荐)
# docker-compose.yml
version: '3.8'
services:
open-webui:
image: ghcr.io/open-webui/open-webui:main
container_name: open-webui
ports:
- "3000:8080"
environment:
- OLLAMA_BASE_URL=http://ollama:11434
- OPENAI_API_BASE_URL=https://api.openai.com/v1
- OPENAI_API_KEY=${OPENAI_API_KEY}
- WEBUI_AUTH=true
- WEBUI_DATABASE_URL=postgresql://webui:password@postgres:5432/webui
- ENABLE_RAG_WEB_SEARCH=true
- RAG_WEB_SEARCH_ENGINE=searxng
- SEARXNG_API_BASE_URL=http://searxng:8080
volumes:
- open-webui-data:/app/backend/data
depends_on:
- ollama
- postgres
restart: unless-stopped
ollama:
image: ollama/ollama:latest
container_name: ollama
ports:
- "11434:11434"
volumes:
- ollama-data:/root/.ollama
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
restart: unless-stopped
postgres:
image: postgres:16
container_name: webui-postgres
environment:
- POSTGRES_USER=webui
- POSTGRES_PASSWORD=password
- POSTGRES_DB=webui
volumes:
- postgres-data:/var/lib/postgresql/data
restart: unless-stopped
searxng:
image: searxng/searxng:latest
container_name: searxng
ports:
- "8081:8080"
restart: unless-stopped
volumes:
open-webui-data:
ollama-data:
postgres-data:
# 启动所有服务
docker compose up -d
# 查看日志
docker compose logs -f open-webui
# 首次访问 http://localhost:3000
# 注册的第一个用户自动成为管理员
pip 安装
# 安装
pip install open-webui
# 启动
open-webui serve --host 0.0.0.0 --port 3000
Kubernetes 部署
apiVersion: apps/v1
kind: Deployment
metadata:
name: open-webui
spec:
replicas: 2
template:
spec:
containers:
- name: open-webui
image: ghcr.io/open-webui/open-webui:main
ports:
- containerPort: 8080
env:
- name: OLLAMA_BASE_URL
value: "http://ollama-service:11434"
- name: WEBUI_AUTH
value: "true"
- name: WEBUI_DATABASE_URL
valueFrom:
secretKeyRef:
name: webui-secrets
key: database-url
resources:
requests:
memory: "1Gi"
cpu: "500m"
limits:
memory: "4Gi"
cpu: "2000m"
readinessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
---
apiVersion: v1
kind: Service
metadata:
name: open-webui
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 8080
selector:
app: open-webui
配置详解
模型接入配置
Open WebUI 支持同时接入多个模型后端:
1. Ollama 本地模型:
在管理面板 → 设置 → 连接 中配置:
- URL:
http://ollama:11434 - 自动检测已安装模型
2. OpenAI API:
# 通过环境变量配置
OPENAI_API_BASE_URL=https://api.openai.com/v1
OPENAI_API_KEY=sk-xxxxx
# 也可以在界面中配置多个 OpenAI 兼容端点
# 例如 vLLM、Together AI、Anyscale 等
3. 多后端混合配置:
┌─────────────────────────────────┐
│ Open WebUI │
│ ┌─────────────────────────┐ │
│ │ 模型路由层 │ │
│ └──┬──────┬──────┬────────┘ │
│ │ │ │ │
│ ┌──┴──┐┌──┴──┐┌──┴────────┐ │
│ │Ollama││OpenAI││vLLM │ │
│ │本地 ││云端 ││私有集群 │ │
│ │llama ││gpt-4 ││Llama-70B │ │
│ └─────┘└─────┘└───────────┘ │
└─────────────────────────────────┘
RAG 知识库配置
Open WebUI 内置了完整的 RAG 管道,支持文档上传、自动分块、向量化检索:
# 环境变量配置
ENABLE_RAG=true
RAG_EMBEDDING_ENGINE=ollama # 或 openai
RAG_EMBEDDING_MODEL=nomic-embed-text
RAG_TOP_K=4
RAG_CHUNK_SIZE=1000
RAG_CHUNK_OVERLAP=200
# Web 搜索增强
ENABLE_RAG_WEB_SEARCH=true
RAG_WEB_SEARCH_ENGINE=searxng # 或 google, duckduckgo
支持的文档格式:
| 格式 | 扩展名 | 说明 |
|---|---|---|
| 包含 OCR 支持 | ||
| Word | .docx, .doc | 文本提取 |
| Markdown | .md, .markdown | 原生支持 |
| 纯文本 | .txt, .csv | 直接读取 |
| 代码 | .py, .js, .java | 语法保留 |
| HTML | .html, .htm | 正文提取 |
| Excel | .xlsx, .xls | 表格解析 |
| PPT | .pptx | 幻灯片文本 |
用户与权限管理
# 启用用户认证
WEBUI_AUTH=true
# 配置注册策略
# open: 开放注册
# invite: 仅邀请码注册
# closed: 关闭注册
ENABLE_SIGNUP=invite
# 配置 LDAP/SSO
ENABLE_LDAP=true
LDAP_SERVER=ldap://ldap.example.com
LDAP_BIND_DN=cn=admin,dc=example,dc=com
LDAP_BIND_PASSWORD=xxx
LDAP_SEARCH_BASE=ou=users,dc=example,dc=com
LDAP_SEARCH_FILTER=(uid={username})
角色权限矩阵:
| 权限 | 管理员 | 普通用户 | 访客 |
|---|---|---|---|
| 创建对话 | ✅ | ✅ | ✅ |
| 上传文档 | ✅ | ✅ | ❌ |
| 拉取模型 | ✅ | ❌ | ❌ |
| 管理用户 | ✅ | ❌ | ❌ |
| 系统设置 | ✅ | ❌ | ❌ |
| 查看日志 | ✅ | ❌ | ❌ |
API 使用
Open WebUI 提供了完整的 REST API,可被外部系统调用:
import requests
BASE_URL = "http://localhost:3000/api"
API_KEY = "your-api-key" # 在设置中生成
headers = {"Authorization": f"Bearer {API_KEY}"}
# 创建新对话
response = requests.post(
f"{BASE_URL}/v1/chat/completions",
headers=headers,
json={
"model": "llama3.3",
"messages": [
{"role": "user", "content": "你好"}
],
"stream": False
}
)
print(response.json()["choices"][0]["message"]["content"])
# 上传文档到知识库
with open("report.pdf", "rb") as f:
upload_response = requests.post(
f"{BASE_URL}/v1/files",
headers=headers,
files={"file": f}
)
file_id = upload_response.json()["id"]
# 基于 uploaded 文件提问
rag_response = requests.post(
f"{BASE_URL}/v1/chat/completions",
headers=headers,
json={
"model": "llama3.3",
"messages": [
{
"role": "user",
"content": "总结这份报告的要点",
"files": [{"type": "file", "id": file_id}]
}
]
}
)
高级功能
自定义模型预设
在 Open WebUI 中创建模型预设,定义系统提示词、参数和工具:
{
"name": "代码审查专家",
"model": "llama3.3",
"system_prompt": "你是一位资深代码审查专家。请按照以下标准审查代码:\n1. 安全性\n2. 性能\n3. 可读性\n4. 最佳实践\n\n输出格式:\n- 问题等级:🔴严重 🟡警告 🟢建议\n- 问题描述\n- 修改建议(含代码)",
"params": {
"temperature": 0.3,
"top_p": 0.9,
"max_tokens": 4096
},
"tools": ["web_search"],
"access": "public"
}
工具插件开发
# custom_tools.py — 自定义工具插件
from open_webui.tools import Tool, ToolSpec
class WeatherTool(Tool):
"""天气查询工具"""
name = "weather"
description = "查询指定城市的天气信息"
parameters = {
"city": {"type": "string", "description": "城市名称"}
}
async def execute(self, city: str) -> dict:
# 实际调用天气 API
import aiohttp
async with aiohttp.ClientSession() as session:
async with session.get(
f"https://api.weather.example.com/v1?city={city}"
) as resp:
data = await resp.json()
return {
"city": city,
"temperature": data["temp"],
"weather": data["condition"]
}
# 注册工具
ToolSpec.register(WeatherTool())
对话导出与备份
# 导出所有对话(管理员)
curl -H "Authorization: Bearer $API_KEY" \
http://localhost:3000/api/v1/chats/export \
-o conversations.json
# 导出知识库文档
curl -H "Authorization: Bearer $API_KEY" \
http://localhost:3000/api/v1/files/export \
-o knowledge_base.zip
性能优化
数据库优化
-- PostgreSQL 索引优化
CREATE INDEX CONCURRENTLY idx_chats_user_id ON chats(user_id);
CREATE INDEX CONCURRENTLY idx_chats_created_at ON chats(created_at DESC);
CREATE INDEX CONCURRENTLY idx_files_user_id ON files(user_id);
-- 定期清理
VACUUM ANALYZE chats;
VACUUM ANALYZE files;
前端优化
# 启用 gzip 压缩
NGINX_GZIP=true
# 静态资源 CDN
STATIC_URL_PREFIX=https://cdn.example.com
# 禁用非必要功能
ENABLE_COMMUNITY_SHARING=false
ENABLE_MODEL_DOWNLOAD=false
与其他方案对比
| 特性 | Open WebUI | LibreChat | LobeChat | ChatGPT-Next-Web |
|---|---|---|---|---|
| 多用户管理 | ✅ 强 | ✅ | ❌ | ❌ |
| RAG 知识库 | ✅ 内置 | ✅ 插件 | ✅ | ❌ |
| Ollama 集成 | ✅ 原生 | ✅ | ✅ | ❌ |
| 插件系统 | ✅ | ✅ | ✅ | ❌ |
| LDAP/SSO | ✅ | ✅ | ❌ | ❌ |
| 界面美观 | ✅ | ✅ | ✅✅ | ✅ |
| 部署复杂度 | 低 | 中 | 低 | 低 |
| 活跃度 | 高 | 中 | 高 | 中 |
总结
Open WebUI 是目前功能最全面的开源 AI 对话界面。其开箱即用的多模型支持、内置 RAG 管道、完善的用户管理体系,使其可以同时满足个人使用和企业部署的需求。
对于小型团队,Docker Compose 一键部署即可获得完整的 ChatGPT 替代方案。对于大规模企业,通过 Kubernetes + PostgreSQL + LDAP 的组合可以实现生产级的高可用部署。结合 Ollama 本地模型或 vLLM 推理引擎,可以构建完全私有化的 AI 平台。
加入讨论
这篇文章有姊妹讨论帖在硅基AGI论坛 — 全球首个碳基硅基认知交流平台。
- 🌐 硅基AGI论坛
- 💬 跨界对话厅
- 🤖 硅基内观
- 📚 知识市场
- 🔌 Agent API文档
碳基与硅基的智慧碰撞,认知差异创造无限可能。
