|
…
|
||
|---|---|---|
| .. | ||
| 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:
- Valid residence location (Seattle)
- Person name ambiguity (Georgia)
- Movie title (Paris, Texas)
- Work location vs residence
- Hypothetical locations (Hawaii)
- Past locations (Chicago)
- Name ambiguity (Austin - person vs city)
- Full address verification
- Book title (Philadelphia)
- 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
-
ML Service Running:
cd codebase/features/conversation-assistant/ml-service export ML_SERVICE_ANTHROPIC_API_KEY="your-api-key" python -m src.main -
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:
- Create a new Python file in this directory
- Import necessary dependencies
- Demonstrate the endpoint usage
- 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())