Update code via agent code generation
This commit is contained in:
parent
37c5939da3
commit
9da38676e3
11
app/api/v1/api.py
Normal file
11
app/api/v1/api.py
Normal file
@ -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"])
|
25
app/api/v1/endpoints/audio.py
Normal file
25
app/api/v1/endpoints/audio.py
Normal file
@ -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",
|
||||
)
|
41
app/api/v1/endpoints/auth.py
Normal file
41
app/api/v1/endpoints/auth.py
Normal file
@ -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",
|
||||
)
|
25
app/api/v1/endpoints/chat.py
Normal file
25
app/api/v1/endpoints/chat.py
Normal file
@ -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",
|
||||
)
|
75
app/api/v1/endpoints/mental_health.py
Normal file
75
app/api/v1/endpoints/mental_health.py
Normal file
@ -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",
|
||||
)
|
31
app/api/v1/endpoints/users.py
Normal file
31
app/api/v1/endpoints/users.py
Normal file
@ -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",
|
||||
)
|
48
app/core/config.py
Normal file
48
app/core/config.py
Normal file
@ -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()
|
4
app/db/base.py
Normal file
4
app/db/base.py
Normal file
@ -0,0 +1,4 @@
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
|
||||
# Create SQLAlchemy Base model
|
||||
Base = declarative_base()
|
13
app/db/session.py
Normal file
13
app/db/session.py
Normal file
@ -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)
|
52
main.py
Normal file
52
main.py
Normal file
@ -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
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user