当前位置: 首页 > news >正文

RAG实战:本地部署ragflow+ollama(linux)

1.部署ragflow

1.1安装配置docker

因为ragflow需要诸如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服务:

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构建docker环境期间,有遇到elasticsearch下载失败的情况,于是将docker-compose-base.yml中的
image: docker.elastic.co/elasticsearch/elasticsearch:${STACK_VERSION}
改成:
image: elasticsearch:${STACK_VERSION}
​

环境构建完成后,确认服务器状态:

docker logs --tail 100 -f ragflow-server

出现以下界面提示说明服务器启动成功:

     ____   ___    ______ ______ __               / __ \ /   |  / ____// ____// /____  _      __/ /_/ // /| | / / __ / /_   / // __ \| | /| / // _, _// ___ |/ /_/ // __/  / // /_/ /| |/ |/ / /_/ |_|/_/  |_|\____//_/    /_/ \____/ |__/|__/  * 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

此时,通过docker ps可以看到运行中的容器:

如果要停止服务:docker stop $(docker ps -q)

1.3 登陆ragflow页面

在你的浏览器中输入你的服务器对应的 IP 地址并登录 RAGFlow。只需输入 http://IP_OF_YOUR_MACHINE 即可:未改动过配置则无需输入端口(默认的 HTTP 服务端口 80,如需修改端口,修改docker-compose.yml中ports下面80前面端口号)

你将在浏览器中看到如下界面,第一次要注册一个账号,邮箱随便填。

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 启动

ollama serve

2.3 下载大模型

以qwen2-7b为例,其他模型可以去https://ollama.com/library搜索。

方法一:ollama run qwen2:7b

模型文件比较大,如果上述方法网络不稳定,可以使用下面的方法二。

方法二:

        ①去https://huggingface.co/models?library=gguf下载gguf格式的模型文件,根据所需,选择一个下载,如Qwen2-7B-Instruct.Q4_K_M.gguf

        ②创建一个构造文件qwen2-7b.modelfile(自由命名),文件的内容为你下载的模型文件路径,如:

FROM ./Qwen2-7B-Instruct.Q4_K_M.gguf

        ③构造

ollama create qwen2-7b -f qwen2-7b.modelfile

构造完成后执行ollama list即可看到你构造的模型。如:

$ollama list
NAME                  ID              SIZE      MODIFIED      
qwen2-7b:latest       0151b69b0ffa    4.7 GB    1 weeks ago

测试:

ollama run qwen2-7b "你是谁?"

2.4 补充其他两种调用方式

url调用:

curl http://localhost:11434/api/chat -d '{"model": "qwen2-7b","messages": [{ "role": "user", "content": "你是谁?" }]
}'

python代码调用:

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,点击右上角的头像,找到模型供应商-选择Ollama-添加模型

在 RagFlow 中配置模型时,由于 RagFlow 是通过 Docker 安装的,因此需要使用以下地址连接本地部署的 Ollama:http://host.docker.internal:11434

若要部署embedding模型,方式与2.3和3.1一样。

3.2 构建知识库 & 聊天

后续的使用步骤均在页面上操作,比较简单易懂,就省略了。

http://www.lryc.cn/news/514749.html

相关文章:

  • 前路漫漫,曙光在望 !
  • 特征工程-特征预处理
  • 代码随想录算法训练营day22
  • 2024秋语法分析作业-B(满分25分)
  • Python爬虫入门(1)
  • 鸿蒙1.2:第一个应用
  • 2024年常用工具
  • 【蓝桥杯】走迷宫
  • 【pyqt】(三)designer
  • 【Go学习】-01-3-函数 结构体 接口 IO
  • 昆仑万维大数据面试题及参考答案
  • 20250103在Ubuntu20.04.5的Android Studio 2024.2.1.12中跑通Hello World
  • Hack The Box-Starting Point系列Three
  • 【Python其他生成随机字符串的方法】
  • redis7基础篇2 redis的主从模式1
  • Springboot - Web
  • 【C】​动态内存管理
  • lec5-传输层原理与技术
  • 【C语言】_指针运算
  • “AI智慧教学系统:开启个性化教育新时代
  • 商用车自动驾驶,迎来大规模量产「临界点」?
  • CSS 学习之正确看待 CSS 世界里的 margin 合并
  • 杰发科技——使用ATCLinkTool解除读保护
  • uni-app深度解码:跨平台APP开发的核心引擎与创新实践
  • unity团结云下载项目
  • Jmeter进阶篇(31)解决java.net.BindException: Address already in use: connect报错
  • 商米电子秤服务插件
  • 华为ensp-BGP路由过滤
  • Sigrity System SI SerialLink模式进行Pcie3协议仿真分析操作指导-pcie3_client_single_post
  • Python提取目标Json键值:包含子嵌套列表和字典