seo外貿(mào)網(wǎng)站建設(shè)百度下載安裝2021最新版
1.部署ragflow
1.1安裝配置docker
因?yàn)閞agflow需要諸如elasticsearch、mysql、redis等一系列三方依賴,所以用docker是最簡便的方法。
docker安裝可參考Linux安裝Docker完整教程,安裝后修改docker配置如下:
vim /etc/docker/daemon.json
{"builder": {"gc": {"defaultKeepStorage": "20GB","enabled": true}},"experimental": false,"features": {"buildkit": true},"live-restore": true,"registry-mirrors": ["https://docker.211678.top","https://docker.1panel.live","https://hub.rat.dev","https://docker.m.daocloud.io","https://do.nark.eu.org","https://dockerpull.com","https://dockerproxy.cn","https://docker.awsl9527.cn/"]
}
修改后重新加載配置并重啟docker服務(wù):
systemctl daemon-reload && systemctl restart docker
1.2 配置ragflow
?
git clone?https://github.com/infiniflow/ragflow.git
cd ragflow/docker
docker compose -f docker-compose.yml up -d構(gòu)建docker環(huán)境期間,有遇到elasticsearch下載失敗的情況,于是將docker-compose-base.yml中的
image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
改成:
image: elasticsearch:${STACK_VERSION}
?
環(huán)境構(gòu)建完成后,確認(rèn)服務(wù)器狀態(tài):
docker logs --tail 100 -f ragflow-server
出現(xiàn)以下界面提示說明服務(wù)器啟動(dòng)成功:
____ ___ ______ ______ __ / __ \ / | / ____// ____// /____ _ __/ /_/ // /| | / / __ / /_ / // __ \| | /| / // _, _// ___ |/ /_/ // __/ / // /_/ /| |/ |/ / /_/ |_|/_/ |_|\____//_/ /_/ \____/ |__/|__/ * Running on all addresses (0.0.0.0)* Running on http://127.0.0.1:9380* Running on http://x.x.x.x:9380INFO:werkzeug:Press CTRL+C to quit
此時(shí),通過docker ps可以看到運(yùn)行中的容器:
如果要停止服務(wù):docker stop $(docker ps -q)
1.3 登陸ragflow頁面
在你的瀏覽器中輸入你的服務(wù)器對應(yīng)的 IP 地址并登錄 RAGFlow。只需輸入 http://IP_OF_YOUR_MACHINE 即可:未改動(dòng)過配置則無需輸入端口(默認(rèn)的 HTTP 服務(wù)端口 80,如需修改端口,修改docker-compose.yml中ports下面80前面端口號(hào))
你將在瀏覽器中看到如下界面,第一次要注冊一個(gè)賬號(hào),郵箱隨便填。
2.部署ollama
2.1下載ollama
# 兩種下載方式:
# 方法一:
curl -fsSL https://ollama.com/install.sh | sh# 方法二:
curl -L https://ollama.com/download/ollama-linux-amd64.tgz -o ollama-linux-amd64.tgz
sudo tar -C /usr -xzf ollama-linux-amd64.tgz
2.2 啟動(dòng)
ollama serve
2.3 下載大模型
以qwen2-7b為例,其他模型可以去https://ollama.com/library搜索。
方法一:ollama run qwen2:7b
模型文件比較大,如果上述方法網(wǎng)絡(luò)不穩(wěn)定,可以使用下面的方法二。
方法二:
? ? ? ? ①去https://huggingface.co/models?library=gguf下載gguf格式的模型文件,根據(jù)所需,選擇一個(gè)下載,如Qwen2-7B-Instruct.Q4_K_M.gguf
? ? ? ? ②創(chuàng)建一個(gè)構(gòu)造文件qwen2-7b.modelfile(自由命名),文件的內(nèi)容為你下載的模型文件路徑,如:
FROM ./Qwen2-7B-Instruct.Q4_K_M.gguf
? ? ? ? ③構(gòu)造
ollama create qwen2-7b -f qwen2-7b.modelfile
構(gòu)造完成后執(zhí)行ollama list即可看到你構(gòu)造的模型。如:
$ollama list
NAME ID SIZE MODIFIED
qwen2-7b:latest 0151b69b0ffa 4.7 GB 1 weeks ago
測試:
ollama run qwen2-7b "你是誰?"
2.4 補(bǔ)充其他兩種調(diào)用方式
url調(diào)用:
curl http://localhost:11434/api/chat -d '{"model": "qwen2-7b","messages": [{ "role": "user", "content": "你是誰?" }]
}'
python代碼調(diào)用:
import requests
import jsondef send_message_to_ollama(message, port=11434):url = f"http://localhost:{port}/api/chat"payload = {"model": "qwen2-7b","messages": [{"role": "user", "content": message}]}response = requests.post(url, json=payload)if response.status_code == 200:response_content = ""for line in response.iter_lines():if line:response_content += json.loads(line)["message"]["content"]return response_contentelse:return f"Error: {response.status_code} - {response.text}"if __name__ == "__main__":user_input = "why is the sky blue?"response = send_message_to_ollama(user_input)print("Ollama's response:")print(response)
3.在ragflow中配置ollama
3.1 添加LLM
登陸ragflow,點(diǎn)擊右上角的頭像,找到模型供應(yīng)商-選擇Ollama-添加模型
在 RagFlow 中配置模型時(shí),由于 RagFlow 是通過 Docker 安裝的,因此需要使用以下地址連接本地部署的 Ollama:http://host.docker.internal:11434
若要部署embedding模型,方式與2.3和3.1一樣。
3.2 構(gòu)建知識(shí)庫 & 聊天
后續(xù)的使用步驟均在頁面上操作,比較簡單易懂,就省略了。