AttributeError when accessing OpenAI API response

I’m developing a Streamlit application that integrates BigQuery and OpenAI’s GPT model to generate SQL queries and provide insights based on user questions. I’m encountering an error when trying to access the content of the OpenAI API response. Here are the details:

Error Message:

AttributeError: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you're on Streamlit Cloud, click on 'Manage app' in the lower right of your app).
Traceback:
File "/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 600, in *run*script
    exec(code, module.__dict__)
File "/mount/src/askyoudatabase/main.py", line 202, in <module>
    descriptive_result = descriptive_agent.choices[0].message.content.strip()
                         ^^^^^^^^^^^^^^^^^^^^^^^^^

Relevant Code Snippet:

descriptive_agent = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "system", "content": '''
         Role: You are a data storyteller who transforms complex data into clear, relatable insights.
        Task: Analyze datasets or data descriptions and present key findings concisely.
        Instructions:
        
        Create a section for Key Insight, make sure it was:
        - Provide the important insight based on the data in list or point format.
        - Explain the key insight in a brief, comprehensive manner.
        - Use simple language and relatable examples to make the insight accessible to all.

        Keep responses concise and focused on the single most impactful insight from the data.
        '''},
        {"role": "user", "content": tabular_data}
        ],
    temperature=0.3,
    max_tokens=1500,
    top_p=1,
    frequency_penalty=0,
    presence_penalty=0,
    stream=True
)
descriptive_result = descriptive_agent.choices[0].message.content.strip()

What I’ve Tried:

  1. I’ve double-checked that my OpenAI API key is correctly set in the Streamlit secrets.
  2. The error occurs specifically when trying to access the content of the API response.

Questions:

  1. Is there a change in the OpenAI API response structure that I’m not aware of?
  2. Could this be related to the stream=True parameter in the API call?
  3. Are there any known issues with accessing OpenAI API responses in Streamlit Cloud?

I would greatly appreciate any insights or suggestions on how to resolve this issue. If you need any additional information, please let me know.

Thank you in advance for your help!