File size: 2,623 Bytes
3d69d54 |
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 |
"""Example usage of MbazaAI"""
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
from mbaza_ai import LegalAI, CountryDatasetLoader, Config
from mbaza_ai.utils import setup_logging
# Setup logging
setup_logging("INFO")
def main():
# Initialize the MbazaAI system
print("ποΈ Initializing MbazaAI...")
config = Config()
dataset_loader = CountryDatasetLoader(config)
legal_ai = LegalAI(config, dataset_loader)
print(f"π Current country: {dataset_loader.current_country}")
print(f"π Available countries: {', '.join(config.get_available_countries())}")
# Example questions
questions = [
"What are the requirements for Rwandan citizenship?",
"What is the penalty for theft in Rwanda?",
"What are the basic constitutional rights?",
]
print("\n" + "="*60)
print("π€ MbazaAI Legal Question Answering Demo")
print("="*60)
# Ask questions to the current dataset (Rwanda)
for question in questions:
print(f"\nβ Question: {question}")
result = legal_ai.predict(question)
print(f"β
Answer: {result['answer']}")
print(f"π― Confidence: {result['confidence']:.2f}")
print(f"π Category: {result.get('category', 'N/A')}")
print("-" * 40)
# Demonstrate adding a new country
print("\nπ Adding a new country (Kenya)...")
config.add_country(
country_code="kenya",
name="Kenya",
dataset_path="datasets/kenya/legal_data.json",
language="en",
legal_system="common_law"
)
print(f"β
Updated available countries: {', '.join(config.get_available_countries())}")
# Switch to Kenya (will create sample data)
print("\nπ Switching to Kenya legal dataset...")
if legal_ai.switch_country("kenya"):
print("β
Successfully switched to Kenya!")
# Ask a question in the new context
result = legal_ai.predict("What are the basic rights in Kenya?")
print(f"\nβ Question: What are the basic rights in Kenya?")
print(f"β
Answer: {result['answer']}")
print(f"π Country: {result['country']}")
# Show model information
print("\n" + "="*40)
print("π Model Information")
print("="*40)
info = legal_ai.get_model_info()
print(f"Model: {info['model_name']}")
print(f"Current Country: {info['country']}")
print(f"Legal Categories: {', '.join(info['legal_categories'])}")
print("\nπ Demo completed successfully!")
if __name__ == "__main__":
main() |