ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

如何使用 Quivr Assistants 从 PDF 生成文档摘要?

如何使用 Quivr Assistants 从 PDF 生成文档摘要? 如何使用 Quivr Assistants 从 PDF 生成文档摘要【免费下载链接】quivrOpiniated RAG for integrating GenAI in your apps Focus on your product rather than the RAG. Easy integration in existing products with customisation! Any LLM: GPT4, Groq, Llama. Any Vectorstore: PGVector, Faiss. Any Files. Anyway you want.项目地址: https://gitcode.com/GitHub_Trending/qui/quivrQuivr 的 Assistant 是另一种 Brain它是一种 AI Agent能针对特定输入生成可直接使用的输出。文档给出的典型例子就是“输入一个 PDF收到该文档的摘要作为结果”见 Quivr Assistants 文档 与 Summary 说明。本文介绍如何用 Quivr 内置的 Summary Assistant 完成这个任务先在本地把 Quivr 跑起来然后通过界面或 API 上传一个 PDF最终通过邮件收到摘要或把摘要写入一个已有的 Brain。适用前提是你已安装 Docker 与 Docker Compose并拥有 OpenAI API Key——后端摘要链路在源码中固定使用gpt-4o见 summary.py 中ChatLiteLLM(modelgpt-4o, max_tokens2000)因此必须配置OPENAI_API_KEY。准备在本地运行 Quivr按 安装文档 的步骤操作# Step 1: 克隆仓库如已在本地可直接跳过 git clone https://gitcode.com/GitHub_Trending/qui/quivr cd quivr # Step 2: 复制 .env.example 为 .env cp .env.example .env # Step 3: 编辑 .env填入 OPENAI_API_KEY vim .env # Step 4: 启动项目 cd backend supabase start cd ../ docker compose pull docker compose up启动后按文档给出的地址确认服务可用前端应用http://localhost:3000/login使用adminquivr.app/admin登录后端 API 文档http://localhost:5050/docsSupabase 控制台http://localhost:54323。如果登录页和 Swagger 文档都能访问说明环境准备完成可以继续。在界面中使用 Summary AssistantQuivr Assistants 文档 给出的操作流程是三步选择你的 Quivr Assistant在 Assistants 页面对应源码 frontend/app/assistants/page.tsx选择 Summary。提供输入上传要摘要的 PDF 文件。Summary 的输入约束是“One document to summarize”即只能有一个 PDF。选择结果去向选择通过邮件接收结果或把结果上传到一个已存在的 Brain。通过 API 生成摘要如果你希望脚本化验证这条链路可以直接调用后端接口。接口定义在 assistant_routes.py两个路由都声明了AuthBearer()依赖因此请求需要携带 Bearer 令牌在 http://localhost:5050/docs 的 Swagger UI 中也可以直接尝试。查看可用的 Assistantcurl http://localhost:5050/assistants \ -H Authorization: Bearer YOUR_BEARER_TOKENGET /assistants返回当前注册的 Assistant 列表其中 Summary 条目的关键字段来自 summary_inputs()name:Summarydescription:Summarize a set of documentsinput_description:One document to summarizeoutput_description:A summary of the document with key points and main themesinputs.files: 要求一个key为doc_to_summarize、允许扩展名pdf的文件outputs:email通过邮件发送与brain类型uuid即目标 Brain 的 uuid如果响应里能看到 Summary 条目说明 Assistant 可用。调用摘要接口POST /assistant/process是 multipart 请求表单字段input是一段 JSON 字符串对应 InputAssistant包含name、inputs、outputs三部分files是上传的文件。示例curl -X POST http://localhost:5050/assistant/process \ -H Authorization: Bearer YOUR_BEARER_TOKEN \ -F input{name:summary,inputs:{files:[{key:doc_to_summarize,value:report.pdf}]},outputs:{email:{activated:true},brain:{activated:true,value:BRAIN_UUID}}} \ -F filesreport.pdf占位符替换说明YOUR_BEARER_TOKEN你的 Bearer 认证令牌report.pdfinputJSON 里files[0].value必须与files后实际上传的文件名完全一致且必须是唯一的 PDFBRAIN_UUID接收结果的目标 Brain 的 uuid仅当brain.activated为true时需要如果只想通过邮件接收把brain的activated设为false或省略即可但email与brain至少有一个激活。结果验证与常见报错成功路径请求通过后Summary Assistant 用UnstructuredPDFLoader解析 PDF按chunk_size1000、chunk_overlap100切分文档用 Map-Reduce 链MapReduceDocumentsChainreduce 侧token_max4000先逐段总结、再汇总成最终摘要。reduce 提示词要求最终摘要包含Summary和Key Points加粗小节的 markdown 结构并保留与原文相同的语言。随后摘要会被生成并处理成结果文件create_and_upload_processed_file(content, filename, Summary)按你的选择通过邮件送达或写入所选 Brain。在邮箱或对应 Brain 中看到摘要文件即为完成。失败路径接口校验失败时返回 HTTP 400detail字段是对应错误文本。以下信息都来自 SummaryAssistant.check_input()错误信息原文触发条件No file was uploaded没有上传任何文件或inputs.files[0].value为空Only one file can be uploaded一次上传了多个文件或inputs.files数组超过 1 项No files key were given in the inputinputs.files缺失The key of the file should be doc_to_summarize文件条目的key不是doc_to_summarizeThe key of the file should be the same as the name of the filevalue与上传文件的实际文件名不一致No output was selectedoutputs.email.activated与outputs.brain.activated都没有设为true限制仅支持pdf扩展名且每次只能处理一个文件摘要模型在源码中固定为gpt-4omax_tokens2000本地实例依赖.env中的OPENAI_API_KEY不能换用本地模型每次使用有默认计费Pricing(cost20, descriptionCredits per use)见 outputs.py会消耗用户额度GET /assistants当前只返回 Summary 一个条目difference、crawler分支在路由中尚未注册进列表所以界面与 API 层面能直接使用的就是 Summary。【免费下载链接】quivrOpiniated RAG for integrating GenAI in your apps Focus on your product rather than the RAG. Easy integration in existing products with customisation! Any LLM: GPT4, Groq, Llama. Any Vectorstore: PGVector, Faiss. Any Files. Anyway you want.项目地址: https://gitcode.com/GitHub_Trending/qui/quivr创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表