內容概述
ChatOllama 是一個基於大型語言模型(LLMs)的開源聊天機器人平台,支持多種語言模型和知識庫管理功能。
無論您是技術新手還是有經驗的開發者,都可以輕鬆地使用和擴展此平台。
應用場景
ChatOllama 可應用於多種場景,包括:
- 與 LLMs 進行自由對話
- 基於知識庫與 LLMs 進行專業領域的對話
- 整合商業 LLMs API 以實現更強大的功能
技術特點
ChatOllama 的主要特點包括:
- 支持多種語言模型,如 Ollama 服務模型、OpenAI、Azure OpenAI、Anthropic、Moonshot、Gemini 和 Groq
- 知識庫管理,方便用戶創建和維護專業領域的知識
- 商業 LLMs API 密鑰管理,便於整合第三方服務
- 支持多種向量數據庫,如 Milvus 和 Chroma,用於高效的數據存儲和檢索
其他整合
ChatOllama 可與多種服務和工具整合,包括:
- Ollama 服務器,用於模型管理和推理
- Chroma 和 Milvus 向量數據庫,用於知識庫的向量化存儲
- LangSmith,用於追蹤和分析知識庫查詢(可選)
安裝步驟
以下是使用 Docker Compose 安裝 ChatOllama 的步驟:
1. 確保您已安裝 Ollama。如果尚未安裝,請參考 Ollama 官方指南。
2. 確保您已安裝 Docker 和 Docker Compose。如果尚未安裝,請參考 Docker 官方指南。
3. 克隆 ChatOllama 儲存庫:
git clone https://github.com/sugarforever/chat-ollama
正複製到 ‘chat-ollama’…
remote: Enumerating objects: 3610, done.
remote: Counting objects: 100% (1482/1482), done.
remote: Compressing objects: 100% (450/450), done.
remote: Total 3610 (delta 1117), reused 1065 (delta 1020), pack-reused 2128 (from 2)
接收物件中: 100% (3610/3610), 1.54 MiB | 4.92 MiB/s, 完成.
處理 delta 中: 100% (2078/2078), 完成.
4. 創建並編輯.env環境變數檔案:
❯ cd chat-ollama
❯ cp .env.example .env
❯ cat .env
DISABLE_VERCEL_ANALYTICS=false
DATABASE_URL=file:../../chatollama.sqlite
# Chat-ollama server's port
PORT=3000
HOST=
LANGCHAIN_TRACING_V2=false
LANGCHAIN_API_KEY=
LANGCHAIN_PROJECT=chat-ollama
REDIS_HOST=
MOONSHOT_API_KEY=
# Supported values: chroma, milvus
VECTOR_STORE=chroma
CHROMADB_URL=http://localhost:8000
MILVUS_URL=http://localhost:19530
# Cohere API Key - Reranking
COHERE_API_KEY=
COHERE_MODEL=
COHERE_BASE_URL=
# Super admin name
SUPER_ADMIN_NAME=
# API model proxy
NUXT_PUBLIC_MODEL_PROXY_ENABLED=false
# HTTP / HTTPS / SOCKS4 / SOCKS5 protocols are supported, e.g.
# http://127.0.0.1:1080
# socks5://127.0.0.1:1080
# http://username:password@127.0.0.1:1080
# socks5://username:password@127.0.0.1:1080
NUXT_MODEL_PROXY_URL=
# Chat
NUXT_PUBLIC_CHAT_MAX_ATTACHED_MESSAGES=50
5. 設置 .env
文件中的必要環境變數,如 Ollama 服務器和向量數據庫的地址。
6. 創建 Docker Compose 配置檔案 docker-compose.yml
,內容如下:
services:
chromadb:
image: chromadb/chroma
ports:
- "8000:8000"
restart: always
volumes:
- chromadb_volume:/chroma/chroma
chatollama:
environment:
- CHROMADB_URL=http://chromadb:8000
- DATABASE_URL=file:/app/sqlite/chatollama.sqlite
- REDIS_HOST=redis
- COHERE_API_KEY=xxxxx
- COHERE_MODEL=ms-marco-MiniLM-L-6-v2
- COHERE_BASE_URL=http://peanutshell:8000/v1
image: 0001coder/chatollama:latest
pull_policy: always
#extra_hosts:
# - "host.docker.internal:host-gateway"
ports:
- "3000:3000"
restart: always
volumes:
- ~/.chatollama:/app/sqlite
redis:
image: redis:latest
restart: always
volumes:
- redis_data:/data
peanutshell:
image: ghcr.io/sugarforever/peanut-shell:latest
volumes:
- hf_data:/root/.cache
volumes:
chromadb_volume:
redis_data:
hf_data:
7. 創建volume:
docker volume create chromadb_volume
chromadb_volume
docker volume create redis_data
redis_data
docker volume create hf_data
hf_data
8. 啟動ChatOllama服務:
docker compose up -d
[+] Running 42/42
✔ chromadb Pulled 65.3s
✔ chatollama Pulled 180.0s
✔ redis Pulled 27.6s
✔ peanutshell Pulled 391.8s
[+] Running 8/8
✔ Network chat-ollama_default Created 0.4s
✔ Volume “chat-ollama_chromadb_volume” Created 0.0s
✔ Volume “chat-ollama_redis_data” Created 0.0s
✔ Volume “chat-ollama_hf_data” Created 0.0s
✔ Container chat-ollama-redis-1 Started 2.2s
✔ Container chat-ollama-peanutshell-1 Started 2.2s
✔ Container chat-ollama-chromadb-1 Started 2.2s
✔ Container chat-ollama-chatollama-1 Started 2.2s
啟動後,ChatOllama 的服務器將運行於 http://localhost:3000。
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a37c9bf54171 0001coder/chatollama:latest “docker-entrypoint.s…” 2 minutes ago Up 2 minutes 0.0.0.0:3000->3000/tcp, :::3000->3000/tcp chat-ollama-chatollama-1
e047048a3142 chromadb/chroma “/docker_entrypoint.…” 2 minutes ago Up 2 minutes 0.0.0.0:8000->8000/tcp, :::8000->8000/tcp chat-ollama-chromadb-1
f0e7e005578d redis:latest “docker-entrypoint.s…” 2 minutes ago Up 2 minutes 6379/tcp chat-ollama-redis-1
e256f7850136 ghcr.io/sugarforever/peanut-shell:latest “uvicorn main:app –…” 2 minutes ago Up 2 minutes chat-ollama-peanutshell-1
Ollama 服務器和向量數據庫分別運行於 http://localhost:11434
和 http://localhost:8000
。
存取和操作
服務啟動後,您可以通過瀏覽器訪問 http://localhost:3000 進行配置和操作。
- Ollama 服務器默認地址為
http://localhost:11434
。 - 向量數據庫默認地址為
http://localhost:8000
。
在設置頁面中,您可以進一步配置 ChatOllama 的參數,以適應您的需求。
小技巧
- 在知識庫創建時,確保指定有效的嵌入模型名稱,如
nomic-embed-text
,並確保模型已下載或可用。 - 若遇到知識庫查詢緩慢的情況,請檢查模型的加載和釋放策略,確保模型在內存中的保留時間足夠長,以避免頻繁加載。