Skip to main content

AI Integration - Aqua GPT

AquaGen API integrates OpenAI's GPT-4 to provide intelligent insights, anomaly detection, and recommendations for water management. This feature is called Aqua GPT.

🤖 Overview

Aqua GPT is a specialized AI assistant that understands water management data and provides:

  • Automated Analysis: Analyze consumption patterns and trends
  • Anomaly Detection: Identify unusual patterns in water/energy data
  • Predictive Insights: Forecast future consumption and requirements
  • Optimization Recommendations: Suggest operational improvements
  • Natural Language Reports: Generate executive summaries in plain English

🎯 Features

1. Automated Report Analysis

Aqua GPT analyzes your water management data and generates insights automatically.

Example Request:

curl -X GET "https://api.aquagen.com/api/user/report?\
reportType=summary&\
reportFormat=pdf&\
service=aqua_gpt&\
startDate=01/11/2024&\
endDate=30/11/2024" \
-H "Authorization: Bearer YOUR_TOKEN"

What Aqua GPT Analyzes:

  • Daily and monthly consumption patterns
  • Peak vs. off-peak usage
  • Efficiency metrics
  • Cost implications
  • Sustainability indicators

2. Anomaly Detection

Automatically detect unusual patterns in your data.

Types of Anomalies Detected:

Anomaly TypeDescriptionExample
SpikeSudden increase in consumption150% above average
DropUnexpected decrease50% below normal
Pattern BreakDeviation from typical patternWeekend usage on weekday
Sustained IncreaseGradual upward trend10% increase over weeks
Equipment IssueSigns of malfunctionErratic readings

Example Insight:

⚠️ Anomaly Detected: Water consumption on November 15, 2024, was 1,245 KL, which is 45% higher than the average of 858 KL. This spike occurred between 2 PM and 5 PM, suggesting a potential leak in the distribution system or unusual operational activity.

3. Predictive Analytics

Forecast future consumption based on historical patterns.

Predictions Include:

  • Next day/week/month consumption forecast
  • Peak demand prediction
  • Resource requirement planning
  • Cost projections

Example Prediction:

📊 Forecast for December 2024: Based on November's consumption pattern and seasonal trends, we predict:

  • Total consumption: 42,500 KL (±5%)
  • Peak day: December 24 (~1,600 KL)
  • Estimated cost: ₹8,50,000

4. Optimization Recommendations

AI-powered suggestions to improve efficiency.

Recommendation Categories:

Example Recommendations:

💡 Optimization Opportunities:

  1. Shift Peak Load: Moving 30% of operations to off-peak hours (10 PM - 6 AM) could reduce energy costs by ₹45,000/month
  2. Fix Leakages: Detected consistent nighttime flow of 12 KL suggests minor leaks. Estimated loss: ₹8,400/month
  3. Equipment Efficiency: Pump efficiency has dropped 15% over 3 months. Maintenance could save 120 kWh/day

5. Natural Language Summaries

Convert complex data into easy-to-understand executive summaries.

Example Summary:

Executive Summary - November 2024

Overall Performance: Good ✅

Total water consumption for November was 38,542 KL, which is 3.2% lower than October and 5% below the annual average. This reduction is attributed to improved operational efficiency and successful leak repairs implemented in mid-October.

Key Highlights:

  • Energy consumption decreased by 8%, saving ₹32,000
  • Water quality parameters consistently met regulatory standards
  • Zero critical alerts during the month

Areas of Concern:

  • Groundwater extraction increased by 12%, indicating higher reliance on borewells
  • Overhead tank level fluctuations suggest potential supply inconsistencies

Recommendations:

  1. Investigate and address borewell dependency
  2. Review municipal water supply schedule
  3. Consider rainwater harvesting expansion

🔧 Technical Implementation

Architecture

Service Components

1. Aqua GPT Service (app/services/gpt/)

services/gpt/
├── gpt.py # Main GPT service
├── gpt_handler.py # Request handling
├── gpt_config.py # Configuration
├── aquagpt/ # Aqua GPT implementation
│ ├── aqua_gpt_assistant.py
│ └── aqua_gpt_service.py
├── templates/ # Prompt templates
│ ├── analysis_prompt.txt
│ ├── anomaly_detection_prompt.txt
│ └── recommendation_prompt.txt
└── utils/ # Utility functions
├── data_preparation.py
└── response_formatter.py

2. Configuration (app/config.py)

class Config:
AQUA_GPT_API_KEY = smi.get(SecretName.AQUA_GPT_API_KEY)
AQUA_GPT_ASSISTANT_ID = smi.get(SecretName.AQUA_GPT_ASSISTANT_ID)
AQUA_GPT_MODEL = smi.get(SecretName.AQUA_GPT_MODEL) # gpt-4

Data Preparation

Input Data Structure:

{
"industryName": "Acme Industries",
"period": {
"start": "2024-11-01",
"end": "2024-11-30"
},
"consumption": {
"water": {
"total": 38542,
"unit": "KL",
"daily_average": 1284.7,
"peak_day": "2024-11-15",
"peak_value": 1685
},
"energy": {
"total": 125678,
"unit": "kWh",
"cost": 880000
}
},
"quality": {
"parameters": [...],
"compliance": "100%"
},
"alerts": {
"total": 12,
"critical": 0,
"high": 3
},
"devices": {
"total": 25,
"online": 24,
"offline": 1
}
}

Prompt Engineering

Analysis Prompt Template:

You are Aqua GPT, an AI assistant specializing in water management and industrial utilities.

Analyze the following water consumption data for {industry_name} for the period {start_date} to {end_date}:

{data_summary}

Provide insights on:
1. Overall consumption patterns and trends
2. Comparison with historical averages
3. Identification of anomalies or unusual patterns
4. Cost analysis and efficiency metrics
5. Sustainability indicators

Format your response as an executive summary suitable for management review.

Anomaly Detection Prompt:

Analyze this time-series water consumption data for anomalies:

{time_series_data}

Detect:
- Sudden spikes or drops (>30% deviation)
- Pattern breaks (unusual timing)
- Sustained trends (gradual changes)
- Equipment issues (erratic behavior)

For each anomaly:
- Timestamp
- Type of anomaly
- Magnitude
- Possible causes
- Recommended action

Recommendation Prompt:

Based on the water and energy consumption analysis:

{analysis_results}

Provide actionable recommendations for:
1. Cost reduction opportunities
2. Operational efficiency improvements
3. Sustainability enhancements
4. Predictive maintenance needs

Prioritize recommendations by:
- Impact (High/Medium/Low)
- Effort required
- Expected ROI
- Implementation timeline

🎨 Usage Examples

Example 1: Monthly AI Report

import requests

url = "https://api.aquagen.com/api/user/report"

params = {
'reportType': 'summary',
'reportFormat': 'pdf',
'service': 'aqua_gpt',
'startDate': '01/11/2024',
'endDate': '30/11/2024'
}

headers = {
'Authorization': 'Bearer YOUR_TOKEN'
}

response = requests.get(url, params=params, headers=headers)

with open('aqua_gpt_report_november.pdf', 'wb') as f:
f.write(response.content)

Example 2: Real-time Anomaly Detection

from app.services.gpt.aquagpt import AquaGPTService

# Initialize service
aqua_gpt = AquaGPTService(industry_id='industry-123')

# Analyze today's data
analysis = aqua_gpt.analyze_anomalies(
start_date='09/11/2024',
end_date='09/11/2024',
unit_id='unit-456'
)

print(analysis['anomalies'])
# Output:
# [
# {
# 'timestamp': '2024-11-09T14:30:00Z',
# 'type': 'spike',
# 'value': 1685,
# 'deviation': '+45%',
# 'severity': 'high',
# 'possible_causes': ['leak', 'unusual_operation'],
# 'recommendation': 'Inspect distribution system'
# }
# ]

Example 3: Predictive Forecast

# Get next month's forecast
forecast = aqua_gpt.predict_consumption(
forecast_period='monthly',
horizon_days=30
)

print(forecast['prediction'])
# Output:
# {
# 'period': 'December 2024',
# 'predicted_consumption': 42500,
# 'confidence_interval': {
# 'lower': 40375, # -5%
# 'upper': 44625 # +5%
# },
# 'peak_day': '2024-12-24',
# 'peak_value': 1600,
# 'factors': [
# 'seasonal_trend',
# 'historical_pattern',
# 'operational_schedule'
# ]
# }

Example 4: Custom Analysis

# Custom analysis with specific focus areas
custom_analysis = aqua_gpt.custom_analysis(
data=consumption_data,
focus_areas=['cost_optimization', 'sustainability'],
output_format='json'
)

print(custom_analysis['recommendations'])

🔐 Security & Privacy

Data Handling

  • Data Anonymization: Sensitive information is removed before sending to OpenAI
  • Aggregation: Individual readings are aggregated to summary statistics
  • Encryption: All API calls use HTTPS/TLS
  • Audit Logs: All AI interactions are logged in aqua_gpt_container

Privacy Considerations

What is sent to OpenAI:

  • ✅ Aggregated consumption data (totals, averages)
  • ✅ Trends and patterns
  • ✅ Statistical summaries
  • ✅ Industry type and size

What is NOT sent:

  • ❌ User personally identifiable information (PII)
  • ❌ Specific location coordinates
  • ❌ Raw sensor readings
  • ❌ Authentication tokens
  • ❌ Customer names/contacts

Compliance

  • GDPR Compliant: No personal data sent to third parties
  • Data Retention: AI conversation logs retained for 90 days
  • Opt-out: Industries can disable AI features

💰 Costs

OpenAI API Pricing

ModelInput (per 1M tokens)Output (per 1M tokens)
GPT-4 Turbo$10$30
GPT-3.5 Turbo$0.50$1.50

Estimated Costs (per month):

UsageTokens/RequestRequests/MonthCost (GPT-4)
Light (daily summaries)5,00030~$5
Medium (weekly analysis)10,000120~$35
Heavy (real-time anomaly)3,0001,000~$90
Cost Optimization

Use GPT-3.5 Turbo for routine analysis and GPT-4 for complex insights. Configure in AQUA_GPT_MODEL.

🎯 Best Practices

1. Effective Prompts

Do:

  • ✅ Provide clear context and objectives
  • ✅ Include relevant historical data
  • ✅ Specify desired output format
  • ✅ Use structured data formats

Don't:

  • ❌ Send raw, unprocessed data
  • ❌ Include sensitive information
  • ❌ Make vague requests
  • ❌ Exceed token limits (8K for GPT-4)

2. Optimal Usage

  • Use Aqua GPT for executive summaries and strategic insights
  • Don't use for real-time control or critical decision-making
  • Combine AI insights with human expertise
  • Review and validate AI recommendations before implementation

3. Performance Optimization

  • Cache results: Store AI analyses for repeated access
  • Batch requests: Analyze multiple units together
  • Async processing: Generate reports in background
  • Rate limiting: Respect OpenAI API rate limits

🐛 Troubleshooting

Error: "AI service unavailable"

Causes:

  • OpenAI API outage
  • Invalid API key
  • Rate limit exceeded

Solutions:

# Implement retry logic
import time
from tenacity import retry, stop_after_attempt, wait_exponential

@retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=4, max=10))
def call_aqua_gpt():
return aqua_gpt.analyze(...)

Poor Quality Insights

Causes:

  • Insufficient data
  • Poor data quality
  • Vague prompts

Solutions:

  • Ensure at least 7 days of data
  • Clean and validate data before analysis
  • Use specific, detailed prompts
  • Provide context about industry operations

AI-Powered Insights

Aqua GPT helps you make data-driven decisions for water management with AI-powered analysis and recommendations.

📚 Next Steps