File size: 3,555 Bytes
908ff10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"""Test the benchmark agent with sample classified clauses."""

import json
import os
from agents.benchmark_agent import benchmark_clause, benchmark_node

OUTPUT_DIR = os.path.join(os.path.dirname(__file__), "..", "outputs")

SAMPLE_RISK_SCORED_CLAUSES = [
    {
        "id": 1,
        "text": "This Agreement shall be governed by and construed in accordance with the laws of the State of Delaware.",
        "section": "General",
        "clause_type": "Governing Law",
        "confidence": 0.99,
        "risk_score": 0.20,
        "risk_factors": ["Missing forum selection clause"],
    },
    {
        "id": 2,
        "text": "During the term of this Agreement and for a period of two years thereafter, the Employee shall not directly or indirectly engage in any business that competes with the Company.",
        "section": "Restrictive Covenants",
        "clause_type": "Non-Compete",
        "confidence": 0.95,
        "risk_score": 0.72,
        "risk_factors": ["Overly broad scope", "No geographic limitation"],
    },
    {
        "id": 3,
        "text": "Either party may terminate this Agreement at any time upon thirty (30) days prior written notice to the other party.",
        "section": "Termination",
        "clause_type": "Termination For Convenience",
        "confidence": 0.95,
        "risk_score": 0.75,
        "risk_factors": ["No wind-down costs", "No cure period"],
    },
    {
        "id": 4,
        "text": "The Company shall indemnify and hold harmless the Contractor from any claims, damages, or expenses arising from the Company's breach of this Agreement.",
        "section": "Liability",
        "clause_type": "Indemnification",
        "confidence": 0.95,
        "risk_score": 0.72,
        "risk_factors": ["One-directional only", "Narrow scope"],
    },
    {
        "id": 5,
        "text": "The Licensor grants to the Licensee a non-exclusive, non-transferable license to use the Software solely for internal business purposes.",
        "section": "License",
        "clause_type": "Non-Transferable License",
        "confidence": 0.95,
        "risk_score": 0.65,
        "risk_factors": ["Undefined internal business purposes"],
    },
]


def test_single_benchmark():
    """Test benchmarking a single clause."""
    clause = SAMPLE_RISK_SCORED_CLAUSES[1]  # Non-compete
    result = benchmark_clause(clause["text"], clause["clause_type"])
    print(f"Clause: {clause['text'][:80]}...")
    print(f"Type:       {clause['clause_type']}")
    print(f"Similarity: {result['benchmark_similarity']}")
    print(f"Deviations: {result['deviations']}")
    print(f"Standard:   {result['standard_language_summary']}")
    print(f"Why:        {result['reasoning']}")
    print()


def test_benchmark_node():
    """Test the full LangGraph node with multiple clauses."""
    state = {"risk_scores": SAMPLE_RISK_SCORED_CLAUSES}
    result = benchmark_node(state)

    print(f"{'ID':<4} {'Type':<30} {'Similarity':<12} {'Source'}")
    print("-" * 80)
    for clause in result["benchmark_results"]:
        print(f"{clause['id']:<4} {clause['clause_type']:<30} {clause['benchmark_similarity']:<12.2f} {clause['benchmark_source']}")

    output_path = os.path.join(OUTPUT_DIR, "benchmark_results.json")
    with open(output_path, "w") as f:
        json.dump(result["benchmark_results"], f, indent=2)
    print(f"\nResults saved to {output_path}")


if __name__ == "__main__":
    print("Single Clause Benchmark Test\n")
    test_single_benchmark()

    print("Full Node Test\n")
    test_benchmark_node()