restpromptopenai-api

ChatGPT doesnt want to answer correctly based on prepared prompt


Now I am researching chat GPT prompt before requesting paid chatGPT API. but my prompt cannot make ChatGPT understand the requirements. I need help fixing it how to make a proper prompt, providing recommended link/docs to learn is also appreciated.

problem:

  1. returning food that contain allergy
  2. the currency not following the country/location.

enter image description here


Solution

  • I removed some stuff that seemed unnecessary and tried the new JSON mode and got the right response. With that being said, though, LLM's are not deterministic and errors can happen. You could try to fine tune your model to decrease the chances of errors cropping up or somehow check for keywords after the response has been given or make multiple calls to the api asking to double-check for allergens and correctness.

    import os
    from openai import OpenAI
    from dotenv import load_dotenv
    load_dotenv()
    client = OpenAI()
    
    response = client.chat.completions.create(
      model="gpt-3.5-turbo-1106",
      response_format={ "type": "json_object" },
      messages=[
        {"role": "system", "content": '''You are a recipe generator designed to take allergies, goals, country, budget and interests and output 8 recipes as JSON format with status and data which should contain ingredients, total_calories, nutrition, budget.*allergies must be  avoided! NEVER RETURN any food that contains allergens!'''},
        {"role": "user", "content": '''allergies: poultry, nuts. goals: boost athletic performance because i am fat and can only do 20 push ups. country: UK budget: 5-20 USD Dollars '''
    
    }
      ]
    )
    print(response.choices[0].message.content)
    
    
    
    {
      "status": "success",
      "data": [
        {
          "recipe_name": "Quinoa Salad with Roasted Vegetables",
          "ingredients": [
            "quinoa",
            "bell peppers",
            "zucchini",
            "red onion",
            "olive oil",
            "lemon juice",
            "garlic",
            "fresh parsley",
            "salt",
            "pepper"
          ],
          "total_calories": 320,
          "nutrition": {
            "carbs": "40g",
            "protein": "8g",
            "fat": "14g"
          },
          "budget": "10 USD"
        },
        {
          "recipe_name": "Black Bean and Sweet Potato Tacos",
          "ingredients": [
            "black beans",
            "sweet potatoes",
            "taco shells",
            "avocado",
            "tomato",
            "red cabbage",
            "lime",
            "cilantro",
            "cumin",
            "paprika",
            "salt",
            "pepper"
          ],
          "total_calories": 380,
          "nutrition": {
            "carbs": "45g",
            "protein": "10g",
            "fat": "15g"
          },
          "budget": "15 USD"
        },
        {
          "recipe_name": "Mediterranean Chickpea Salad",
          "ingredients": [
            "chickpeas",
            "cucumber",
            "tomato",
            "red onion",
            "kalamata olives",
            "feta cheese",
            "olive oil",
            "red wine vinegar",
            "oregano",
            "salt",
            "pepper"
          ],
          "total_calories": 290,
          "nutrition": {
            "carbs": "35g",
            "protein": "12g",
            "fat": "13g"
          },
          "budget": "10 USD"
        },
        {
          "recipe_name": "Vegetable Stir-Fry with Tofu",
          "ingredients": [
            "tofu",
            "broccoli",
            "carrots",
            "bell peppers",
            "snap peas",
            "soy sauce",
            "sesame oil",
            "garlic",
            "ginger",
            "rice",
            "green onions"
          ],
          "total_calories": 350,
          "nutrition": {
            "carbs": "40g",
            "protein": "15g",
            "fat": "12g"
          },
          "budget": "12 USD"
        },
        {
          "recipe_name": "Quinoa Stuffed Bell Peppers",
          "ingredients": [
            "bell peppers",
            "quinoa",
            "black beans",
            "corn",
            "tomato",
            "onion",
            "garlic",
            "cumin",
            "paprika",
            "salt",
            "pepper"
          ],
          "total_calories": 300,
          "nutrition": {
            "carbs": "35g",
            "protein": "10g",
            "fat": "11g"
          },
          "budget": "10 USD"
        },
        {
          "recipe_name": "Cauliflower Rice Bowl with Black Beans and Avocado",
          "ingredients": [
            "cauliflower",
            "black beans",
            "avocado",
            "corn",
            "red cabbage",
            "lime",
            "cilantro",
            "cumin",
            "paprika",
            "salt",
            "pepper"
          ],
          "total_calories": 280,
          "nutrition": {
            "carbs": "30g",
            "protein": "9g",
            "fat": "10g"
          },
          "budget": "10 USD"
        },
        {
          "recipe_name": "Mushroom and Spinach Quinoa Risotto",
          "ingredients": [
            "quinoa",
            "mushrooms",
            "spinach",
            "onion",
            "garlic",
            "vegetable broth",
            "white wine",
            "parmesan cheese",
            "olive oil",
            "salt",
            "pepper"
          ],
          "total_calories": 310,
          "nutrition": {
            "carbs": "35g",
            "protein": "11g",
            "fat": "12g"
          },
          "budget": "12 USD"
        },
        {
          "recipe_name": "Spicy Lentil and Chickpea Stew",
          "ingredients": [
            "lentils",
            "chickpeas",
            "onion",
            "carrots",
            "celery",
            "garlic",
            "tomato",
            "vegetable broth",
            "cumin",
            "coriander",
            "smoked paprika",
            "cayenne pepper",
            "salt",
            "pepper",
            "lemon"
          ],
          "total_calories": 340,
          "nutrition": {
            "carbs": "40g",
            "protein": "14g",
            "fat": "13g"
          },
          "budget": "10 USD"
        }
      ]
    }