Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions ai_services/agno_agents/triage_agent.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# ai_services/agno_agents/triage_agent.py


def triage_incident(description: str) -> str:
"""Simple triage based on keywords — simulate AI agent."""
if any(word in description.lower() for word in ["urgent", "fire", "injury", "explosion"]):
if any(
word in description.lower()
for word in ["urgent", "fire", "injury", "explosion"]
):
return "high"
elif any(word in description.lower() for word in ["delay", "minor", "slow", "confused"]):
elif any(
word in description.lower() for word in ["delay", "minor", "slow", "confused"]
):
return "low"
return "medium"
1 change: 1 addition & 0 deletions ai_services/api/endpoints/incidents.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

router = APIRouter()


@router.post("/incidents", response_model=IncidentOut)
def report_incident(payload: IncidentCreate, user=Depends(get_current_user)):
try:
Expand Down
19 changes: 9 additions & 10 deletions ai_services/api/endpoints/users.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
from fastapi import APIRouter, HTTPException, status, Depends, Request
from pydantic import BaseModel, EmailStr
from core.auth import get_current_user
from core.database import supabase # Assuming supabase client is initialized in core/database.py
from core.database import (
supabase,
) # Assuming supabase client is initialized in core/database.py
from supabase import Client

router = APIRouter()


# Request schemas
class RegisterRequest(BaseModel):
email: EmailStr
password: str


class LoginRequest(BaseModel):
email: EmailStr
password: str


# Route: Register user
@router.post("/register")
def register_user(payload: RegisterRequest):
try:
result = supabase.auth.sign_up(
{
"email": payload.email,
"password": payload.password
}
{"email": payload.email, "password": payload.password}
)
return {"message": "User registered successfully", "user": result.user}
except Exception as e:
Expand All @@ -35,17 +37,14 @@ def register_user(payload: RegisterRequest):
def login_user(payload: LoginRequest):
try:
result = supabase.auth.sign_in_with_password(
{
"email": payload.email,
"password": payload.password
}
{"email": payload.email, "password": payload.password}
)
if result.session is None:
raise HTTPException(status_code=401, detail="Invalid credentials")
return {
"access_token": result.session.access_token,
"refresh_token": result.session.refresh_token,
"user": result.user
"user": result.user,
}
except Exception as e:
raise HTTPException(status_code=401, detail=str(e))
Expand Down
2 changes: 2 additions & 0 deletions ai_services/core/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

security = HTTPBearer()


def decode_jwt_token(token: str):
try:
decoded = jwt.decode(token, JWT_SECRET, algorithms=[JWT_ALGORITHM])
Expand All @@ -14,6 +15,7 @@ def decode_jwt_token(token: str):
except jwt.InvalidTokenError:
raise HTTPException(status_code=401, detail="Invalid token")


def get_current_user(credentials: HTTPAuthorizationCredentials = Depends(security)):
token = credentials.credentials
payload = decode_jwt_token(token)
Expand Down
4 changes: 2 additions & 2 deletions ai_services/core/config.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# core/config.py
import os
from dotenv import load_dotenv
from supabase import create_client, Client
from supabase import create_client, Client

load_dotenv() # Load from .env file if present

SUPABASE_URL = os.getenv("SUPABASE_URL")
SUPABASE_ANON_KEY = os.getenv("SUPABASE_ANON_KEY")
SUPABASE_SERVICE_ROLE_KEY = os.getenv("SUPABASE_SERVICE_ROLE_KEY")
JWT_SECRET = os.getenv("JWT_SECRET", "super-secret")
JWT_ALGORITHM = os.getenv("JWT_ALGORITHM", "HS256")

1 change: 0 additions & 1 deletion ai_services/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@

app.include_router(users.router, prefix="/api/users", tags=["Users"])
app.include_router(incidents.router, prefix="/api", tags=["Incidents"])

5 changes: 3 additions & 2 deletions ai_services/models/incident.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
from typing import Optional
from datetime import datetime


class IncidentCreate(BaseModel):
title: str
description: str
location: Optional[str] = None
reported_by: Optional[str] = None # Could be user_id or email


class IncidentOut(BaseModel):
id: str
id: str
title: str
description: str
location: Optional[str]
reported_by: Optional[str]
created_at: datetime

7 changes: 4 additions & 3 deletions ai_services/services/incident_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
from uuid import uuid4
from datetime import datetime


def create_incident(data: dict) -> dict:
severity = triage_incident(data["description"])
incident_id = str(uuid4())

new_incident = {
"id": incident_id,
"title": data["title"],
"description": data["description"],
"location": data.get("location"),
"reported_by": data.get("reported_by"),
"severity": severity,
"created_at": datetime.utcnow().isoformat()
"created_at": datetime.utcnow().isoformat(),
}

response = supabase.table("incidents").insert(new_incident).execute()
return response.data[0] if response.data else new_incident