Thank you, I now have a different error. Any clue on this?
AttributeError: 'ThreadMessage' object has no attribute 'image_file'
Here is my entire code:
from openai import OpenAI
client = OpenAI(api_key='sk-...')
file = client.files.create(
file=open("balancesheet.pdf", "rb"),
purpose='assistants'
)
assistant = client.beta.assistants.create(
name="Financial Visualizer",
description="You are great at creating beautiful data visualizations. You analyze data present in .csv files, understand trends, and come up with data visualizations relevant to those trends. You also share a brief text summary of the trends observed.",
model="gpt-4-1106-preview",
tools=[{"type": "code_interpreter"},{"type": "retrieval"}],
file_ids=[file.id]
)
thread = client.beta.threads.create()
client.beta.threads.messages.create(
thread_id=thread.id,
role="user",
content="Can you please give me a simple example of a scatter plot"
)
run = client.beta.threads.runs.create(
thread_id=thread.id,
assistant_id=assistant.id
)
messages = client.beta.threads.messages.list(
thread_id=thread.id
)
#messages
r = messages.data[0]
What the next argument I should pass after r
?
# handle image file
api_response = client.files.with_raw_response.retrieve_content(r.?.?)
if api_response.status_code == 200:
content = api_response.content
with open('image.png', 'wb') as f:
f.write(content)
print('File downloaded successfully.')
Here is my r
output
ThreadMessage(id='msg_09C8CSuPEXQvP39kjj2wz7pp', assistant_id=None, content=[MessageContentText(text=Text(annotations=[], value='Can you please give me a simple example of a scatter plot'), type='text')], created_at=1700040507, file_ids=[], metadata={}, object='thread.message', role='user', run_id=None, thread_id='thread_Q1iPMjIT0iGC9uoSDoBVHBTj')
messages
output
SyncCursorPage[ThreadMessage](data=[ThreadMessage(id='msg_09C8CSuPEXQvP39kjj2wz7pp', assistant_id=None, content=[MessageContentText(text=Text(annotations=[], value='Can you please give me a simple example of a scatter plot'), type='text')], created_at=1700040507, file_ids=[], metadata={}, object='thread.message', role='user', run_id=None, thread_id='thread_Q1iPMjIT0iGC9uoSDoBVHBTj')], object='list', first_id='msg_09C8CSuPEXQvP39kjj2wz7pp', last_id='msg_09C8CSuPEXQvP39kjj2wz7pp', has_more=False)