An intelligent backend service that generates creative recipes from a list of ingredients using a powerful generative AI. This project leverages the Grok AI API to provide users with a simple and effective way to discover new meals and reduce food waste.
- Dynamic Recipe Generation: Provide a list of ingredients and get a complete recipe, including title, description, ingredients list, and step-by-step instructions.
- RESTful API: A clean, well-documented API for easy integration with any front-end application (web or mobile).
- AI-Powered: Utilizes a state-of-the-art generative AI to ensure creative and coherent recipe suggestions.
- Scalable Backend: Built with Spring Boot, ensuring a robust, secure, and scalable foundation.
The application provides a simple yet powerful workflow:
- A user sends a
POSTrequest to the/api/recipes/generateendpoint with a list of available ingredients in the request body. - The Spring Boot backend receives the request and constructs a carefully crafted prompt for the Grok AI API.
- The service makes a secure, server-to-server call to the AI API.
- The AI model processes the prompt and returns a structured JSON response containing a complete recipe.
- The backend parses this response and sends a clean, well-formatted recipe object back to the user.
- Backend: Java, Spring Boot
- API Communication: Spring RestTemplate / WebClient
- AI Integration: Grok AI API (or other specified generative AI)
- Data Handling: JSON
- Build Tool: Maven / Gradle
To run this project locally, you will need to have Java and Maven/Gradle installed.
1. Clone the repository:
git clone [https://github.com/sidhu1512/recipe-assistant.git](https://github.com/sidhu1512/recipe-assistant.git)
cd recipe-assistant2. Configure your API Key: The application requires an API key for the AI service. You need to set this as an environment variable.
In your src/main/resources/application.properties file, add the following line:
ai.api.key=YOUR_API_KEY_HERE(For better security, it's recommended to use environment variables instead of hardcoding the key. You can update the code to read from System.getenv("AI_API_KEY").)
3. Build and run the application:
./mvnw spring-boot:runThe application will start on http://localhost:8080.
- URL:
/api/recipes/generate - Method:
POST - Description: Generates a new recipe based on the provided ingredients.
- Request Body:
{ "ingredients": ["chicken breast", "rice", "broccoli", "soy sauce"] } - Success Response (200 OK):
{ "title": "Simple Chicken and Broccoli Stir-fry", "description": "A quick and delicious stir-fry, perfect for a weeknight dinner.", "ingredients": [ "1 lb chicken breast, cubed", "1 cup white rice", "2 cups broccoli florets", "1/4 cup soy sauce" ], "instructions": "1. Cook rice according to package directions. 2. Sauté chicken in a large skillet... etc." }