-
Notifications
You must be signed in to change notification settings - Fork 0
DEMO_GUIDE
This guide walks you through running a complete PATAS demo, from setup to viewing results.
- Python 3.9 or higher
- Poetry installed (installation guide)
- LLM provider API key (optional, for LLM-powered pattern mining, e.g., OpenAI)
# Clone the repository (or use your local copy)
git clone <repository-url>
cd PATAS
# Install dependencies
poetry install
# Copy environment template
cp .env.example .envIf you want to use LLM-powered pattern mining, add your LLM provider API key to .env:
# For OpenAI (default)
OPENAI_API_KEY=your-key-here
# or
PATAS_OPENAI_API_KEY=your-key-hereNote: PATAS works without LLM, but LLM enhances pattern discovery quality.
# Option 1: Using uvicorn directly
poetry run uvicorn app.api.main:app --host 0.0.0.0 --port 8000
# Option 2: Using the CLI entry point
poetry run patas-api
# Option 3: Using the demo script (it will check if server is running)The API will be available at http://localhost:8000
Verify it's running:
curl http://localhost:8000/api/v1/healthYou should see:
{"status": "ok"}./docs/run_demo.shThe script will:
- Check if the API is running
- Send the demo dataset to
/api/v1/analyze - Display results in the terminal
- Save results to
docs/demo_results.json
curl -X POST http://localhost:8000/api/v1/analyze \
-H "Content-Type: application/json" \
-d @- <<EOF
{
"messages": $(cat docs/demo_messages.json),
"run_mining": true,
"run_evaluation": true,
"export_backend": "sql"
}
EOFimport requests
import json
# Load demo messages
with open('docs/demo_messages.json') as f:
messages = json.load(f)
# Send request
response = requests.post(
'http://localhost:8000/api/v1/analyze',
json={
'messages': messages,
'run_mining': True,
'run_evaluation': True,
'export_backend': 'sql'
}
)
# Print results
print(json.dumps(response.json(), indent=2))The response includes several key sections:
{
"patterns": [
{
"id": 1,
"type": "URL",
"description": "Suspicious URL pattern: http://spam-shop.com"
}
]
}These are spam patterns discovered in your messages.
{
"rules": [
{
"id": 1,
"pattern_id": 1,
"status": "candidate",
"sql_expression": "SELECT id FROM messages WHERE text LIKE '%spam-shop.com%'",
"precision": 0.95,
"coverage": 0.15
}
]
}These are blocking rules generated from the patterns.
{
"export": "SELECT id FROM messages WHERE text LIKE '%spam-shop.com%';\n..."
}Ready-to-deploy SQL rules (if export_backend: "sql" was requested).
{
"meta": {
"ingested_count": 10,
"patterns_created": 3,
"rules_created": 3,
"evaluation_count": 3,
"timings": {
"ingest_seconds": 0.123,
"mining_seconds": 2.456,
"evaluation_seconds": 0.789,
"total_seconds": 3.368
}
}
}Statistics about the analysis process.
Edit docs/demo_messages.json:
[
{
"id": "custom_001",
"text": "Your spam message here",
"is_spam": true,
"meta": {"lang": "en"}
},
{
"id": "custom_002",
"text": "Your legitimate message here",
"is_spam": false,
"meta": {"lang": "en"}
}
]{
"messages": [...],
"run_mining": true, // Enable pattern mining
"run_evaluation": true, // Enable rule evaluation
"export_backend": "sql" // Export format: "sql" or "rol"
}{
"export_backend": "rol" // ROL (Rule Object Language) format
}Error: API server is not running
Solution: Start the API server first (see Step 2)
Error: Database connection issues
Solution: PATAS uses SQLite by default. Ensure data/ directory exists and is writable:
mkdir -p dataError: LLM provider API errors
Solution:
- Check your API key in
.env - Or disable LLM by setting
run_mining: false(pattern mining will use rule-based extraction only)
Error: Address already in use
Solution: Use a different port:
poetry run uvicorn app.api.main:app --host 0.0.0.0 --port 8001Then update the demo script or use API_URL=http://localhost:8001 ./docs/run_demo.sh
- API Quickstart - Learn how to integrate PATAS into your system
- Use Cases - See real-world scenarios
- Overview - Understand how PATAS works
The demo includes 10 sample messages:
- 7 spam messages (various patterns: URLs, phone numbers, keywords)
- 3 legitimate messages
This small dataset demonstrates PATAS capabilities. For production use, analyze larger datasets (hundreds or thousands of messages) for better pattern discovery.
Tip: Save the results JSON and explore the discovered patterns and generated rules. This gives you a sense of what PATAS can do with your own data.