-
Notifications
You must be signed in to change notification settings - Fork 59.8k
Expand file tree
/
Copy pathoai-app-recipe.py
More file actions
42 lines (30 loc) · 1.64 KB
/
oai-app-recipe.py
File metadata and controls
42 lines (30 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from openai import OpenAI
import os
from dotenv import load_dotenv
# load environment variables from .env file
load_dotenv()
# configure Azure OpenAI service client
client = OpenAI()
deployment = "gpt-3.5-turbo"
no_recipes = input("No of recipes (for example, 5: ")
ingredients = input("List of ingredients (for example, chicken, potatoes, and carrots: ")
filter = input("Filter (for example, vegetarian, vegan, or gluten-free: ")
# interpolate the number of recipes into the prompt an ingredients
prompt = f"Show me {no_recipes} recipes for a dish with the following ingredients: {ingredients}. Per recipe, list all the ingredients used, no {filter}: "
messages = [{"role": "user", "content": prompt}]
completion = client.chat.completions.create(model=deployment, messages=messages, max_tokens=600, temperature = 0.1)
# print response
print("Recipes:")
if not completion.choices or completion.choices[0].message is None:
print("No response received.")
else:
old_prompt_result = completion.choices[0].message.content
print(old_prompt_result)
prompt_shopping = "Produce a shopping list, and please don't include ingredients that I already have at home: "
new_prompt = f"Given ingredients at home {ingredients} and these generated recipes: {old_prompt_result}, {prompt_shopping}"
messages = [{"role": "user", "content": new_prompt}]
completion = client.chat.completions.create(model=deployment, messages=messages, max_tokens=600, temperature=0)
# print response
print("\n=====Shopping list ======= \n")
if completion.choices and completion.choices[0].message is not None:
print(completion.choices[0].message.content)