mirror of
https://github.com/escalante29/healthy-fit.git
synced 2026-03-21 12:28:46 +01:00
Add AI-powered nutrition and plan modules
Introduces DSPy-based nutrition and plan generation modules, including image analysis for nutritional info and personalized diet/exercise plans. Adds new API endpoints for health metrics/goals, nutrition image analysis, and plan management. Updates models, schemas, and backend structure to support these features, and includes initial training data and configuration for prompt optimization.
This commit is contained in:
@@ -1,35 +1,80 @@
|
||||
from datetime import datetime
|
||||
from typing import Any, List
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlmodel import Session, select
|
||||
from app.api import deps
|
||||
from app.models.health import HealthMetric
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
from pydantic import BaseModel
|
||||
from sqlmodel import Session, select
|
||||
|
||||
from app.api import deps
|
||||
from app.models.health import HealthGoal, HealthMetric
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
class HealthMetricCreate(BaseModel):
|
||||
metric_type: str
|
||||
value: float
|
||||
unit: str
|
||||
user_id: int # TODO: remove when auth is fully integrated
|
||||
|
||||
@router.post("/", response_model=HealthMetric)
|
||||
|
||||
class HealthGoalCreate(BaseModel):
|
||||
goal_type: str
|
||||
target_value: float
|
||||
target_date: datetime | None = None
|
||||
|
||||
|
||||
@router.post("/metrics", response_model=HealthMetric)
|
||||
def create_metric(
|
||||
*,
|
||||
session: Session = Depends(deps.get_session),
|
||||
current_user: deps.CurrentUser,
|
||||
metric_in: HealthMetricCreate,
|
||||
) -> Any:
|
||||
metric = HealthMetric(metric_type=metric_in.metric_type, value=metric_in.value, unit=metric_in.unit, user_id=metric_in.user_id)
|
||||
metric = HealthMetric(
|
||||
metric_type=metric_in.metric_type, value=metric_in.value, unit=metric_in.unit, user_id=current_user.id
|
||||
)
|
||||
session.add(metric)
|
||||
session.commit()
|
||||
session.refresh(metric)
|
||||
return metric
|
||||
|
||||
@router.get("/{user_id}", response_model=List[HealthMetric])
|
||||
|
||||
@router.get("/metrics", response_model=List[HealthMetric])
|
||||
def read_metrics(
|
||||
user_id: int,
|
||||
current_user: deps.CurrentUser,
|
||||
session: Session = Depends(deps.get_session),
|
||||
) -> Any:
|
||||
statement = select(HealthMetric).where(HealthMetric.user_id == user_id)
|
||||
statement = (
|
||||
select(HealthMetric).where(HealthMetric.user_id == current_user.id).order_by(HealthMetric.timestamp.desc())
|
||||
)
|
||||
metrics = session.exec(statement).all()
|
||||
return metrics
|
||||
|
||||
|
||||
@router.post("/goals", response_model=HealthGoal)
|
||||
def create_goal(
|
||||
*,
|
||||
session: Session = Depends(deps.get_session),
|
||||
current_user: deps.CurrentUser,
|
||||
goal_in: HealthGoalCreate,
|
||||
) -> Any:
|
||||
goal = HealthGoal(
|
||||
goal_type=goal_in.goal_type,
|
||||
target_value=goal_in.target_value,
|
||||
target_date=goal_in.target_date,
|
||||
user_id=current_user.id,
|
||||
)
|
||||
session.add(goal)
|
||||
session.commit()
|
||||
session.refresh(goal)
|
||||
return goal
|
||||
|
||||
|
||||
@router.get("/goals", response_model=List[HealthGoal])
|
||||
def read_goals(
|
||||
current_user: deps.CurrentUser,
|
||||
session: Session = Depends(deps.get_session),
|
||||
) -> Any:
|
||||
statement = select(HealthGoal).where(HealthGoal.user_id == current_user.id)
|
||||
goals = session.exec(statement).all()
|
||||
return goals
|
||||
|
||||
Reference in New Issue
Block a user