Can someone help a complete newbie?

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)}

.

If you want to call the assistant you created then you shouldn’t use chat completions, but assistants API instead.

You will need to create a thread, add messages to it and initiate a run that references the thread and the assistant to generate a new response in the thread.

Read the Assistants API docs and it will become more clear.

1 Like