现在我正在研究聊天 GPT 提示,然后再请求付费 chatGPT API。 但我的提示无法使ChatGPT理解要求。 我需要帮助修复如何发出正确的提示,也感谢提供推荐的链接/文档来学习。
问题:
我删除了一些看起来不必要的东西,并尝试了新的 JSON 模式 并得到了正确的响应。尽管如此,法学硕士并不是确定性的,并且可能会发生错误。您可以尝试微调您的模型以减少出现错误的可能性,或者在给出响应后以某种方式检查关键字,或者多次调用 api 要求仔细检查过敏原和正确性。
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"
}
]
}