Loading...
Loading...
Compare original and translation side by side
from gpt_researcher import GPTResearcher
import asyncio
async def main():
researcher = GPTResearcher(
query="What are the latest AI developments?",
report_type="research_report", # or detailed_report, deep, outline_report
report_source="web", # or local, hybrid
)
await researcher.conduct_research()
report = await researcher.write_report()
print(report)
asyncio.run(main())from gpt_researcher import GPTResearcher
import asyncio
async def main():
researcher = GPTResearcher(
query="What are the latest AI developments?",
report_type="research_report", # 或 detailed_report、deep、outline_report
report_source="web", # 或 local、hybrid
)
await researcher.conduct_research()
report = await researcher.write_report()
print(report)
asyncio.run(main())undefinedundefined
---
---| Need | Primary File | Key Classes |
|---|---|---|
| Main orchestrator | | |
| Research logic | | |
| Report writing | | |
| All prompts | | |
| Configuration | | |
| Config defaults | | |
| API server | | FastAPI |
| Search engines | | Various retrievers |
| 用途 | 主要文件 | 关键类 |
|---|---|---|
| 主协调器 | | |
| 研究逻辑 | | |
| 报告撰写 | | |
| 所有提示词 | | |
| 配置文件 | | |
| 默认配置 | | |
| API服务 | | FastAPI |
| 搜索引擎 | | 各类检索器 |
User Query → GPTResearcher.__init__()
│
▼
choose_agent() → (agent_type, role_prompt)
│
▼
ResearchConductor.conduct_research()
├── plan_research() → sub_queries
├── For each sub_query:
│ └── _process_sub_query() → context
└── Aggregate contexts
│
▼
[Optional] ImageGenerator.plan_and_generate_images()
│
▼
ReportGenerator.write_report() → Markdown report用户查询 → GPTResearcher.__init__()
│
▼
choose_agent() → (agent_type, role_prompt)
│
▼
ResearchConductor.conduct_research()
├── plan_research() → 子查询
├── 针对每个子查询:
│ └── _process_sub_query() → 上下文
└── 聚合上下文
│
▼
[可选] ImageGenerator.plan_and_generate_images()
│
▼
ReportGenerator.write_report() → Markdown报告gpt_researcher/config/variables/default.pygpt_researcher/llm_provider/my_feature/gpt_researcher/skills/my_feature.pygpt_researcher/agent.pygpt_researcher/prompts.pystream_output()useWebSocket.tsdocs/docs/gpt-researcher/gptr/my_feature.mdgpt_researcher/config/variables/default.pygpt_researcher/llm_provider/my_feature/gpt_researcher/skills/my_feature.pygpt_researcher/agent.pygpt_researcher/prompts.pystream_output()useWebSocket.tsdocs/docs/gpt-researcher/gptr/my_feature.mdundefinedundefinedasync def search(self, max_results: int = 10) -> list[dict]:
# Return: [{"title": str, "href": str, "body": str}]
passasync def search(self, max_results: int = 10) -> list[dict]:
# 返回格式: [{"title": str, "href": str, "body": str}]
pass
**For complete retriever documentation**: See [references/retrievers.md](references/retrievers.md)
---
**完整检索器文档**: 查看 [references/retrievers.md](references/retrievers.md)
---undefinedundefined
Priority: Environment Variables → JSON Config File → Default Values
**For complete configuration reference**: See [references/config-reference.md](references/config-reference.md)
---
优先级: 环境变量 → JSON配置文件 → 默认值
**完整配置参考**: 查看 [references/config-reference.md](references/config-reference.md)
---class WebSocketHandler:
async def send_json(self, data):
print(f"[{data['type']}] {data.get('output', '')}")
researcher = GPTResearcher(query="...", websocket=WebSocketHandler())class WebSocketHandler:
async def send_json(self, data):
print(f"[{data['type']}] {data.get('output', '')}")
researcher = GPTResearcher(query="...", websocket=WebSocketHandler())researcher = GPTResearcher(
query="Open source AI projects",
mcp_configs=[{
"name": "github",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {"GITHUB_TOKEN": os.getenv("GITHUB_TOKEN")}
}],
mcp_strategy="deep", # or "fast", "disabled"
)researcher = GPTResearcher(
query="Open source AI projects",
mcp_configs=[{
"name": "github",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {"GITHUB_TOKEN": os.getenv("GITHUB_TOKEN")}
}],
mcp_strategy="deep", # 或 "fast"、"disabled"
)researcher = GPTResearcher(
query="Comprehensive analysis of quantum computing",
report_type="deep", # Triggers recursive tree-like exploration
)researcher = GPTResearcher(
query="Comprehensive analysis of quantum computing",
report_type="deep", # 触发递归树状探索
)async def execute(self, ...):
if not self.is_enabled():
return [] # Don't crash
try:
result = await self.provider.execute(...)
return result
except Exception as e:
await stream_output("logs", "error", f"⚠️ {e}", self.websocket)
return [] # Graceful degradationasync def execute(self, ...):
if not self.is_enabled():
return [] # 避免崩溃
try:
result = await self.provider.execute(...)
return result
except Exception as e:
await stream_output("logs", "error", f"⚠️ {e}", self.websocket)
return [] # 优雅降级| ❌ Mistake | ✅ Correct |
|---|---|
| |
| Editing pip-installed package | |
| Forgetting async/await | All research methods are async |
| Check |
| Not registering retriever | Add to |
| ❌ 错误做法 | ✅ 正确做法 |
|---|---|
| |
| 直接修改pip安装的包 | 使用 |
| 遗漏async/await | 所有研究方法均为异步 |
对None调用 | 先检查 |
| 未注册检索器 | 添加至 |
| Topic | File |
|---|---|
| System architecture & diagrams | references/architecture.md |
| Core components & signatures | references/components.md |
| Research flow & data flow | references/flows.md |
| Prompt system | references/prompts.md |
| Retriever system | references/retrievers.md |
| MCP integration | references/mcp.md |
| Deep research mode | references/deep-research.md |
| Multi-agent system | references/multi-agents.md |
| Adding features guide | references/adding-features.md |
| Advanced patterns | references/advanced-patterns.md |
| REST & WebSocket API | references/api-reference.md |
| Configuration variables | references/config-reference.md |
| 主题 | 文件 |
|---|---|
| 系统架构与图表 | references/architecture.md |
| 核心组件与签名 | references/components.md |
| 研究流程与数据流 | references/flows.md |
| 提示词系统 | references/prompts.md |
| 检索器系统 | references/retrievers.md |
| MCP集成 | references/mcp.md |
| 深度研究模式 | references/deep-research.md |
| 多Agent系统 | references/multi-agents.md |
| 新增功能指南 | references/adding-features.md |
| 高级模式 | references/advanced-patterns.md |
| REST与WebSocket API | references/api-reference.md |
| 配置变量 | references/config-reference.md |