-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAI_App_Recipy.py
43 lines (30 loc) · 1.47 KB
/
AI_App_Recipy.py
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
42
43
from openai import AzureOpenAI
import os
import dotenv
# import dotenv
dotenv.load_dotenv()
# configure Azure OpenAI service client
client = AzureOpenAI(
azure_endpoint = os.environ["AZURE_OPENAI_ENDPOINT"],
api_key=os.environ['AZURE_OPENAI_KEY'],
api_version = "2023-10-01-preview"
)
deployment=os.environ['AZURE_OPENAI_DEPLOYMENT']
no_recipes = input("No of recipes : ")
ingredients = input("List of ingredients : ")
filter = input("Filter : ")
# 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:")
print(completion.choices[0].message.content)
old_prompt_result = completion.choices[0].message.content
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")
print(completion.choices[0].message.content)