-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_usage.py
More file actions
100 lines (74 loc) · 2.94 KB
/
example_usage.py
File metadata and controls
100 lines (74 loc) · 2.94 KB
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
94
95
96
97
98
99
100
"""Example usage showing TruthLayer with well-matched content."""
from src.verifier.verifier import TruthLayerVerifier
def example_verified():
"""Example showing verified claims."""
print("=" * 70)
print("Example 1: Verified Claims")
print("=" * 70)
verifier = TruthLayerVerifier()
ai_response = """
The Eiffel Tower is located in Paris, France. It was completed in 1889.
The tower stands 330 meters tall and was designed by Gustave Eiffel.
"""
source_documents = [
"The Eiffel Tower is located in Paris, France and was completed in 1889.",
"The tower stands 330 meters tall and was designed by Gustave Eiffel."
]
result = verifier.verify(ai_response, source_documents)
print_results(result)
def example_mixed():
"""Example showing mixed verification results."""
print("\n" + "=" * 70)
print("Example 2: Mixed Results")
print("=" * 70)
verifier = TruthLayerVerifier()
ai_response = """
The company was founded in 2020 and has 500 employees.
It operates in 15 countries worldwide.
The CEO is John Smith and revenue reached $100 million last year.
"""
source_documents = [
"The company was founded in 2020 and currently has 500 employees.",
"Operations span across 15 countries globally."
]
result = verifier.verify(ai_response, source_documents)
print_results(result)
def example_unsupported():
"""Example showing unsupported claims."""
print("\n" + "=" * 70)
print("Example 3: Unsupported Claims")
print("=" * 70)
verifier = TruthLayerVerifier()
ai_response = """
The product was launched in March 2023.
It has received over 10,000 downloads in the first month.
"""
source_documents = [
"Our company focuses on software development and cloud services.",
"We have a team of experienced engineers working on various projects."
]
result = verifier.verify(ai_response, source_documents)
print_results(result)
def print_results(result):
"""Print verification results in a readable format."""
status_symbols = {
"VERIFIED": "✅",
"UNCERTAIN": "⚠️",
"UNSUPPORTED": "❌"
}
print("\nClaims:")
for i, claim in enumerate(result["claims"], 1):
symbol = status_symbols.get(claim["status"], "?")
print(f"\n{i}. {claim['text']}")
print(f" {symbol} {claim['status']} ({claim['confidence']}%)")
print(f"\nSummary: ✅ {result['summary']['verified']} | "
f"⚠️ {result['summary']['uncertain']} | "
f"❌ {result['summary']['unsupported']}")
if __name__ == "__main__":
example_verified()
example_mixed()
example_unsupported()
print("\n" + "=" * 70)
print("Note: TF-IDF embeddings have limitations. Real semantic embeddings")
print("(like AWS Bedrock) will provide much better accuracy.")
print("=" * 70)