跳转到内容

合同类型分类

在此示例中,我们将使用LlamaClassify和llama-cloud-services Python SDK按类型对各类合同进行分类。当提供文件时,我们会将其分类为co_branding合同或affiliate_agreement合同。

例如,我们将使用 CUAD 数据集,其中包含各类合同,例如:关联方协议、联合品牌合同、特许经营合同等。

下面的示例同样可以在LlamaCloud中复现,您还可以通过用户界面创建分类规则,而无需在代码中定义它们:

!pip install llama-cloud-services

首先,我们建议从“联盟协议”和“联合品牌”部分下载几份合同。

要开始使用,请确保提供您的 Llama Cloud API 密钥。

import os
from getpass import getpass
if "LLAMA_CLOUD_API_KEY" not in os.environ:
os.environ["LLAMA_CLOUD_API_KEY"] = getpass("Enter your Llama Cloud API Key: ")
from llama_cloud_services.beta.classifier.client import ClassifyClient
from llama_cloud.client import AsyncLlamaCloud
client = AsyncLlamaCloud(token=os.environ["LLAMA_CLOUD_API_KEY"])
project_id = "your-project-id"
organization_id = "your-organization-id"
classifier = ClassifyClient(client, project_id=project_id, organization_id=organization_id)

在这个示例中,我们将范围缩小到对 co_brandingaffiliate_agreements 类型进行分类:

from llama_cloud.types import ClassifierRule
rules = [
ClassifierRule(
type="affiliate_agreements",
description="This is a contract that outlines an affiliate agreement",
),
ClassifierRule(
type="co_branding",
description="This is a contract that outlines a co-branding deal/agreement",
),
]

最后,我们可以对文件(或多个文件)进行分类:

result = await classifier.aclassify_file_path(
rules=rules,
file_input_path="CybergyHoldingsInc_Affliate Agreement.pdf",
)

分类完成后,结果不仅会包含文件被归类为的合同类型,还会包含LlamaClassify对此分类的推理过程。 例如,在这种情况下我们得到的结果如下:

classification = result.items[0].result
print("Classification Result: " + classification.type)
print("Classification Reason: " + classification.reasoning)
Classification Result: affiliate_agreements
Classification Reason: The document is titled 'MARKETING AFFILIATE AGREEMENT' and repeatedly refers to one party as the 'Marketing Affiliate.' The agreement outlines the rights and obligations of the 'Marketing Affiliate' (MA) to market, sell, and support certain technology products, and details the relationship between the company and the affiliate. There is no mention of joint branding, shared trademarks, or collaborative marketing under both parties' brands, which would be indicative of a co-branding agreement. The content is entirely consistent with an affiliate agreement, where one party (the affiliate) is authorized to market and sell the products of another company, rather than a co-branding arrangement. Therefore, the best match is 'affiliate_agreements' with very high confidence.