Chinookgrpotest / civil_engineering_example.py
ziadrone's picture
Upload folder using huggingface_hub
4faf887 verified
from civil_engineering_rag_verifier import CivilEngineeringRAGVerifier
def main():
# Initialize the verifier
verifier = CivilEngineeringRAGVerifier(similarity_threshold=0.7)
# Example model response for a structural engineering question
model_response = """
For a reinforced concrete beam with a span of 6 m carrying a uniform load of 25 kN/m:
1. The maximum bending moment will be approximately 112.5 kNm at midspan.
2. Assuming a concrete strength of 30 MPa and steel yield strength of 500 MPa, a beam depth of 450 mm would be appropriate.
3. The minimum reinforcement ratio should be 0.3% according to ACI 318.
4. The beam should have a minimum width of 250 mm to accommodate the required reinforcement.
5. Shear reinforcement with 10 mm diameter stirrups at 200 mm spacing will be sufficient near the supports.
"""
# Example retrieved engineering documents
retrieved_documents = [
{
"content": "For simply supported beams with uniform loading (w), the maximum bending moment occurs at midspan and equals wL²/8, where L is the span length.",
"source": "structural_engineering_handbook_p127"
},
{
"content": "ACI 318 specifies a minimum flexural reinforcement ratio of 0.33% for beams using Grade 60 (420 MPa) steel. For higher strength steels, this may be adjusted.",
"source": "concrete_design_manual"
},
{
"content": "For concrete with compressive strength of 30 MPa and steel with yield strength of 500 MPa, recommended beam depths typically range from L/12 to L/15 for normal loading conditions.",
"source": "design_guidelines"
},
{
"content": "Shear reinforcement spacing should not exceed d/2 or 600 mm, whichever is smaller, where d is the effective depth of the beam.",
"source": "code_provisions"
}
]
# Verify the response
is_verified, modified_response, verification_details = verifier.verify_response(
model_response,
retrieved_documents
)
# Print results
print(f"Response verified: {is_verified}")
print(f"Verification score: {verification_details['verification_score']:.2f}")
print(f"Claims verified: {verification_details['claims_verified']}/{verification_details['total_claims']}")
print(f"Units verified: {verification_details['units_verified']}/{verification_details['total_units']}")
print("\nOriginal response:")
print(model_response)
if not is_verified:
print("\nModified response with verification:")
print(modified_response)
print("\nDetailed verification results:")
print("\nTechnical Claims:")
for claim_result in verification_details['claim_details']:
status = "✓" if claim_result['verified'] else "✗"
print(f"{status} {claim_result['claim']}")
print("\nUnits and Values:")
for unit_result in verification_details['unit_details']:
status = "✓" if unit_result['verified'] else "✗"
print(f"{status} {unit_result['unit_value']}")
if __name__ == "__main__":
main()