Hi, I am completely new to programming and am building a small app in Python as a challenge with the help of GPT. Everything is going well until I need to implement my assistant, which I created in Playgrounds. Both GPT and I are clueless about how to proceed. If I wanted to integrate “asst_xxx” from Playgrounds into this code, how would I do it? It works perfectly with the standard GPT
def generate_recipe_with_gpt(user_prompt):
"""
Generates recipes based on the user's prompt using OpenAI's correctly configured chat completion.
:param user_prompt: String containing the user's description/requirements.
:return: GPT-generated text.
"""
try:
response = openai.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You are a helpful assistant for creating beer recipes."},
{"role": "user", "content": user_prompt}
],
max_tokens=500,
temperature=0.7
)
# Extract content from the response
choices = response.choices
if choices and len(choices) > 0:
return choices[0].message.content
else:
return "No content returned from OpenAI."
except Exception as e:
return {"error": str(e)}
.