-
Notifications
You must be signed in to change notification settings - Fork 0
/
recipie_creator.py
36 lines (32 loc) · 1.28 KB
/
recipie_creator.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
from keys import OPENAI_KEY
import requests
import openai
openai.api_key = OPENAI_KEY
def generate_recipe(ingredients):
ingredients_str = ', '.join(ingredients) # Convert the list of ingredients to a comma-separated string
try:
response = openai.ChatCompletion.create(
model="gpt-4",
messages=[
{
"role": "system",
"content": "You are a recipe generating machine. Give me a recipe that uses the following ingredients. Respond in HTML only using p and b tags. It must not have any other HTML tags. Keep it medium length and detail. Give it a title at the top. You do not have to use all ingredients, and can choose more to buy. The ingredients will follow.",
},
{
"role": "user",
"content": f"{ingredients_str}"
},
],
temperature=1,
max_tokens=2000,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
return response.choices[0].message.content
except:
return "Sorry, couldn't generate a recipe. Please try again."
if __name__ == "__main__":
ingredients = ["chicken", "rice", "broccoli"]
recipe = generate_recipe(ingredients)
print(recipe)