內容概述
在現代人工智慧應用中,監控和追蹤大型語言模型(LLM)的運行狀態至關重要。Langfuse 提供開源的可觀測性和評估工具,讓開發者能夠深入了解應用的行為。
本文將介紹如何將 OpenWebUI 與Langfuse 進行整合,實現對 LLM 應用的高效監控。
應用場景
透過將 OpenWebUI與Langfuse 進行整合,開發者可以:
- 追蹤應用程式的操作流程。
- 分析使用者互動模式。
- 根據模型和使用者計算成本數據。
- 執行模型輸出的評估,以提升應用品質。
技術特點
OpenWebUI 是一個自託管的 Web 介面,支援多種 LLM 執行,包括 Ollama 和與 OpenAI 相容的 API。
它的彈性架構允許開發者輕鬆整合各種插件和工具。
Langfuse 則提供了強大的追蹤和評估功能,能夠捕捉應用的各種指標,協助開發者優化模型表現。
其他整合
Langfuse本身具備完善的LLM觀測功能外,亦支援與多種框架和工具的整合,如 Langchain、LlamaIndex、Haystack 等,為開發者提供全方位的可觀測性解決方案。
安裝步驟
1. 設定 OpenWebUI:依照官方文件,安裝並配置 OpenWebUI。
docker run -d -p 3001:8080 –add-host=host.docker.internal:host-gateway -v open-webui:/app/backend/data –name open-webui –restart always ghcr.io/open-webui/open-webui::v0.5.4
ghcr.io/open-webui/open-webui:v0.5.4
Unable to find image ‘ghcr.io/open-webui/open-webui:v0.5.4’ locally
v0.5.4: Pulling from open-webui/open-webui
f5c6876bb3d7: Already exists
681f5b8ff801: Already exists
b1227c93bfb7: Already exists
cb08acae466d: Already exists
0503d2c39f40: Pull complete
4f4fb700ef54: Pull complete
a960254c47b1: Pull complete
6c61893cbbc8: Pull complete
f0369727b766: Pull complete
5ffedea529a1: Pull complete
5d183d640b49: Pull complete
c38e11b2322d: Pull complete
18bfed63a559: Pull complete
d2999f7a63e7: Pull complete
824bda6034c1: Pull complete
Digest: sha256:42e8fa544facc38d731e3d516fbf478abe435bb4b80798e0934930afea6c5bab
Status: Downloaded newer image for ghcr.io/open-webui/open-webui:v0.5.4
59d1cf3fbf0a25b2c54580a07f1039e3763b9176d9c22d49aca8a033b04d4d31
2. 設定Langfuse:依照官方文件,安裝並配置 Langfuse。
git clone https://github.com/langfuse/langfuse.git
正複製到 ‘langfuse’…
remote: Enumerating objects: 44793, done.
remote: Counting objects: 100% (5969/5969), done.
remote: Compressing objects: 100% (542/542), done.
remote: Total 44793 (delta 5717), reused 5442 (delta 5426), pack-reused 38824 (from 1)
接收物件中: 100% (44793/44793), 16.01 MiB | 1.64 MiB/s, 完成.
處理 delta 中: 100% (30611/30611), 完成.
cd langfuse
docker compose up -d
[+] Running 75/75
✔ redis Pulled 42.4s
✔ postgres Pulled 38.2s
✔ minio Pulled 81.4s
✔ langfuse-worker Pulled 112.3s
✔ clickhouse Pulled 115.0s
✔ langfuse-web Pulled 73.1s
[+] Running 11/11
✔ Network langfuse_default Created 0.0s
✔ Volume “langfuse_langfuse_minio_data” Created 0.0s
✔ Volume “langfuse_langfuse_postgres_data” Created 0.0s
✔ Volume “langfuse_langfuse_clickhouse_data” Created 0.0s
✔ Volume “langfuse_langfuse_clickhouse_logs” Created 0.0s
✔ Container langfuse-postgres-1 Healthy 5.7s
✔ Container clickhouse Healthy 7.2s
✔ Container langfuse-redis-1 Healthy 5.2s
✔ Container minio Healthy 7.7s
✔ Container langfuse-langfuse-web-1 Started 6.2s
✔ Container langfuse-langfuse-worker-1 Started 6.2s
- 登入langfuse portal(http://localhost:3000),創建專案open-webui,接著點選 project settings,進入API Keys管理頁面,創建API Key。

- 複製Secret Key & Public Key的值,先保存起來,稍後在open-webui中會用到。

3. 設定 Pipelines:啟動 Pipelines 實例。
docker run -d -p 9099:9099 –add-host=host.docker.internal:host-gateway -v pipelines:/app/pipelines –name pipelines –restart always ghcr.io/open-webui/pipelines:main
Unable to find image ‘ghcr.io/open-webui/pipelines:main’ locally
main: Pulling from open-webui/pipelines
f5c6876bb3d7: Already exists
681f5b8ff801: Already exists
b1227c93bfb7: Already exists
cb08acae466d: Already exists
86f973873606: Pull complete
571eaf0f2478: Pull complete
c93e905218be: Pull complete
a2b8ea1f14ac: Pull complete
965077b9c81d: Pull complete
b8324a82a188: Pull complete
407e0385d59e: Pull complete
b3ede5505188: Pull complete
Digest: sha256:854ab2028fa06e0491260a8d013776fedb484b5611b182ee3a6a456752121e35
Status: Downloaded newer image for ghcr.io/open-webui/pipelines:main
df3aacd7f5b376448704ec3030a03938de2217b44495dd850b6ed9fc8e3f9121
4. 登入OpenWebUI portal(http://localhost:3001),連接 OpenWebUI 與 Pipelines:在 OpenWebUI 的設定中,將 OpenAI API 的 URL 指向您的 Pipelines 實例。
- 新增Connections,輸入URL & API Key
- URL: http://host.docker.internal:9099
- API Key : 0p3n-w3bu!

- 確認新增完畢後的設置。

5. 新增 Langfuse Filter Pipeline:在 Pipelines 中,新增 Langfuse 的 Filter Pipeline,並配置您的 Langfuse API 金鑰。
https://github.com/open-webui/pipelines/blob/main/examples/filters/langfuse_filter_pipeline.py
- 複製上述連結,貼入Pipelines 的 Install form Github URL中,安裝Filter Pipeline。

- 將langfuse中的金鑰,貼入此處。

存取和操作
完成上述設定後,您可以透過 Langfuse 的儀表板觀察 OpenWebUI 的操作情況,包括使用者互動、模型回應時間等關鍵指標。
- 設置完成後,您將可以透過Langfuse追蹤所有Open WebUI的Chat紀錄。

- 除了Chat的紀錄外,Langfuse也會針對API的訪問,進行計費統計與分析。

教學影片
小技巧
為確保數據的準確性,請定期更新 Langfuse 和 OpenWebUI 至最新版本。
此外,善用 Langfuse 的評估功能,對模型輸出進行質量檢測,持續提升應用的表現。
參考連結
透過上述步驟,您可以成功將OpenWebUI與Langfuse進行整合,全面提升 LLM 應用的可觀測性和性能。