Files
healthy-fit/backend/app/ai/plans.py
Carlos Escalante 184c8330a7 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.
2026-01-18 17:14:56 -06:00

35 lines
1.2 KiB
Python

import dspy
from pydantic import BaseModel, Field
class PlanOutput(BaseModel):
reasoning: str = Field(description="Reasoning behind the selected plan based on user goals")
title: str = Field(description="Title of the plan")
summary: str = Field(description="Brief summary of the plan")
diet_plan: list[str] = Field(description="List of daily diet recommendations")
exercise_plan: list[str] = Field(description="List of daily exercise routines")
tips: list[str] = Field(description="Additional health tips")
class GeneratePlan(dspy.Signature):
"""Generate a personalized diet and exercise plan based on user goal and details.
Analyze the user's profile and goal, explain your reasoning, and then generate the plan.
"""
user_profile: str = dspy.InputField(desc="User details (age, weight, height, etc)")
goal: str = dspy.InputField(desc="Specific user goal")
plan: PlanOutput = dspy.OutputField(desc="Structured plan with reasoning")
class PlanModule(dspy.Module):
def __init__(self):
super().__init__()
self.generate = dspy.ChainOfThought(GeneratePlan)
def forward(self, user_profile: str, goal: str):
return self.generate(user_profile=user_profile, goal=goal)
plan_module = PlanModule()