跳转到主内容

混合研究

简介

GPT Researcher 可以将网络搜索功能与本地文档分析相结合,以提供全面的、具有上下文感知的研究结果。

本指南将引导您完成使用 GPT Researcher 设置和运行混合研究的过程。

先决条件

在开始之前,请确保您已具备以下条件

  • 您的系统上已安装 Python 3.10 或更高版本
  • pip(Python 包安装程序)
  • 一个 OpenAI API 密钥(您也可以选择其他支持的大语言模型(LLM)
  • 一个 Tavily API 密钥(您也可以选择其他支持的检索器

安装

pip install gpt-researcher

设置环境

将您的 API 密钥导出为环境变量

export OPENAI_API_KEY=your_openai_api_key_here
export TAVILY_API_KEY=your_tavily_api_key_here

或者,您可以在您的 Python 脚本中设置这些变量

import os
os.environ['OPENAI_API_KEY'] = 'your_openai_api_key_here'
os.environ['TAVILY_API_KEY'] = 'your_tavily_api_key_here'

在 default.py 中将环境变量 REPORT_SOURCE 设置为空字符串 ""

准备文档

1. 本地文档

  1. 在您的项目文件夹中创建一个名为 my-docs 的目录。
  2. 将所有相关的本地文档(PDF、TXT、DOCX 等)放入此目录。

2. 在线文档

  1. 这是您的在线文档 URL 示例:https://xxxx.xxx.pdf(支持 PDF、TXT、DOCX 等文件格式)

通过“本地文档”运行混合研究

这是一个运行混合研究的基本脚本

from gpt_researcher import GPTResearcher
import asyncio

async def get_research_report(query: str, report_type: str, report_source: str) -> str:
researcher = GPTResearcher(query=query, report_type=report_type, report_source=report_source)
research = await researcher.conduct_research()
report = await researcher.write_report()
return report

if __name__ == "__main__":
query = "How does our product roadmap compare to emerging market trends in our industry?"
report_source = "hybrid"

report = asyncio.run(get_research_report(query=query, report_type="research_report", report_source=report_source))
print(report)

通过“在线文档”运行混合研究

这是一个运行混合研究的基本脚本

from gpt_researcher import GPTResearcher
import asyncio

async def get_research_report(query: str, report_type: str, report_source: str) -> str:
researcher = GPTResearcher(query=query, report_type=report_type, document_urls=document_urls, report_source=report_source)
research = await researcher.conduct_research()
report = await researcher.write_report()
return report

if __name__ == "__main__":
query = "How does our product roadmap compare to emerging market trends in our industry?"
report_source = "hybrid"
document_urls = ["https://xxxx.xxx.pdf", "https://xxxx.xxx.doc"]

report = asyncio.run(get_research_report(query=query, report_type="research_report", document_urls=document_urls, report_source=report_source))
print(report)

要运行该脚本:

  1. 将其保存为 run_research.py
  2. 使用以下命令执行:python run_research.py

理解结果

输出将是一份综合研究报告,结合了来自网络资源和您本地文档的见解。报告通常包括执行摘要、关键发现、详细分析、内部数据与外部趋势的比较,以及基于综合见解的建议。

故障排除

  1. API 密钥问题:确保您的 API 密钥已正确设置并具有必要的权限。
  2. 文档加载错误:检查您的本地文档是否为支持的格式且未损坏。
  3. 内存问题:对于大型文档或广泛的研究,您可能需要增加系统的可用内存或在文档处理步骤中调整 chunk_size

常见问题

问:一次典型的研究会话需要多长时间? 答:持续时间因查询的复杂性和需要处理的数据量而异。对于非常全面的研究,可能需要 1-5 分钟。

问:我可以在其他语言模型上使用 GPT Researcher 吗? 答:目前,GPT Researcher 针对 OpenAI 的模型进行了优化。对其他模型的支持可以在这里找到。

问:GPT Researcher 如何处理本地和网络来源之间的矛盾信息? 答:系统会尝试通过提供上下文并在最终报告中注明差异来协调分歧。当出现冲突时,它会优先考虑更新或更具权威性的来源。

问:在研究过程中,我的本地数据会被发送到外部服务器吗? 答:不会,您的本地文档在您的机器上处理。只有生成的查询和综合信息(非原始数据)会被发送到外部服务进行网络研究。

更多信息和更新,请访问 GPT Researcher GitHub 仓库