From 9da38676e3d8b89fb2da26ab1039a91a21bfc590 Mon Sep 17 00:00:00 2001 From: Automated Action Date: Sun, 8 Jun 2025 21:56:42 +0000 Subject: [PATCH] Update code via agent code generation --- app/api/v1/api.py | 11 ++++ app/api/v1/endpoints/audio.py | 25 +++++++++ app/api/v1/endpoints/auth.py | 41 +++++++++++++++ app/api/v1/endpoints/chat.py | 25 +++++++++ app/api/v1/endpoints/mental_health.py | 75 +++++++++++++++++++++++++++ app/api/v1/endpoints/users.py | 31 +++++++++++ app/core/config.py | 48 +++++++++++++++++ app/db/base.py | 4 ++ app/db/session.py | 13 +++++ main.py | 52 +++++++++++++++++++ 10 files changed, 325 insertions(+) create mode 100644 app/api/v1/api.py create mode 100644 app/api/v1/endpoints/audio.py create mode 100644 app/api/v1/endpoints/auth.py create mode 100644 app/api/v1/endpoints/chat.py create mode 100644 app/api/v1/endpoints/mental_health.py create mode 100644 app/api/v1/endpoints/users.py create mode 100644 app/core/config.py create mode 100644 app/db/base.py create mode 100644 app/db/session.py create mode 100644 main.py diff --git a/app/api/v1/api.py b/app/api/v1/api.py new file mode 100644 index 0000000..ff09df1 --- /dev/null +++ b/app/api/v1/api.py @@ -0,0 +1,11 @@ +from fastapi import APIRouter +from app.api.v1.endpoints import auth, users, mental_health, audio, chat + +api_router = APIRouter() + +# Include all endpoint routers +api_router.include_router(auth.router, prefix="/auth", tags=["authentication"]) +api_router.include_router(users.router, prefix="/users", tags=["users"]) +api_router.include_router(mental_health.router, prefix="/mental-health", tags=["mental health"]) +api_router.include_router(audio.router, prefix="/audio", tags=["audio"]) +api_router.include_router(chat.router, prefix="/chat", tags=["chat"]) \ No newline at end of file diff --git a/app/api/v1/endpoints/audio.py b/app/api/v1/endpoints/audio.py new file mode 100644 index 0000000..5f9c12c --- /dev/null +++ b/app/api/v1/endpoints/audio.py @@ -0,0 +1,25 @@ +from fastapi import APIRouter, Depends, HTTPException, status, UploadFile, File +from sqlalchemy.orm import Session + +from app.db.dependencies import get_db +from app.core.security import get_current_user +from app.schemas.user import UserInDB +from app.schemas.audio import AudioTranscription + +router = APIRouter() + +@router.post("/transcribe", response_model=AudioTranscription) +async def transcribe_audio( + audio: UploadFile = File(...), + current_user: UserInDB = Depends(get_current_user), + db: Session = Depends(get_db) +): + """ + Transcribe audio using OpenAI's Whisper API. + """ + # Will be implemented after OpenAI Whisper integration + # Placeholder for now + raise HTTPException( + status_code=status.HTTP_501_NOT_IMPLEMENTED, + detail="Endpoint not implemented yet", + ) \ No newline at end of file diff --git a/app/api/v1/endpoints/auth.py b/app/api/v1/endpoints/auth.py new file mode 100644 index 0000000..5c1943d --- /dev/null +++ b/app/api/v1/endpoints/auth.py @@ -0,0 +1,41 @@ +from fastapi import APIRouter, Depends, HTTPException, status +from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm +from sqlalchemy.orm import Session + +from app.core.config import settings +from app.db.dependencies import get_db +from app.schemas.auth import Token, TokenData +from app.services import firebase_auth + +router = APIRouter() + +@router.post("/token", response_model=Token) +async def login_for_access_token( + form_data: OAuth2PasswordRequestForm = Depends(), + db: Session = Depends(get_db) +): + """ + Endpoint to authenticate users and get JWT token. + Will use Firebase for authentication. + """ + # This will be implemented after Firebase integration + # Placeholder for now + raise HTTPException( + status_code=status.HTTP_501_NOT_IMPLEMENTED, + detail="Endpoint not implemented yet", + ) + +@router.post("/register", status_code=status.HTTP_201_CREATED) +async def register_user( + # User registration data will be defined later + db: Session = Depends(get_db) +): + """ + Endpoint to register new users via Firebase. + """ + # This will be implemented after Firebase integration + # Placeholder for now + raise HTTPException( + status_code=status.HTTP_501_NOT_IMPLEMENTED, + detail="Endpoint not implemented yet", + ) \ No newline at end of file diff --git a/app/api/v1/endpoints/chat.py b/app/api/v1/endpoints/chat.py new file mode 100644 index 0000000..57cac27 --- /dev/null +++ b/app/api/v1/endpoints/chat.py @@ -0,0 +1,25 @@ +from fastapi import APIRouter, Depends, HTTPException, status +from sqlalchemy.orm import Session + +from app.db.dependencies import get_db +from app.core.security import get_current_user +from app.schemas.user import UserInDB +from app.schemas.chat import ChatMessage, ChatResponse + +router = APIRouter() + +@router.post("/message", response_model=ChatResponse) +async def process_chat_message( + message: ChatMessage, + current_user: UserInDB = Depends(get_current_user), + db: Session = Depends(get_db) +): + """ + Process a chat message using GPT-4.1 and return a response. + """ + # Will be implemented after OpenAI GPT integration + # Placeholder for now + raise HTTPException( + status_code=status.HTTP_501_NOT_IMPLEMENTED, + detail="Endpoint not implemented yet", + ) \ No newline at end of file diff --git a/app/api/v1/endpoints/mental_health.py b/app/api/v1/endpoints/mental_health.py new file mode 100644 index 0000000..db2cd6a --- /dev/null +++ b/app/api/v1/endpoints/mental_health.py @@ -0,0 +1,75 @@ +from fastapi import APIRouter, Depends, HTTPException, status +from sqlalchemy.orm import Session + +from app.db.dependencies import get_db +from app.core.security import get_current_user +from app.schemas.user import UserInDB +from app.schemas.mental_health import MoodLogCreate, MoodLogOut, JournalEntryCreate, JournalEntryOut + +router = APIRouter() + +@router.post("/mood", response_model=MoodLogOut, status_code=status.HTTP_201_CREATED) +async def create_mood_log( + mood_log: MoodLogCreate, + current_user: UserInDB = Depends(get_current_user), + db: Session = Depends(get_db) +): + """ + Create a new mood log entry. + """ + # Will be implemented after model creation + # Placeholder for now + raise HTTPException( + status_code=status.HTTP_501_NOT_IMPLEMENTED, + detail="Endpoint not implemented yet", + ) + +@router.get("/mood", response_model=list[MoodLogOut]) +async def get_mood_logs( + skip: int = 0, + limit: int = 100, + current_user: UserInDB = Depends(get_current_user), + db: Session = Depends(get_db) +): + """ + Get mood logs for the current user. + """ + # Will be implemented after model creation + # Placeholder for now + raise HTTPException( + status_code=status.HTTP_501_NOT_IMPLEMENTED, + detail="Endpoint not implemented yet", + ) + +@router.post("/journal", response_model=JournalEntryOut, status_code=status.HTTP_201_CREATED) +async def create_journal_entry( + journal_entry: JournalEntryCreate, + current_user: UserInDB = Depends(get_current_user), + db: Session = Depends(get_db) +): + """ + Create a new journal entry with sentiment analysis. + """ + # Will be implemented after Dialogflow integration + # Placeholder for now + raise HTTPException( + status_code=status.HTTP_501_NOT_IMPLEMENTED, + detail="Endpoint not implemented yet", + ) + +@router.get("/journal", response_model=list[JournalEntryOut]) +async def get_journal_entries( + skip: int = 0, + limit: int = 100, + current_user: UserInDB = Depends(get_current_user), + db: Session = Depends(get_db) +): + """ + Get journal entries for the current user. + """ + # Will be implemented after model creation + # Placeholder for now + raise HTTPException( + status_code=status.HTTP_501_NOT_IMPLEMENTED, + detail="Endpoint not implemented yet", + ) \ No newline at end of file diff --git a/app/api/v1/endpoints/users.py b/app/api/v1/endpoints/users.py new file mode 100644 index 0000000..12c39ed --- /dev/null +++ b/app/api/v1/endpoints/users.py @@ -0,0 +1,31 @@ +from fastapi import APIRouter, Depends, HTTPException, status +from sqlalchemy.orm import Session + +from app.db.dependencies import get_db +from app.schemas.user import UserCreate, UserUpdate, UserInDB, UserOut +from app.core.security import get_current_user + +router = APIRouter() + +@router.get("/me", response_model=UserOut) +async def read_users_me(current_user: UserInDB = Depends(get_current_user)): + """ + Get current user information. + """ + return current_user + +@router.put("/me", response_model=UserOut) +async def update_user_me( + user_update: UserUpdate, + current_user: UserInDB = Depends(get_current_user), + db: Session = Depends(get_db) +): + """ + Update current user information. + """ + # This will be implemented after model creation + # Placeholder for now + raise HTTPException( + status_code=status.HTTP_501_NOT_IMPLEMENTED, + detail="Endpoint not implemented yet", + ) \ No newline at end of file diff --git a/app/core/config.py b/app/core/config.py new file mode 100644 index 0000000..5e1418e --- /dev/null +++ b/app/core/config.py @@ -0,0 +1,48 @@ +import os +from pathlib import Path +from typing import List, Optional +from pydantic import field_validator +from pydantic_settings import BaseSettings, SettingsConfigDict + +class Settings(BaseSettings): + # Project details + PROJECT_NAME: str = "AI Mental Health App" + PROJECT_DESCRIPTION: str = "AI-powered mental health application with Firebase, Dialogflow, and OpenAI integrations" + VERSION: str = "0.1.0" + API_V1_STR: str = "/api/v1" + DEBUG_MODE: bool = os.getenv("DEBUG_MODE", "False").lower() in ("true", "1", "t") + + # Firebase configuration + FIREBASE_CREDENTIALS: Optional[str] = None + FIREBASE_DATABASE_URL: Optional[str] = None + + # OpenAI configuration + OPENAI_API_KEY: Optional[str] = None + + # Dialogflow configuration + DIALOGFLOW_PROJECT_ID: Optional[str] = None + DIALOGFLOW_LOCATION: str = "global" + DIALOGFLOW_AGENT_ID: Optional[str] = None + GOOGLE_APPLICATION_CREDENTIALS: Optional[str] = None + + # SQLite Database settings + DB_DIR: Path = Path("/app/storage/db") + SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite" + + # JWT settings + SECRET_KEY: str = os.getenv("SECRET_KEY", "secret_key_for_development_only") + ACCESS_TOKEN_EXPIRE_MINUTES: int = int(os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES", "30")) + + # Security + ALLOWED_HOSTS: List[str] = ["*"] + + # Model config + model_config = SettingsConfigDict(env_file=".env", case_sensitive=True) + + @field_validator("DB_DIR") + def create_db_dir(cls, v): + """Create database directory if it doesn't exist""" + v.mkdir(parents=True, exist_ok=True) + return v + +settings = Settings() \ No newline at end of file diff --git a/app/db/base.py b/app/db/base.py new file mode 100644 index 0000000..30621d7 --- /dev/null +++ b/app/db/base.py @@ -0,0 +1,4 @@ +from sqlalchemy.ext.declarative import declarative_base + +# Create SQLAlchemy Base model +Base = declarative_base() \ No newline at end of file diff --git a/app/db/session.py b/app/db/session.py new file mode 100644 index 0000000..72115da --- /dev/null +++ b/app/db/session.py @@ -0,0 +1,13 @@ +from sqlalchemy import create_engine +from sqlalchemy.orm import sessionmaker + +from app.core.config import settings + +# Create database engine +engine = create_engine( + settings.SQLALCHEMY_DATABASE_URL, + connect_args={"check_same_thread": False} # Needed for SQLite +) + +# Create sessionmaker +SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..6db3d65 --- /dev/null +++ b/main.py @@ -0,0 +1,52 @@ +import uvicorn +from fastapi import FastAPI +from fastapi.middleware.cors import CORSMiddleware +from app.api.v1.api import api_router +from app.core.config import settings + +app = FastAPI( + title=settings.PROJECT_NAME, + description=settings.PROJECT_DESCRIPTION, + version=settings.VERSION, + openapi_url=f"/openapi.json", + docs_url="/docs", + redoc_url="/redoc", +) + +# Configure CORS +app.add_middleware( + CORSMiddleware, + allow_origins=["*"], + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + +# Include API router +app.include_router(api_router, prefix=settings.API_V1_STR) + +@app.get("/") +async def root(): + """ + Root endpoint that returns basic information about the service. + """ + return { + "name": settings.PROJECT_NAME, + "docs": "/docs", + "health": "/health" + } + +@app.get("/health", status_code=200) +async def health_check(): + """ + Health check endpoint to verify service status. + """ + return {"status": "ok"} + +if __name__ == "__main__": + uvicorn.run( + "main:app", + host="0.0.0.0", + port=8000, + reload=settings.DEBUG_MODE + ) \ No newline at end of file