Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI, HTTPException | |
| from fastapi.responses import JSONResponse | |
| from models import PoojaRequest, PoojaIngredientsResponse | |
| from services import generate_pooja_ingredients | |
| app = FastAPI( | |
| title="Pooja Ingredients Agent API", | |
| description="An API to generate structured ingredients for any Pooja using Groq LLM", | |
| version="1.0.0" | |
| ) | |
| def read_root(): | |
| return {"message": "Welcome to the Pooja Ingredients Agent API. Use POST /pooja-ingredients to get ingredients."} | |
| def get_pooja_ingredients(request: PoojaRequest): | |
| """ | |
| Accepts a Pooja name and returns a strictly structured list of ingredients | |
| required for different steps in the pooja. | |
| """ | |
| pooja_name = request.pooja_name.strip() | |
| if not pooja_name: | |
| raise HTTPException(status_code=400, detail="Pooja name cannot be empty.") | |
| try: | |
| # Call the service that uses Groq to generate the structured list | |
| ingredients_data = generate_pooja_ingredients(pooja_name) | |
| return ingredients_data | |
| except HTTPException: | |
| raise | |
| except Exception: | |
| raise HTTPException(status_code=500, detail="Error generating ingredients.") | |