本地搭建【文档助手】大模型版(LangChain+llama+Streamlit)

概述

本文的文档助手就是:我们上传一个文档,然后在对话框中输入问题,大模型会把问题的答案返回。

安装步骤

  1. 先下载代码到本地

LangChain调用llama模型的示例代码:https://github.com/afaqueumer/DocQA(代码不是本人写的,尊重原创)

java 复制代码
git clone https://github.com/afaqueumer/DocQA.git
  1. 环境安装
java 复制代码
双击 setup_env.bat
  • 如果没反应可能是缺少环境,打开控制台手动执行一下,缺python或者pip的自己根据报错下载一下

如果llama-cpp-python安装报错

(1)需要下载Visual Studio

(2)打开Visual Studio,工具,获取工具和功能

(3)等待下载完,重新运行setup_env.bat

如果还有报错【error C2061: 语法错误: 】,那么可能是Visual Studio的版本太低了,我一开始用的是2019版本,后来换成了2022

更新为2022之后重复上面操作

  1. 下载一个靠谱的模型
    https://huggingface.co/TheBloke/Llama-2-7B-GGUF
    本文用的是:TheBloke/Llama-2-7B-GGUF中的最精简版
  2. 进入DocQA,修改app.py

原始

java 复制代码
llm = LlamaCpp(model_path="./models/llama-7b.ggmlv3.q4_0.bin")
embeddings = LlamaCppEmbeddings(model_path="models/llama-7b.ggmlv3.q4_0.bin")

这里改成自己下载的模型地址,比如:llama-2-7b.Q2_K.gguf

java 复制代码
llm = LlamaCpp(model_path="../llama.cpp/models/7B/llama-2-7b.Q2_K.gguf")
embeddings = LlamaCppEmbeddings(model_path="../llama.cpp/models/7B/llama-2-7b.Q2_K.gguf")
  1. 运行
java 复制代码
双击run_app.bat
  1. 测试

准备好一个txt文档

java 复制代码
As of October this year, there were nearly 2,500 geographical indication products in China
The reporter learned from the State Intellectual Property Office that in recent years, the quantity and quality of China's geographical indication products have risen rapidly. As of October this year, China has approved a total of 2,495 geographical indication products, and approved 7,013 geographical indications to be registered as collective trademarks and certification trademarks. In 2021, the direct output value of GI products exceeded 700 billion yuan.
In recent years, the State Intellectual Property Office has conscientiously implemented the decisions and arrangements of the CPC Central Committee and the State Council, actively and steadily promoted the unified acceptance channels, unified special signs, unified announcements, unified protection and supervision, unified foreign cooperation and other work, and further improved the system of protection, management and application of geographical indications.
In terms of institutional construction, the State Intellectual Property Office issued the "14th Five-Year Plan for the Protection and Use of Geographical Indications", formulated and issued a unified special indication for geographical indications, revised and issued the "Measures for the Protection of Foreign Geographical Indication Products", and launched the legislative work on geographical indications; In the year, a total of 1,416 cases of infringement of geographical indications were investigated and dealt with across the country, involving an amount of 9.28 million yuan and a fine of 13.023 million yuan

上传到页面中

没有GPU的痛苦,运行太慢了

注意:别用中文问,这个模型好像不支持中文,换一个支持中文的模型就行了

相关推荐
奔跑吧邓邓子9 分钟前
【Python爬虫(12)】正则表达式:Python爬虫的进阶利刃
爬虫·python·正则表达式·进阶·高级
码界筑梦坊32 分钟前
基于Flask的京东商品信息可视化分析系统的设计与实现
大数据·python·信息可视化·flask·毕业设计
pianmian134 分钟前
python绘图之箱型图
python·信息可视化·数据分析
csbDD1 小时前
2025年网络安全(黑客技术)三个月自学手册
linux·网络·python·安全·web安全
kcarly2 小时前
KTransformers如何通过内核级优化、多GPU并行策略和稀疏注意力等技术显著加速大语言模型的推理速度?
人工智能·语言模型·自然语言处理
赔罪2 小时前
Python 高级特性-切片
开发语言·python
伊一大数据&人工智能学习日志3 小时前
selenium爬取苏宁易购平台某产品的评论
爬虫·python·selenium·测试工具·网络爬虫
说是用户昵称已存在3 小时前
Pycharm+CodeGPT+Ollama+Deepseek
ide·python·ai·pycharm
Fansv5873 小时前
深度学习-2.机械学习基础
人工智能·经验分享·python·深度学习·算法·机器学习
wang_yb4 小时前
『Python底层原理』--Python对象系统探秘
python·databook