-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_call.py
More file actions
27 lines (18 loc) · 748 Bytes
/
api_call.py
File metadata and controls
27 lines (18 loc) · 748 Bytes
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
import openai
# Set your OpenAI API key
openai.api_key = "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"
def get_recipe_suggestions(user_message):
# Create a conversation with the system message as a cooking assistant and the user message
conversation = [
{"role": "system", "content": "You are a cooking assistant."},
{"role": "user", "content": user_message},
]
# Generate a response from the assistant
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=conversation
)
# Extract and return the assistant's reply
assistant_reply = response['choices'][0]['message']['content']
return assistant_reply
# Example usage