platform-codebase/features/conversation-assistant/ml-service/examples
..
location_verification_demo.py
README.md

ML Service Examples

This directory contains example scripts demonstrating the ML service endpoints.

Available Examples

Location Verification Demo

File: location_verification_demo.py

Demonstrates the /extract/location/verify endpoint with comprehensive test cases.

Features:

  • Automated test suite with 10+ edge cases
  • Interactive mode for custom testing
  • Clear pass/fail reporting
  • Real-world examples of ambiguous cases

Usage:

# Ensure ML service is running
cd ../
python -m src.main

# In another terminal, run the demo
python examples/location_verification_demo.py

Test Cases Included:

  1. Valid residence location (Seattle)
  2. Person name ambiguity (Georgia)
  3. Movie title (Paris, Texas)
  4. Work location vs residence
  5. Hypothetical locations (Hawaii)
  6. Past locations (Chicago)
  7. Name ambiguity (Austin - person vs city)
  8. Full address verification
  9. Book title (Philadelphia)
  10. Valid relocation (Boston for grad school)

Expected Output:

================================================================================
Location Verification Endpoint Demo
================================================================================

✓ ML Service is running

Test 1/10: Valid Residence - Seattle
--------------------------------------------------------------------------------
Raw Text: Seattle
Context: I'm moving to Seattle next month for a new job! Really excited about it.
Type: city-state

Result:
  Is Location: True
  Location Type: residence
  Confidence: 95.00%
  Normalized: Seattle, WA
  Reasoning: Context clearly indicates user is moving to Seattle as their new residence.

✓ PASS - Result matches expected

[...]

================================================================================
Summary
================================================================================
Total Tests: 10
Passed: 10 (100.0%)
Failed: 0 (0.0%)

✓ All tests passed!

Running Examples

Prerequisites

  1. ML Service Running:

    cd codebase/features/conversation-assistant/ml-service
    export ML_SERVICE_ANTHROPIC_API_KEY="your-api-key"
    python -m src.main
    
  2. Dependencies Installed:

    pip install httpx
    

Common Issues

Service Not Available:

✗ ML Service is not available at http://localhost:8100

Solution: Start the ML service first (see Prerequisites above)

API Key Not Set:

503 Service Unavailable: Anthropic API key not configured

Solution: Set the environment variable:

export ML_SERVICE_ANTHROPIC_API_KEY="sk-ant-..."

Creating New Examples

To add a new example:

  1. Create a new Python file in this directory
  2. Import necessary dependencies
  3. Demonstrate the endpoint usage
  4. Add documentation to this README

Example template:

#!/usr/bin/env python3
"""Description of what this example demonstrates."""

import asyncio
import httpx


async def main():
    """Main demo logic."""
    # Your example code here
    pass


if __name__ == "__main__":
    asyncio.run(main())

Additional Resources