forked from microsoft/generative-ai-for-beginners
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaoai-app-recipe.py
More file actions
46 lines (30 loc) · 1.62 KB
/
aoai-app-recipe.py
File metadata and controls
46 lines (30 loc) · 1.62 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
42
43
from openai import AzureOpenAI
import os
from dotenv import load_dotenv
# load environment variables from .env file
load_dotenv()
# configure Azure OpenAI service client
client = AzureOpenAI(
azure_endpoint = os.environ["AZURE_OPENAI_ENDPOINT"],
api_key=os.environ['AZURE_OPENAI_API_KEY'],
api_version = "2023-10-01-preview"
)
deployment=os.environ['AZURE_OPENAI_DEPLOYMENT']
no_recipes = input("No of recipes (for example, 1: ")
ingredients = input("List of ingredients (for example, choclate, ice cream, and coco powder: ")
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:")
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)