164 使用LlamaParse增强功能

使用LlamaParse增强功能

在之前的示例中,我们向文档提出了一个非常基本的问题,即预算总额。让我们改为询问文档中一个更复杂的具体事实:

documents = SimpleDirectoryReader("./data").load_data()
index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine()

response = query_engine.query(
    "How much exactly was allocated to a tax credit to promote investment in green technologies in the 2023 Canadian federal budget?"
)
print(response)

不幸的是,我们得到了一个无用的答案:

The budget allocated funds to a new green investments tax credit, but the exact amount was not specified in the provided context information.

这很糟糕,因为我们恰好知道确切的数字在文档中!但PDF很复杂,有表格和多列布局,LLM错过了答案。幸运的是,我们可以使用LlamaParse来帮助我们。

首先,你需要一个LlamaCloud API密钥。你可以通过注册LlamaCloud免费获得一个。然后像你的OpenAI密钥一样将其放在你的.env文件中:

LLAMA_CLOUD_API_KEY=llx-xxxxx

现在你可以在代码中使用LlamaParse了。让我们将其作为导入引入:

from llama_parse import LlamaParse

让我们进行第二次尝试来解析和查询文件(注意这使用了documents2、index2等),看看我们是否能得到更好的答案:

documents2 = LlamaParse(result_type="markdown").load_data(
    "./data/2023_canadian_budget.pdf"
)
index2 = VectorStoreIndex.from_documents(documents2)
query_engine2 = index2.as_query_engine()

response2 = query_engine2.query(
    "How much exactly was allocated to a tax credit to promote investment in green technologies in the 2023 Canadian federal budget?"
)
print(response2)

我们得到了!

$20 billion was allocated to a tax credit to promote investment in green technologies in the 2023 Canadian federal budget.

你可以随时查看仓库以了解这段代码的样子。

正如你所见,解析质量对LLM的理解有很大影响,即使是相对简单的问题。接下来,我们来看看如何使用记忆来帮助我们回答更复杂的问题。

关于 LlamaParse 的定价或费用结构,通常这类服务会依据使用量、功能需求以及订阅计划来制定价格策略。然而,具体的价格信息可能不会公开显示在文档中,而是通过联系销售团队获取详细的报价单[^1]。 对于大多数基于云的服务平台而言,其常见的收费模式可以分为以下几个方面: ### 1. 基础订阅费 一些服务商提供基础级别的订阅方案,这些方案适合小型项目或者个人开发者测试用途。此部分可能会有免费层 (Free Tier),允许有限次数的操作执行而无需支付任何费用[^2]。 ### 2. 数据处理成本 如果涉及到大量数据解析和存储,则这部分开销取决于上传文件大小、数量以及复杂度等因素。每单位的数据操作都会被计价,并反映到最终账单上[^3]。 ### 3. 高级特性解锁 当用户需要更高级别的支持和服务时(如优先客服响应时间、专属实例部署等),则需额外付费以获得此类特权访问权限[^4]。 以下是 Python 中模拟计算总花费的一个简单例子: ```python def calculate_total_cost(base_fee, data_processing_rate, num_operations): total = base_fee + (data_processing_rate * num_operations) return round(total, 2) # Example usage of the function with hypothetical values example_base_fee = 50.00 # Base subscription fee per month ($USD) example_data_rate = 0.01 # Cost per operation on processed data ($USD/op.) operations_count = 1000 # Number of operations expected monthly estimated_monthly_cost = calculate_total_cost(example_base_fee, example_data_rate, operations_count) print(f"Estimated Monthly Cost: ${estimated_monthly_cost}") ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

需要重新演唱

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值