1313from mellea .backends .huggingface import LocalHFBackend
1414from mellea .stdlib .components import Document , Message
1515from mellea .stdlib .context import ChatContext
16- from mellea .stdlib .requirements .rag import CitationRequirement
16+ from mellea .stdlib .requirements .rag import CitationMode , CitationRequirement
1717
1818
1919async def main ():
@@ -64,16 +64,42 @@ async def main():
6464 )
6565 print (f"Reason: { reason_preview } " )
6666
67- # Example 2: Higher coverage threshold
68- print ("\n --- Example 2: Higher coverage threshold (80%) ---" )
69- req2 = CitationRequirement (min_citation_coverage = 0.8 , documents = docs )
67+ # Example 2: CLAIMS mode (default) - counts fraction of claims with citations
68+ print ("\n --- Example 2: CLAIMS mode (default) - fraction of claims cited ---" )
69+ req2 = CitationRequirement (
70+ min_citation_coverage = 0.7 , documents = docs , mode = CitationMode .CLAIMS
71+ )
7072 result2 = await req2 .validate (backend , ctx )
7173
7274 print (f"Validation passed: { result2 .as_bool ()} " )
7375 print (f"Citation coverage score: { result2 .score :.2%} " )
76+ if result2 .reason :
77+ reason_preview = (
78+ result2 .reason [:200 ] + "..."
79+ if len (result2 .reason ) > 200
80+ else result2 .reason
81+ )
82+ print (f"Reason: { reason_preview } " )
83+
84+ # Example 3: CHARACTERS mode - calculates character-based coverage
85+ print ("\n --- Example 3: CHARACTERS mode - character-based coverage ---" )
86+ req3 = CitationRequirement (
87+ min_citation_coverage = 0.7 , documents = docs , mode = CitationMode .CHARACTERS
88+ )
89+ result3 = await req3 .validate (backend , ctx )
90+
91+ print (f"Validation passed: { result3 .as_bool ()} " )
92+ print (f"Citation coverage score: { result3 .score :.2%} " )
93+ if result3 .reason :
94+ reason_preview = (
95+ result3 .reason [:200 ] + "..."
96+ if len (result3 .reason ) > 200
97+ else result3 .reason
98+ )
99+ print (f"Reason: { reason_preview } " )
74100
75- # Example 3 : Documents attached to message
76- print ("\n --- Example 3 : Documents in message (not constructor) ---" )
101+ # Example 4 : Documents attached to message
102+ print ("\n --- Example 4 : Documents in message (not constructor) ---" )
77103 ctx2 = ChatContext ().add (Message ("user" , "Tell me about Mars." ))
78104 ctx2 = ctx2 .add (
79105 Message (
@@ -85,11 +111,11 @@ async def main():
85111 )
86112 )
87113
88- req3 = CitationRequirement (min_citation_coverage = 0.7 ) # No documents in constructor
89- result3 = await req3 .validate (backend , ctx2 )
114+ req4 = CitationRequirement (min_citation_coverage = 0.7 ) # No documents in constructor
115+ result4 = await req4 .validate (backend , ctx2 )
90116
91- print (f"Validation passed: { result3 .as_bool ()} " )
92- print (f"Citation coverage score: { result3 .score :.2%} " )
117+ print (f"Validation passed: { result4 .as_bool ()} " )
118+ print (f"Citation coverage score: { result4 .score :.2%} " )
93119
94120 print ("\n " + "=" * 70 )
95121 print ("Example completed successfully!" )
0 commit comments