Follow Up Chat Responses With API

In the playground I was able to add system instructions, then add my prompt and then 2 follow up questions which produced consistent results for my output which I was really happy with.

However, I am unable to replicate this using the API.

My current code is this: Any ideas what I am doing wrong?

def rewrite_content_with_gpt3(text):
    try:
        # Initial AI response
        initial_response = client.chat.completions.create(
            model="gpt-3.5-turbo-16k",
            messages=[
                {
                    "role": "system",
                    "content": "{{System Prompt Here}}"
                },
                {
                    "role": "user",
                    "content": text  
                }
            ],
            temperature=1,
            max_tokens=12198,
            top_p=1,
            frequency_penalty=0,
            presence_penalty=0
        )

        initial_content = initial_response.choices[0].message.content.strip() if initial_response.choices else None

        if initial_response.choices:
            print("Initial response received and processed.")
        else:
            print("Initial response is empty or not received.")
    
        # Asking AI how  can be improved
        improvement_suggestion_response = client.chat.completions.create(
            model="gpt-3.5-turbo-16k",
            messages=[
                {
                    "role": "system",
                    "content": "{{System Prompt Here}}"
                },
                {
                    "role": "user",
                    "content": text
                },
                {
                    "role": "assistant",
                    "content": initial_content
                },
                {
                    "role": "user",
                    "content": "How can this be improved?"
                }
            ],
            temperature=1,
            max_tokens=12198,
            top_p=1,
            frequency_penalty=0,
            presence_penalty=0
        )
        
        improvement_suggestions = improvement_suggestion_response.choices[0].message.content.strip() if improvement_suggestion_response.choices else None

        if improvement_suggestion_response.choices:
            print("Improvement suggestion response received and processed.")
        else:
            print("Improvement suggestion response is empty or not received.")

        # Requesting the AI to make the improvements
        final_improved_plan_response = client.chat.completions.create(
            model="gpt-3.5-turbo-16k",
            messages=[
                {
                    "role": "system",
                    "content": "{{System Prompt Here}}"
                },
                {
                    "role": "user",
                    "content": text
                },
                {
                    "role": "assistant",
                    "content": initial_content
                },
                {
                    "role": "user",
                    "content": improvement_suggestions
                },
                {
                    "role": "assistant",
                    "content": "Please make these improvements"
                }
            ],
            temperature=1,
            max_tokens=12198,
            top_p=1,
            frequency_penalty=0,
            presence_penalty=0
        )

        final_improved_plan = final_improved_plan_response.choices[0].message.content.strip() if final_improved_plan_response.choices else None

        if final_improved_plan_response.choices:
                print("Final improved response received and processed.")
        else:
                print("Final improved  response is empty or not received.")

        return initial_content, final_improved_plan
    except Exception as e:
        print(f"Error during GPT-3 interaction: {e}")
        return None, None