{"id":31669595,"url":"https://github.com/branchingbad/whats-for-dinner","last_synced_at":"2025-10-08T01:51:27.344Z","repository":{"id":317089508,"uuid":"1065947414","full_name":"BranchingBad/Whats-For-Dinner","owner":"BranchingBad","description":"The script simulates using a search tool to find a recipe and then sends the result back to the Gemini model, which formats the final output as a professional recipe card image (text representation).","archived":false,"fork":false,"pushed_at":"2025-09-28T19:21:16.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-28T20:28:30.699Z","etag":null,"topics":["api-application","gemini","gemini-api","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BranchingBad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-28T18:46:15.000Z","updated_at":"2025-09-28T18:54:09.000Z","dependencies_parsed_at":"2025-09-28T20:28:38.729Z","dependency_job_id":"c6ebcc4e-cf6c-4ead-9352-34231a08e03a","html_url":"https://github.com/BranchingBad/Whats-For-Dinner","commit_stats":null,"previous_names":["branchingbad/whats-for-dinner"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/BranchingBad/Whats-For-Dinner","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BranchingBad%2FWhats-For-Dinner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BranchingBad%2FWhats-For-Dinner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BranchingBad%2FWhats-For-Dinner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BranchingBad%2FWhats-For-Dinner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BranchingBad","download_url":"https://codeload.github.com/BranchingBad/Whats-For-Dinner/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BranchingBad%2FWhats-For-Dinner/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278877088,"owners_count":26061380,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-application","gemini","gemini-api","python"],"created_at":"2025-10-08T01:51:23.865Z","updated_at":"2025-10-08T01:51:27.340Z","avatar_url":"https://github.com/BranchingBad.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🍽️ What's for Dinner? Recipe Card Generator\n\nThis Python script uses the **Google Gemini API**'s **function calling** capability to generate a single dinner recipe based on a list of core ingredients provided via the command line.\n\nThe script simulates using a search tool to find a recipe and then sends the result back to the Gemini model, which formats the final output as a professional recipe card image (text representation).\n\n-----\n\n## ✨ Features\n\n* **Intelligent Recipe Generation:** Uses the Gemini model to creatively generate a full recipe from a list of ingredients.\n* **Nutritional Estimates:** The model is instructed to **estimate and include nutritional information** (Calories, Protein, Fat, Carbs) per serving based on the recipe and ingredients.\n* **Function Calling Simulation:** Demonstrates the use of a mock `Google Search` function to fetch real-world data (a recipe snippet).\n* **Reliable Tool Use:** Uses robust configuration (`function_calling_config`) to ensure the model reliably calls the mock search function.\n* **Command-Line Interface (CLI):** Easily input your available ingredients using the `--ingredients` flag.\n* **Professional Formatting:** Outputs the recipe as a clean, text-based recipe card.\n* **Error Handling:** Includes checks for missing ingredients, a **check for empty/filtered API responses**, and graceful fallback to a mock response if the API key is not configured.\n\n-----\n\n## 🚀 Setup and Installation\n\n### 1. Prerequisites\n\nYou must have Python installed (3.8+ recommended).\n\n### 2. Install Dependencies\n\nThe script relies on the Google GenAI SDK for Python and standard libraries (`os`, `json`, `argparse`).\n\n```bash\npip install google-genai\n````\n\n### 3\\. Set Your API Key\n\nThe Gemini model requires an API key. You must set this key as an environment variable named `GEMINI_API_KEY`.\n\n**Linux/macOS:**\n\n```bash\nexport GEMINI_API_KEY=\"YOUR_API_KEY_HERE\"\n```\n\n**Windows (Command Prompt):**\n\n```bash\nset GEMINI_API_KEY=\"YOUR_API_KEY_HERE\"\n```\n\n*(Note: If the key is not set, the script will default to generating a mock, placeholder recipe.)*\n\n-----\n\n## 🍴 Usage\n\nRun the script from your terminal, passing your available ingredients as a comma-separated string to the `--ingredients` argument. **Be sure to wrap the entire list in double quotes (`\" \"`) to prevent shell errors.**\n\n### Example Command\n\nThis example uses core ingredients:\n\n```bash\npython whats-for-dinner.py --ingredients \"turkey kielbasa, penne pasta, jarred marinara sauce, shredded mozzarella, instant potatoes\"\n```\n\n### Example Output (API Success)\n\nThe script output will be formatted as a recipe card, now including a nutritional estimate section:\n\n```\n--- Input Ingredients: ['turkey kielbasa', 'penne pasta', 'jarred marinara sauce', 'shredded mozzarella', 'instant potatoes'] ---\n\n[STEP 1: Calling Gemini to initiate search and tool use...]\n--- TOOL CALLING: Searching for: simple dinner recipe with turkey kielbasa, penne pasta, jarred marinara sauce, shredded mozzarella, instant potatoes ---\n\n[STEP 2: Sending tool results back to Gemini for final response generation...]\n\n================================================================================\nGENERATED RECIPE CARD:\n================================================================================\n**[RECIPE CARD IMAGE: WHAT'S FOR DINNER?]**\n\n**CORE INGREDIENTS**\nturkey kielbasa, penne pasta, jarred marinara sauce, shredded mozzarella, instant potatoes\n\n***\n\n**RECIPE: ONE-POT KIELBASA \u0026 CHEESY MARINARA PASTA**\n*(Time: 30 Min | Serves 4)*\n\n**Description:**\nA simple, hearty weeknight meal that combines savory turkey kielbasa, tomato sauce, and pasta, all cooked in one pot for minimal cleanup.\n... (Rest of the recipe steps)\n\n***\n\n**NUTRITIONAL INFORMATION (Estimated Per Serving)**\n* Calories: 580 kcal\n* Protein: 35g\n* Fat: 22g\n* Carbs: 65g\n================================================================================\n```\n\n### Error Handling Example\n\nIf the script runs but the model's final response is empty (e.g., due to safety filtering), the new error check will print a helpful message instead of just \"None.\"\n\n```\n================================================================================\nGENERATED RECIPE CARD:\n================================================================================\nERROR: Recipe generation failed. The model returned no text.\nThis can happen due to safety filtering. Please check the prompt or try again.\n================================================================================\n```\n\n-----\n\n## 🛠️ How It Works (Code Breakdown)\n\n1.  **`argparse`:** The script uses `argparse` to receive the ingredients string, cleans it, and validates that ingredients were actually provided.\n2.  **`Google Search` (Mock Tool):** This function acts as the **tool** for the Gemini model, providing a hardcoded mock recipe snippet.\n3.  **`generate_recipe_card` (Main Logic):**\n      * It prepares a detailed prompt, now explicitly asking for **estimated nutritional information**.\n      * It uses `tool_config_force` with `function_calling_config(mode='ANY')` to make the **First API Call**, ensuring the model calls the mock `Google Search` function reliably.\n      * The script executes the Python `Google Search` function and captures the mock JSON result.\n      * It makes the **Second API Call**, sending the original prompt *plus* the mock result back to Gemini.\n      * Gemini uses the snippet to generate the final, fully formatted recipe card, including the nutritional estimates.\n      * The final output block includes a check: `if response.text:` to handle cases where the model returns an empty body.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbranchingbad%2Fwhats-for-dinner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbranchingbad%2Fwhats-for-dinner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbranchingbad%2Fwhats-for-dinner/lists"}